Shop OBEX P1 Docs P2 Docs Learn Events
spin interpreter: how does it interpret the byte code — Parallax Forums

spin interpreter: how does it interpret the byte code

Chris MicroChris Micro Posts: 160
edited 2009-07-13 21:08 in Propeller 1
Hallo together,

as the spin interpreter source code is open, I try to understand how it works.
I traced with my emulator through the code.

In the interpreter source we can find the folowing:

' par word
'
' +2 pbase
' +4 vbase
' +6 dbase
' +8 pcurr
' +A dcurr

pcurr seems to mean "current programm counter" which points to the current byte to be interpreted.
What is the meaning of the other labels?

thanks for joining the discussion,
chris

Comments

  • BradCBradC Posts: 2,601
    edited 2009-07-13 10:14
    Chris Micro said...
    Hallo together,

    as the spin interpreter source code is open, I try to understand how it works.
    I traced with my emulator through the code.

    In the interpreter source we can find the folowing:

    ' par word
    '
    ' +2 pbase
    ' +4 vbase
    ' +6 dbase
    ' +8 pcurr
    ' +A dcurr

    pcurr seems to mean "current programm counter" which points to the current byte to be interpreted.
    What is the meaning of the other labels?

    thanks for joining the discussion,
    chris

    pbase = hub address of start of object
    vbase = hub address of start of global variables
    dbase = hub address of start of stack
    pcurr = program counter
    dcurr = stack pointer

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Release the hounds!

    Post Edited (BradC) : 7/13/2009 10:20:04 AM GMT
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-13 13:09
    Thanks for the answer wink.gif

    I created a more or less senseless program:
    var
       long a
    
    pub xx
      a:=0
      if a==1
        putchar(a)
    
    pub putchar(c)
      outa:=c 
    
    



    With your incredible useful BSTC I got the following listing:
    |===========================================================================|
    
    4                        a:=0
    
    Addr : 001C:             35  : Constant 1 $00000000
    
    Addr : 001D:             41  : Variable Operation Global Offset - 0 Write
    
    5                        if a==1
    
    Addr : 001E:             40  : Variable Operation Global Offset - 0 Read
    
    Addr : 001F:             36  : Constant 2 $00000001
    
    Addr : 0020:             FC  : Math Op ==    
    
    Addr : 0021: JZ Label0002
    
    Addr : 0021:          0A 04  : jz Address = 0027 4
    
    6                          putchar(a)
    
    Addr : 0023:             01  : Drop Anchor   
    
    Addr : 0024:             40  : Variable Operation Global Offset - 0 Read
    
    Addr : 0025:          05 02  : Call Sub 2    
    
    Addr : 0027: Label0002
    
    Addr : 0027: Label0003
    
    Addr : 0027:             32  : Return        
    
    |===========================================================================|
    
    Spin Block putchar with 1 Parameters and 0 Extra Stack Longs. Method 2
    
    pub putchar(c)
    
    
    
    Local Parameter DBASE:0000 - Result
    
    Local Parameter DBASE:0004 - c
    
    |===========================================================================|
    
    9                        outa:=c
    
    Addr : 0028:             64  : Variable Operation Local Offset - 1 Read
    
    Addr : 0029:          3F B4  : Register op OUTA Write
    
    Addr : 002B:             32  : Return        
    
    



    From this I can get some very useful information, but some things I do not really understand about the spin interpreter:

    Addr : 0023: 01 : Drop Anchor ==> what does Drop Anchor do?

    Addr : 0025: 05 02 : Call Sub 2 ==>
    does Call Sub 2 mean that the interpreter calls the routine from the current program counter +2 or is there a label list somewhere in the code which used as jump address?
  • BradCBradC Posts: 2,601
    edited 2009-07-13 13:13
    Chris Micro said...

    Addr : 0023: 01 : Drop Anchor ==> what does Drop Anchor do?

    Addr : 0025: 05 02 : Call Sub 2 ==>
    does Call Sub 2 mean that the interpreter calls the routine from the current program counter +2 or is there a label list somewhere in the code which used as jump address?

    Drop Anchor is a phrase I got from the interpreter source. It pretty much means prepare the stack for a function call.

    Call Sub 2 : means, call subroutine method 2 in the current method table.

    The header for each spin method lists the method numbers. The interpreter gets this information from the method table at the start of each object.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Release the hounds!
  • Chris MicroChris Micro Posts: 160
    edited 2009-07-13 15:54
    Thank you for the answer. I found a description for the object structure and hoped to understand where the method addresses are written.

    Probably it would be possible with the insights of this thread to write a spin object analyzer.
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-07-13 21:08
    @Chris:
    Homespun also provides a listing in a different format, so you might also get some other infor from this.
    Also look at my thread for the faster spin interpreter (see "tools" link in my signature below for this). There is a description of the interpreter instructions there.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBladeProp, RamBlade, TwinBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80), MoCog (6809)
    · Search the Propeller forums (via Google)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Sign In or Register to comment.