|Calling seguence for 65816 (Was: 8/16 bit compilers) mercier@pongo.West.Sun.COM (1994-02-02)|
|Re: Calling seguence for 65816 (Was: 8/16 bit compilers) email@example.com (1994-02-02)|
|From:||mercier@pongo.West.Sun.COM (Bob Mercier)|
|Organization:||Sunsoft Inc., Los Angeles, CA.|
|Date:||Wed, 2 Feb 1994 02:49:41 GMT|
I'm working on a tiny compiler for the 65816 and was trying to work out a
decent calling sequence for function calls.
I assumed native mode (16 bit X, Y and A) and wanted to be able to access
more than 256 bytes of local variables so I didn't use d,s.
If you can think of anything shorter that will allow easy access to more
than 256 bytes of locals and recursive functions, please let me know!
Proposed calling sequence:
We will dedicate a direct page word as the
procedure frame pointer, for example $80.
At procedure entry:
foo: lda $80
pha Save callers frame pointer
sbc #framesize Space for local variables
tcs Adjust stack pointer
sta $80 Store new frame pointer
Arguments and local variables are accessed by:
Where offset is framesize+4+argindex for function arguments.
This value can be calculated at compile time. The 4 is to skip
over the saved frame pointer and the return address. Accessing
local variables is the same except 'offset' would be less than
A procedure call for n = foo(1, 2) would look like:
jsr foo Functions return values in X
tcs Stack now the same as before call.
When we leave it's:
pla Restore callers frame pointer
Return to the
Search the comp.compilers archives again.