Seven-Step Program: Some More Detail
Place parameters in a place where the procedure can access them.
- First save the "unsaved" registers if we will still care
about them after procedure returns
$t0, ..., $t9, $a0, ..., $a3).
Where do they get saved?   the Stack
(we'll talk about this in a minute)
- Place the parameters in the "argument" registers
$a0, ..., $a3)
Transfer control to the procedure.
Acquire the storage resources needed for the procedure.
- Save the "saved" registers that this procedure plans to
$s0, ..., $s7).
Where do they get saved? the Stack
- Save the return address register if this procedure will call
other procedures (
Perform the desired task.
- Perform the desired task. (May include calls to
other procedures or recursive calls to this procedure.)
RELEASE the storage resources needed for the procedure. (Not one of the
steps listed on p. 97)
- Restore the saved registers (
Where were they saved? the Stack
Place the result values in a place where the calling program can access
Return control to the point of origin.
- Jump to the address specified by
register Jumps to the
address in the specified register.
Calling program must retrieve values from
and retrieve any saved arguments and temporary registers
$a0, ..., $a3, $t0, ..., $t9)
from the stack.
None of the register saves is automatic/guaranteed!!!
A big advantage of high-level languages is that compilers will
always do this consistently and get it right.
Alyce Brady, Kalamazoo College