<<< while loop example | Index | Register-type instructions >>> |
The stack pointer is in register $sp
$sp contains the address of the top of the stack
OS loader initializes $sp when the program is loaded
At runtime, $sp is your responsibility!
For example, stack frames in procedures are managed like this:
addiu $sp, $sp, -24 # allocate 6 words on the stack ... sw $t0, 16($sp) # save $t0 in stack frame ... lw $t0, 16($sp) # restore $t0 from the stack frame ... addiu $sp, $sp, 24 # deallocate 6 words on the stack
<<< while loop example | Index | Register-type instructions >>> |