Yes.
Those rules are complicated. In broad outline it works the same way as the previous chapter's stack-based linkage convention. But now, the subroutine prolog pushes room on the stack for local variables, and the epilog pops that room.
Here is a picture. It shows the sections of subroutine linkage. The basic tasks of each section are:
Subroutine Call: Push anyT
registers that contain values that are needed. Put arguments inA
registers.jal
to the subroutine.
Prolog: Push$ra
and the caller's$fp
. Push anyS
register the subroutine will alter. Initialize the subroutine's$fp
and$sp
.
Body: Normal code, except it must follow these conventions if it calls another subroutine.T
andA
registers can be used freely, as can anyS
registers that were saved in the prolog. Variables on the stack are accessed usingdisp($fp)
.
Epilog: Put return values inV
registers. Reset$sp
. Pop anyS
registers. Pop the caller's$fp
and$ra
.back to the caller. jr $ra
Regaining Control: Pop any previously pushed
T
registers.
Is there a limit to how many variables a subroutine may have?