@Eeems: The way that SDCC stores local variables is not always the same. I haven't done that for local variables, as SDCC will change where they are placed on the stack depending on your code. However, passed parameters to functions is the same, regardless of the sdcc version and allocator method. SDCC uses the IX register to quickly (depends if you have too many variables for pop's) get parameters and other variables.
Usually SDCC sets up the ix register. Passed parameters force it, but not always locals alone. Let me demonstrate. Lets say to want to access a variable in multiple instances...
Code: void callme(int x)
{
__asm
ld l,4(ix)
ld h,5(hl)
__endasm;
}
Looks like overkill, but not when you call printf with over 9000.... er, 100 parameters... But what is the IX?
SDCC makes that function intoCode: _callme_start:
_callme:
push ix
ld ix,#0
add ix,sp
; start of function below
ld l,4(ix) ;0-1 is ret, 2-3 is ix, 4-5 is x param
ld h,5(ix)
; end of function
pop ix
ret
_callme_end:
What if you don't want ix?
then do this:
Code: void callme(int x) __naked
That tells sdcc that you plan to use asm to start and end the function. You can still use C if ix is setup first. Now, for variables, you should play around with it. It should be stacked as you expect. Variables in each block are local to it. (as in {} ). I haven't done that, but it should just work... but it's sdcc, full of surprises
So, what about asm to C? Well, sdcc does not promote a byte to fit into a word. What do I mean? If you have void callme(byte a,int b), then sdcc would have a at 4(ix) and b at 5-6(ix). How does it pass it?Code: ld a,#0
push af
inc sp
ld hl,#0
push hl
call callme
pop hl
dec sp
pop af
Lastly, what about return values? You should look at the sdcc manual, but iirc, it uses de/hl for the return, dehl for 2 words, hl for a word, and l for a byte. I hope that's right. Anything else about sdcc, let me know
(I may add these functions as examples in the os source)