- Can someone explains why exactly we need Stack frames?
- What is its core purpose?
- What are its benefits?
- Isn't just one Stack Pointer sufficient to just push and pop elements from stack and not to use any frame?
- Here Stack Frames, it is mentioned that stack frame is a memory management technique... how is it a memory management technique?

- 21,212
- 6
- 68
- 105

- 621
- 1
- 7
- 13
-
No these are not home work questions... – Aimal Jun 10 '17 at 15:07
-
Are you asking about *stack frames* themselves or *frame pointers*? – EOF Jun 10 '17 at 16:27
-
kind of both. frame pointer comes under the topic of stack frames. – Aimal Jun 10 '17 at 16:45
-
2Well the answer is quite different depending on whether you ask about stack frames or frame pointers. Frame pointers are mostly used for convenience when humans write assembly (so basically never today), and otherwise for debugging (not necessary nowadays due to better debug info) or for functions with variable stack frame size (`alloca()` or VLAs). Stack frames are effectively unavoidable for non-leaf functions if reentrancy is desired. – EOF Jun 10 '17 at 16:48
-
How is your question specific to the ARM? – artless noise Jun 12 '17 at 13:08
1 Answers
Can someone explains why exactly we need Stack frames?
What is its core purpose?
What are its benefits?
I think those are all similar questions. The stack frame provides a means to,
- Trace call stacks; useful for debugging.
- A ways to create larger arrays, structs and other function data.
- A fairly quick access to spilled variables.
- Allow conditional execution (and recursion) of sub-functions.
- Can simplify
signal
handling.
Reason '3' was/is much more important on machines that do not have a lot of registers. Whether an item above is a 'core purpose', a benefit or needed is subjective. They are all reasons to have a stack frame. Whether a stack frame is needed or not for the above reasons is up to the application designer.
Isn't just one Stack Pointer sufficient to just push and pop elements from stack and not to use any frame?
push/pop is sufficient in most cases, but it might not be efficient; indeed in newer ARM 'application binary interface' (ABI) it is not required and gcc provides options to use/not use a stack frame. It definitely harder to provide a stack trace without the use of a stack frame.
Push/pop become less straight forward with recursion, variable allocations (alloca), function pointers, etc.
Here Stack Frames, it is mentioned that stack frame is a memory management technique... how is it a memory management technique?
It is managing memory in a simple way. Where the 'last request' is the 'first free', a stack and frame pointers are perfect. Gnu Objstack is similar.

- 21,212
- 6
- 68
- 105