Re: frame pointer
- From: "Julienne Walker" <happyfrosty@xxxxxxxxxxx>
- Date: 30 Apr 2006 06:00:21 -0700
Christian Christmann wrote:
Hi,
I'm learning MIPS assembly programming. In couple of examples
I went through, the authors save the "frame pointer" with
sw $fp 8($sp) # sp is stack pointer
onto the stack.
However, after returning from a routine accessed by a jump instruction
(like JAL label, "JAL" = jump&link return address), they restore the
stored values using $fp like
lw $ra -4($fp).
What is the general purpose of a frame pointer and why is in the
aforementioned examples not the stack pointer "$sp" used for
saving and restoring context values?
If you use $sp for addressing inside the stack frame, it's like trying
to hit a moving target. That makes it very difficult to write reliable
(and maintainable!) code. The frame pointer saves $sp at a predictable
point so that you have a predictable base to work with while still
allowing $sp to change as necessary.
As for why $fp is used instead of $sp to load the return address,
that's entirely up to the author of the code. If it's more convenient
to use $fp, all the better.
.
- References:
- frame pointer
- From: Christian Christmann
- frame pointer
- Prev by Date: frame pointer
- Next by Date: Re: I'd like to learn asm...
- Previous by thread: frame pointer
- Index(es):
Relevant Pages
|