PDA

View Full Version : spin interpreter: how does it interpret the byte code



Chris Micro
07-13-2009, 05:55 PM
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

BradC
07-13-2009, 06:14 PM
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 Micro
07-13-2009, 09:09 PM
Thanks for the answer http://forums.parallax.com/images/smilies/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?

BradC
07-13-2009, 09:13 PM
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 Micro
07-13-2009, 11:54 PM
Thank you for the answer. I found a description for the object structure (http://forums.parallax.com/showthread.php?p=736449) 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.

Cluso99
07-14-2009, 05:08 AM
@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 (http://forums.parallax.com/showthread.php?p=786418), RamBlade (http://forums.parallax.com/showthread.php?p=810753), TwinBlade (http://forums.parallax.com/showthread.php?p=806697),·SixBlade (http://forums.parallax.com/showthread.php?p=780033), website (http://bluemagic.biz/cluso.htm)
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator) (http://forums.parallax.com/showthread.php?p=790917)
· Prop Tools under Development or Completed (Index) (http://forums.parallax.com/showthread.php?p=753439)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index (http://forums.parallax.com/showthread.php?p=778427)) ZiCog (Z80), MoCog (6809)
· Search the Propeller forums (via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)
My cruising website is: ·www.bluemagic.biz (http://www.bluemagic.biz)·· MultiBladeProp is: www.bluemagic.biz/cluso.htm (http://www.bluemagic.biz/cluso.htm)