Stack in Memory and Registers

Learn how to implement the stack, call stack, and jumps in memory and registers.

Register review

So far, we have seen and used general-purpose CPU registers:

  • x0/w0
  • x1/w1
  • x2/w2
  • x3/w3
  • x4/w4
  • x30/w30

We also have special purpose registers:

  • XZR/WZR (the zero register)
  • pc (the instruction pointer)
  • sp (the stack pointer)

Application memory simplified

When an executable file is loaded into memory, we observe the following:

  • Its header and sections are mapped to memory pages.
  • Some data and code are copied unmodified, but some data is initialized and expanded.
  • The first stack is also created at this stage.
  • A pc register is set to point to the first program instruction, and sp points to the top of the stack.

This simplified process is shown in the figure below:

Get hands-on with 1400+ tech skills courses.