go to previous page   go to home page   go to next page hear noise

Answer:

Sure. And that new subroutine can call another one and so on.


Register Problem

In the Simple Linkage convention of the previous chapter, registers $s0―$s7 must not be altered by a subroutine. But this restriction creates a problem when subroutines call other subroutines.

Say that main calls subA and that subA calls subB. subA can't save any values in $s0―$s7 (because it is not allowed to alter them). But any values it saves in $t0―$t9 might be clobbered by subB (because subB is allowed to alter them). In effect, subA can't use any registers! Not good.

The solution is to allow subA to use $s0―$s7. However, before using one of these registers, subA must save its value on the stack. Later, when subA returns to its caller, it must restore the register to its initial state.


QUESTION 4:

Is it safe to store $s0―$s7 and $ra on the stack?