STACK FRAMES


According to the developers, a stack frame is memory between the frame
pointer pointer ($fp), which points to the word immediately after the
last argument passed on the stack, and the stack pointer ($sp), which
points to the first free word on the stack. 

Stack frames usually store the following imformation: local variables,
saved registers and return address. 

Each time a function call is executed a new frame is added to the stack
containing all the imformation of the state of the program at the instant
that the function was called.

Once the execution of the function is finished, the frame created during
the call is disposed from the stack.


WARNING: Multiple executions of the same function, have distinct frames 



CALLING CONVENTIONS



The following steps are necessary to effect a call: 

   1.Pass the arguments. By convention, the first four arguments are
     passed in registers $a0-$a3 (though simplier compilers may choose to
     ignore this convention and pass all arguments via the stack). The
     remaining arguments are pushed on the stack. 

   2.Save the caller-saved registers. This includes registers $t0-$t9, if
     they contain live values at the call site. 

   3.Execute a jal instruction.
 

Within the called routine, the following steps are necessary: 

   1.Establish the stack frame by subtracting the frame size from the
     stack pointer. 

   2.Save the callee-saved registers in the frame. Register $fp is always
     saved. Register $ra needs to be saved if the routine itself makes
     calls. Any of the registers $s0-$s7 that are used by the callee need
     to be saved. 

   3.Establish the frame pointer by adding the stack frame size to the
     address in $sp. 


Finally, to return from a call, a function places the returned value into
$v0 and executes the following steps: 


   1.Restore any callee-saved registers that were saved upon entry
     (including the frame pointer $fp). 

   2.Pop the stack frame by subtracting the frame size from $sp. 

   3.Return by jumping to the address in register $ra.