Parameter Transmission Techniques

There are several fairly standard kinds of parameter transmission, plus a few that are less common but ought to be mentioned.

By Value

The conceptually simplest mechanism for parameter transmission is called ``by value'' - this is the mechanism used by C. In this mechanism, the value you actually want to send is pushed on the stack. If you pass parameters by value, you have no way of getting a changed parameter back to the caller. So to pass a parameter by value, you need to do something like

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.

By Reference

The other common technique is parameter passing by reference: instead of passing in the value of the parameter, you pass its address. This is the technique commonly associated with FORTRAN, and is available with C++.

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