ldaa 3,x * get local variable into a accumulator
psha * push on stack
On the HC11, access to a parameter passed by value can be obtained by using indexed addressing. For reading a parameter, something like this will work
ldaa 6,x
where the parameter is six bytes away from the x
index
register.
Using by-reference parameters is a little harder on the HC11 than using by-value parameters. To get at a by-reference parameter, you have to extract the address of the data from the parameter, and then use indexed addressing (with an index of 0) to get at it.
First, to pass the parameter you need to get its address. If it's a global variable, that's easy
ldx #global
pshx
It's a bit trickier to pass the address of a local variable, or
something that was originally passed to the caller as a parameter.
The cases for local variable and for parameter (passed in as by-value)
are the same:
xgdx * get frame pointer into D
addd #7 * add offset to variable
pshb * push D (using two instructions)
psha
subd #7 * get value back to before
xgdx * get back into x.
Something originally passed in as a by-reference parameter needs to be
handled a little differently. Something like this could work
ldy #5,x * get address
pshy * push it
To access a by-reference parameter, you need to get the pointer and
dereference it. So you get something like:
ldy 8,x * get address
ldaa 0,y * fetch from there