L4 - TheMIPSstack:recap memoryaddresses isstored(byconvention)inthestack pointerregister,$sp 0($sp,1($sp,areusedlocations 1($sp,2($sp,arefree

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 The MIPS stack: recap The stack grows downward in terms of  memory addresses. The address of the top element of the stack  is stored (by convention) in the “stack  pointer” register,  $sp . 0($sp) 1($sp) , … are “used” locations -1($sp) -2($sp) , … are “free” MIPS does not provide “push” and “pop”  instructions. Instead, they must be done  explicitly by the programmer. “push” $t0  simulated with: sub $sp, $sp, 4  # $t0 needs 4 bytes sw  $t0, 0($sp)  # write to stack “pop” $t0  simulated with: lw   $t0, 0($sp)  # read stack top addi $sp, $sp, 4  # free 4 bytes 0x7FFFFFFF 0x00000000 $sp  stack
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Using the stack: MP 2’s  main Performs a  jal , so must save  $ra  before and restore it afterwards main:   addi  $sp, $sp, -4         # grow stack   sw    $ra, 0($sp)          # save callee-saved register $ra   jal   iterTraverse         # call your function   lw    $ra, 0($sp)          # restore $ra   addi  $sp, $sp, 4          # shrink stack   jr    $ra jal  to a function Will cause a malfunction If  ra  is not on the stack And  caller-saved regs Should be handled like eggs They're junk when the function comes back And lastly, no messes In each of the  esses Make sure you restore 'em - don't slack!
Background image of page 2
3 Practice with pointers: Linked Lists
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/28/2012 for the course CSCE 3510 taught by Professor Unt during the Spring '12 term at North Texas.

Page1 / 9

L4 - TheMIPSstack:recap memoryaddresses isstored(byconvention)inthestack pointerregister,$sp 0($sp,1($sp,areusedlocations 1($sp,2($sp,arefree

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online