Skip to main content
Engineering LibreTexts

8: Reentrant Subprograms

  • Page ID
  • Learning Objectives

    1. The stack datastructure.
    2. The purpose of a program stack, and how to implement it.
    3. How to implement reentrant programs.
    4. How to store local variables on the stack
    5. What recursive subprograms are, and how to implement them.

    In Chapter 5 the concept of a subprogram was introduced. At the time the jal operand was introduced as a way to call a subprogram, and the jr $ra instruction was introduced as the equivalent of a return statement. To implement subprograms which do not call other subprograms, this definition of how to call and return from a subprogram was sufficient. However this limitation on subprograms that they cannot be reentrant is far too restrictive to be of use for in real programs. This chapter will implement an infrastructure for subprogram dispatching that removes the non-reentrant problem from subprograms.24

    24 The subprogram infrastructure given here will have a limitation. Only 4 input parameters to the subprogram, and 2 return values from the subprogram, will be allowed. This limitation is used to simplify the concept of a stack. In many cases in MIPS assembly subprograms are implemented using a Frame Pointer ($fp) to keep track of parameters and return values. The following web site gives a good overview of how the $fp can be used in subprogram calls:

    • Was this article helpful?