The stack and function calls
The call stack and its pointer, pushing and popping, what a call and its return do, the stack frame, the calling convention and stack overflow.
- 23 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The numbers
- Scenarios
A few cards from the deck
Call stack: what is it?
Show the answer
A region of memory managed last in, first out, where each function call keeps its data for as long as it runs.
The last function called is the first to finish: that is what makes nested calls and recursion work.
The stack pointer holds 0x1000. What does it hold after these two instructions, with 4-byte words?
```arm
PUSH {R0}
PUSH {R1}`- 0x0FF8
- 0x1008
- 0x0FFC
- 0x0FFE
Show the answer
0x0FF8
Each PUSH subtracts 4: 0x1000, then 0x0FFC, then 0x0FF8. 0x1008 assumes the stack goes up, 0x0FFC counts only one push, 0x0FFE takes one byte per push instead of four.
The stack follows the … rule: you only ever push and pop at its ….
Show the answer
The stack follows the last in, first out rule: you only ever push and pop at its top.
Like a pile of plates: to reach the one underneath, you first remove those on top.
Stack frame: what is it?
Show the answer
The block of the stack belonging to one function call, which holds its parameters, its return address and its local variables.
It is created at the call and vanishes at the return. Two calls of the same function have two distinct frames, hence distinct local variables.