Introduction to the Stack
Explore the concept of the stack as a last in, first out (LIFO) data structure, its memory implementation using the sp register in ARM64 Linux, and how push and pop instructions manipulate stack data. Understand stack alignment, usage for function calls, parameters, and local variables.
What is a stack?
A stack is a simple computational device with two operations: push and pop.
That allows us to pile up data to remember using the LIFO (last in, first out) method and quickly retrieve the last piled data item as shown below:
Stack implementation in memory
A CPU sp register (stack pointer) points to the top of a stack. In the figure below, a stack grows towards lower memory addresses with every push operation, and this is implemented as the sp register. We’ll decrement it by 16 and then move a value or a pair of values using the str or stp ...