barrym95838 wrote:
Your stack diagram for PEA seems to imply that the low byte of the operand is pushed before the high byte, which contradicts my 65xx instincts. I have a reputation for being correct more than 50% of the time.
Good spot thanks! A good rule of thumb is that the high byte
always goes higher in memory*. Chock up another one to greater than 50
BigDumbDinosaur wrote:
What follows is a macro in Kowalski assembler syntax that generates a stack frame for use in passing parameters into a called function (subroutine). An arbitrary number of arguments is passed to the macro, these arguments being interpreted as 32-bit pointers to data. Along with each pointer argument, a corresponding mode argument is passed to tell the macro how to interpret the pointer argument. The bottom of the stack frame, i.e., at SP+1, will have a 16-bit number that is a count of the number of words in the rest of the stack frame.
Very cool! I need to up my macro-fu game.
BigDumbDinosaur wrote:
Unlike SP in the 65C02 (and other 8-bit 6502 members), the native-mode 65C816 SP is a true pointer—it holds an address, unlike the 65C02’s SP, which is merely an index into a fixed memory range (page $01). That the native-mode 816 SP is a pointer makes it easy to do all sorts of useful tricks with it, which are facilitated by various stack-oriented machine instructions. For example, the 816 makes it convenient to reserve ephemeral workspace on the stack, giving each function in your program a “scratchpad” for doing local stuff
Interesting, what you've posted for the function setup and cleanup is subtly different to
this post here based on the WDC C compiler's convention. The only real difference being that the PHD happens last and without the INC. Possibly marginally more optimal but it makes thinking about variables in the Direct Page a pain because everything is offset by one as the first byte in the Direct Page contains the high byte of the old DP. The low byte being inaccessible at DP - 1.
* And ... BDD had already made exactly the same point in his last post. Doh!