Introduction to the Stack

Learn how to implement the stack in memory.

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 ...

Access this course and 1400+ top-rated courses and projects.