This question already has an answer here:
- Frame Pointer Explanation 1 answer
I'm trying to understand how stack frames are constructed and have run into this description on wikipedia:
The locations of all other fields in the frame can be defined relative either to the top of the frame, as negative offsets of the stack pointer, or relative to the top of the frame below, as positive offsets of the frame pointer. The location of the frame pointer itself must inherently be defined as a negative offset of the stack pointer. --- https://en.wikipedia.org/wiki/Call_stack
The description in the quote above implies that the frame pointer's address being an offset from the stack pointer is trivially obvious from their respective definitions.
I'm confused about why the location of the frame pointer must inherently be defined as a function of the stack pointer.
As I understand the situation, the stack pointer is incremented when new memory is allocated to the frame. However the location of the frame pointer is fixed from the point where the procedure's prologue has finished.
Since all memory accesses within the frame must either be addressed as offsets from the frame pointer or as memory offsets from the stack pointer, and one of the frame pointer and stack pointer is a fixed location and the other one is inherently mutable, surely it makes sense to make the mutable pointer an offset from the fixed pointer?
As I understand it, in the above scheme, you'd need to update the frame pointer reference every time you incremented the stack pointer, which seems excessive. What have I misunderstood?