Stack-Based Linkage Convention


The subroutine linkage conventions of MIPS include: In the simple linkage convention, a subroutine is not able to call another subroutine because the return address in $ra is overwritten. The stack-based subroutine linkage convention can be used to solve the problem. The following picture shows the four sections of the stack-base subroutine linkage. The basic tasks of each section are

  1. Subroutine call: Push all T registers that contain values that will be needed after the call. Put arguments in A registers. jal to the subroutine.

  2. Prolog: If this subroutine calls other subroutines, push $ra. Push all S registers that the subroutine alters.

  3. Body: Normal code, except that it must follow these conventions if it calls a subroutine. T registers and A registers can be used freely, as can any S registers that were saved in the prolog.
  1. Epilog: Put return values in V registers. Pop any S registers. Pop $ra if it was pushed in the prolog. jr $ra back to the caller.

  2. Regaining control: Pop any T registers that were previously pushed.



      Nine times out of ten (almost always)    
      your first choice turns out to be the right one.