[prev] 29 [next]

Function Calling Protocol

Before one function calls another, it needs to
  • place (32-bit) arguments in the $a0..$a3
  • if more than 4 args, or args larger than 32-bits ...
    • push value of all such args onto stack
  • save any non-$s? registers that need to be preserved
    • push value of all such registers onto stack
  • jal address of function (usually given by a label)
Pushing value of e.g. $t0 onto stack means:

addi $sp, $sp, -4      OR      sw   $t0, -4($sp)
sw   $t0, ($sp)                addi $sp, $sp, -4