next up previous contents index

[ENGN3213 Home]

Parameter Passing

  There are two ways of passing data parameters to and from a subroutine:

These mechanisms can be effected using registers, stacks, memory locations or in some cases in-line coding.

Via registers. Perhaps the simplest way to pass a small number of parameters is to use registers. The parameters to be passed are copied into suitable registers before the subroutine is called, and the values in these registers can be accessed and manipulated in the subroutine. Return results can be placed in a register and thereby made available to the calling program (D0 is often used for this by C compilers). Data values as well as addresses may be passed in this way.

An example of this is given in the code clab62s.s from CLAB6.

Via the stack. The stack provides a very useful mechanism for parameter passing, and is widely used. The parameters are pushed onto the stack before the subroutine is called. Since the return address is saved on the stack, the programmer must calculate the correct offset from (SP) in order to access the desired parameters inside the subroutine.

An example of this is given in the code clab63s.s from CLAB6.


next up previous contents index

[ENGN3213 Home]

ANU Engineering - ENGN3213