HomeARM CourseDay 3
DAY 3 · FOUNDATIONS

The Programmer's Model — Registers & the CPSR

By EcrioniX · Updated Jun 6, 2026

On Day 1 we learned ARM is a load/store machine: all real work happens in registers. So today we meet those registers — the CPU's handful of ultra-fast scratchpads — and the status register that records what just happened.

1. What is a register?

A register is a tiny piece of storage inside the CPU that holds one value (32 bits in classic ARM). Registers are the fastest memory that exists — accessed in a single cycle — which is exactly why ARM insists all arithmetic happens here, not in slow external memory.

The classic 32-bit ARM model gives you 16 registers you can name directly: R0–R15, plus a special status register, the CPSR.

R0arg / result
R1arg / scratch
R2arg / scratch
R3arg / scratch
R4variable
R5variable
R6variable
R7variable
R8variable
R9variable
R10variable
R11frame ptr
R12scratch (IP)
R13 / SPStack Pointer
R14 / LRLink Register
R15 / PCProgram Counter

2. R0–R12: the general-purpose workers

These thirteen hold your variables and intermediate results. The hardware treats them equally, but convention (the AAPCS, coming on Day 15) assigns habits: R0–R3 pass the first arguments to a function and return its result; R4–R11 hold longer-lived variables. Following the convention is what lets your code call other people's code safely.

3. The three special registers

R13, R14 and R15 are ordinary 32-bit registers given special jobs by the hardware:

RegNameJob
R13SP — Stack PointerPoints to the top of the stack (where local data & saved registers live). Day 14.
R14LR — Link RegisterHolds the return address when you call a subroutine, so the CPU knows where to come back to. Day 15.
R15PC — Program CounterHolds the address of the instruction being fetched. Change it and you've branched.

💡 Reading a book analogy

The PC is your finger tracking the current line. The LR is the sticky note you leave when you jump to a footnote, so you can return. The SP marks the top of your stack of bookmarks.

4. The CPSR — the status register

After every operation the CPU records what happened in the CPSR (Current Program Status Register). Its top four bits are the condition flags — the single most important thing to learn today:

31
N
30
Z
29
C
28
V
27…8
reserved / extra
7 6 5
I F T
4…0
mode
FlagNameSet when…
NNegativeresult's bit 31 = 1 (negative as a signed number)
ZZeroresult is exactly 0
CCarryan add carried out, or a subtract did not borrow
VoVerflowsigned overflow occurred

The other CPSR fields: I and F disable IRQ/FIQ interrupts (Day 17), T selects Thumb vs ARM state (Day 6), and the mode bits set the processor mode (Day 5).

5. Seeing flags in action

Flags are how a CPU makes decisions. Watch CMP (compare) — it subtracts, throws away the result, and just keeps the flags:

; compare R0 with 5 CMP R0, #5 ; computes R0 - 5, sets N Z C V ; if R0 == 5 -> Z = 1 ; if R0 < 5 -> N differs from V BEQ equal ; "Branch if EQual" = branch when Z == 1

So CMP sets the flags and BEQ reads them. That two-step — set flags, then act on them — is the heart of every if, loop and comparison in machine code. We'll build on it heavily in Day 11 (conditional execution).

✅ The mental model to keep

Registers = the CPU's hands (work happens here). SP / LR / PC = three hands with a permanent job. The CPSR flags (N Z C V) = a sticky note saying what the last result looked like, which the next instruction can read to make a decision.

6. A note on 64-bit

Everything above is the classic 32-bit (AArch32) model. The 64-bit world (AArch64, Day 26) expands this to 31 general-purpose 64-bit registers, X0–X30, and splits the status flags into their own register. The ideas — registers, SP, return address, NZCV flags — carry straight over.

🎯 Day 3 takeaways

Quick check

  1. Which register holds the address you'll return to after a subroutine?
  2. After CMP R0, R1, which flag is set if R0 == R1?
  3. If you write a new value into the PC, what just happened to the program?

FAQ

How many registers does ARM have?

Classic 32-bit ARM exposes 16 registers (R0–R15) plus the CPSR. AArch64 has 31 general-purpose registers (X0–X30).

What are SP, LR and PC?

R13 = Stack Pointer, R14 = Link Register (return address), R15 = Program Counter (address being fetched).

What are the NZCV flags?

The four CPSR condition flags: Negative, Zero, Carry, oVerflow — set by arithmetic/logic results and tested by conditional instructions.

Previous
← Day 2: ARM processor families

← Back to the full course roadmap