[prev] 33 [next]

Structure of Functions

Functions in MIPS have the following general structure:

# start of function
FuncName:
   # function prologue
   #   set up stack frame ($fp, $sp)
   #   save relevant registers (incl. $ra)
   ...
   # function body
   #   perform computation using $a0, etc.
   #   leaving result in $v0
   ...
   # function epilogue
   #   restore saved registers (esp. $ra)
   #   clean up stack frame ($fp, $sp)
   jr  $ra

Aim of prologue: create environment for function to execute in.