4.1.5 · D1Computer Architecture (Deep)

Foundations — Registers — general purpose, special (PC, SP, LR, CPSR)

1,996 words9 min readBack to topic

Before you can follow a single line of the parent note, you need the alphabet it is written in. This page defines every symbol, from the meaning of a "bit" up to CPSR. Read it top to bottom — each idea is a brick for the next.


0. The atom: a bit

The picture: a light switch. Down = 0, up = 1. Nothing in between.

Why the topic needs it: a register is nothing but a row of these switches wired together. If you don't picture the switch, "32-bit register" is just noise.

Figure — Registers — general purpose, special (PC, SP, LR, CPSR)

1. A row of bits → a register's width

The picture: figure s01 shows 8 switches in a row (an 8-bit box). Line them up and read them left-to-right as one binary number.

Counting how many values fit. Each switch doubles the number of patterns: 1 switch → 2 patterns (0,1); 2 switches → 4 (00 01 10 11); and in general switches give

The symbol just means "approximately equals" — the exact number is huge, so we round.


2. Reading those bits as a number (unsigned & signed)

A row of switches is only useful once we agree what number it names.

But CPUs also store negative numbers. They use a trick called two's complement (its own topic — see Two's Complement Arithmetic). All you need here:

The picture: in figure s01 the leftmost switch is highlighted — that one switch decides "positive or negative."

Why the topic needs it: the N (Negative) and V (signed overflow) flags in CPSR are statements about this signed reading. Without knowing which bit is the sign, "N = result MSB = 1" is meaningless.


3. Hexadecimal — the shorthand 0x

The picture: cut a row of 8 switches into two blocks of 4; label each block with one hex symbol.

Why the topic needs it: the parent's worked example 0x7F + 0x01 is written in hex. You must be able to unfold 0x7F into bits to see why the sign bit flips.


4. Address — a house number for memory

The picture: a long vertical strip of boxes, each labelled with a number going up. Lower numbers at the bottom, higher at the top.

Figure — Registers — general purpose, special (PC, SP, LR, CPSR)

Why the topic needs it:

  • The PC holds an address (which instruction to run next).
  • The SP holds an address (where the stack's top box is).
  • The LR holds an address (where to come back to).

All three special registers store house numbers, not data. That is the single most important realisation of the whole parent note.


5. The assignment arrow

The picture: an arrow pointing into a box — new number pours in, old number gone.

Why the topic needs it: every register operation is written this way: , , . If you misread as "" (a fact), the derivations look circular. It is an action performed in time.


6. Instruction, and the fixed length

The picture: the memory strip of figure s02, but now each instruction occupies 4 consecutive byte-boxes. Instructions sit at addresses — always a multiple of 4.

Why the topic needs it: because instructions are a fixed bytes apart, "go to the next instruction" is simply add : . The whole fetch loop rests on this constant spacing.


7. The ALU — where results (and flags) are born

The picture: a machine with two input pipes (operands), one output pipe (result), and a little scoreboard hanging off the side (the flags).

Why the topic needs it: the flags N Z C V are the ALU's report card on its last sum. CMP a,b runs through the ALU just to light up that scoreboard, then discards the number.

Figure — Registers — general purpose, special (PC, SP, LR, CPSR)

8. The four flag letters N Z C V

Each flag is a single bit on the ALU's scoreboard (figure s03):

The picture: four tiny lights labelled N, Z, C, V above the ALU. After each sum the right lights turn on.

Why the topic needs it: conditional branches (BEQ, BNE, …) do nothing but peek at these lights. BEQ = "jump only if the Z light is on."


9. Logic symbols , ,

The parent's overflow rule uses two small logic marks:

Why the topic needs it: the formula reads in English: "overflow is on when the two inputs had the same sign and the result's sign is different." Now it's a sentence, not hieroglyphics.


10. The stack (a preview picture)

The picture: the memory strip again, but the stack grows downward (toward smaller addresses) — a "full-descending" stack, as the parent uses. Pushing moves SP down; popping moves it up.

Fuller detail lives in The Stack and Function Calls (Calling Conventions); here you just need "SP = finger on the top plate."


How these bricks build the topic

bit = one switch

width W = row of bits

2 power W values

MSB = sign bit

signed vs unsigned reading

hex 0x shorthand

address = box number in RAM

PC holds address

SP holds stack top address

LR holds return address

arrow means copy in

instruction length L = 4

ALU computes result

N Z C V flags

CPSR and conditional branch

stack grows down

Registers topic

Every arrow says "you need the left thing to understand the right thing." Notice how address feeds three special registers, and signed reading feeds the flags — those are the two hubs of the whole chapter.


Equipment checklist

Cover the right side; can you answer before revealing?

What is a bit, physically?
One switch that is either 0 (off) or 1 (on) — a low or high voltage.
How many distinct values does a -bit register hold, and why?
, because each added switch doubles the number of patterns.
Which switch is the MSB and what does it decide?
The leftmost bit; in signed reading it decides negative (1) vs positive (0).
Unfold 0x80 into 8 bits.
— sign bit set, so unsigned or signed.
What does mean?
The contents of the memory box whose address (house number) is .
Read in plain English.
"Copy the value (SP minus 4) into the SP box" — i.e. move the stack pointer down by 4.
Why is the next instruction at ?
Instructions are a fixed bytes long, so they sit 4 apart in memory.
What does the ALU produce besides a result?
The N, Z, C, V flags — its report card on that result.
Say the V-flag rule as an English sentence.
Overflow is set when both inputs share a sign AND the result's sign differs.
Which way does a full-descending stack grow, and where does SP point?
Toward lower addresses; SP points at the last item pushed (the occupied top).