bytecode header q.: base of stack vs. initial stack pointer
mpark
Posts: 1,305
Hippy's MainSpec.txt document on Spin bytecodes describes the 16-byte header of a .eeprom file. One word is described as "Base of stack", another as "Initial stack Pointer". Question: Why are they different?
I've finally figured out that the difference between them is 4 x (number of parameters and local variables·in first PUB, including result variable), but I can't see why that should be.
Doesn't the stack grow upward in memory? Shouldn't the stack pointer start out pointing at the base of the stack? Why does the compiler need to reserve space below the stack?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
I've finally figured out that the difference between them is 4 x (number of parameters and local variables·in first PUB, including result variable), but I can't see why that should be.
Doesn't the stack grow upward in memory? Shouldn't the stack pointer start out pointing at the base of the stack? Why does the compiler need to reserve space below the stack?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
Comments
That's right. There is a return address already placed on the stack so that if your program 'return's, it branches to 3 bytes of ROM code that are COGSTOP(COGID). This is why the base and pointer vary.
·
Post Edited By Moderator (Chip Gracey (Parallax)) : 8/25/2008 9:34:53 PM GMT
Considering there's a constant offset between the two I'm not sure why both items appear in the header. I suspect it's got something to do with Cognew/CogInit ( which uses a similar header to launch a method in its own Cog ) or simply to save a byte or two in the Spin interpreter. It may have come about as an alternative to wasting an otherwise unused word which doesn't fit with the long alignment which follows; it's there, use it, one less thing needed to do the interpreter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
But of course.. the method still requires stack space to operate on all its local variables, so that must already be allocated on the stack prior to the method being started.
The more variables defined, the longer the pre-allocated stack space area.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!
Time to fix some bugs I know I've got based around that mistaken belief ...