Calling seguence for 65816 (Was: 8/16 bit compilers)

mercier@pongo.West.Sun.COM (Bob Mercier)
Wed, 2 Feb 1994 02:49:41 GMT

          From comp.compilers

Related articles
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) meekins@crl.com (1994-02-02)
| List of all articles for this month |
Newsgroups: comp.compilers,rec.games.video.nintendo
From: mercier@pongo.West.Sun.COM (Bob Mercier)
Keywords: architecture, question
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!


bob.mercier@cypress.west.sun.com


-----


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
tsc
sbc #framesize Space for local variables
tcs Adjust stack pointer
sta $80 Store new frame pointer


Arguments and local variables are accessed by:


ldy lda ($80),y


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
framesize.


A procedure call for n = foo(1, 2) would look like:


lda #$1
pha
lda #$2
pha
jsr foo Functions return values in X
tsc
adc #$4
tcs Stack now the same as before call.


stx n


When we leave it's:


tsc
adc #framesize
tcs
pla Restore callers frame pointer
sta $80
rts
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.