5

I am currently reading Computer Organization and Design by John L. Henessy for Architecture course. As far as I understood that $sp points to the most recently allocated address in the stack and $fp points to the begining of the stack. Why exactly do we need $fp? And how does they behave if a procedure calls another procedure? For example when stack grows, the stack pointer decrements, but what are the changes in $fp?

cnoob
  • 53
  • 1
  • 3
  • Cross-site dup: [Frame Pointer Explanation](https://softwareengineering.stackexchange.com/q/194339/98103). It's not what we *need* `$fp` but it helps in many cases like stack unrolling or handwritten asm. Not about MIPS but these could give you some idea [What is the purpose of the EBP frame pointer register?](https://stackoverflow.com/q/579262/995714) – phuclv Jan 26 '18 at 10:23

1 Answers1

4

$fp contains the value of $sp just before the current function was called, i.e. the beginning of the current stack frame (wikipedia). $fp is useful for x86 machines where PUSH and POP are commonly used, and is less useful for MIPS, where $sp is typically adjusted once on entry to a function and $sp relative addressing can be used.

markgz
  • 6,054
  • 1
  • 19
  • 41