1.1.8How Computers Work

Registers — N flip-flops storing N bits

1,783 words8 min readdifficulty · medium1 backlinks

WHAT is a register?

  • WHAT it stores: an NN-bit pattern, e.g. 1011 in a 4-bit register.
  • WHAT distinguishes it from raw flip-flops: the flip-flops are synchronised (same clock) so the bits don't change at slightly different times — the word stays consistent.

HOW: building it from one flip-flop

Step 1 — The atom: a D flip-flop

The defining behaviour (its characteristic equation):

Qnext=D(captured at the clock edge)Q_{\text{next}} = D \quad \text{(captured at the clock edge)}

Why this equation? "Next stored value = the data I presented." Between edges QQ is frozen, so it is genuinely memory, not just a wire.

Step 2 — Replicate N times

Put down flip-flops FF0,FF1,,FFN1FF_0, FF_1, \dots, FF_{N-1}. Wire:

  • data inputs D0DN1D_0 \dots D_{N-1} (the word you want to store),
  • a shared clock to every flip-flop,
  • outputs Q0QN1Q_0 \dots Q_{N-1} (the stored word).

Qinext=Difor all i=0,1,,N1, at the same clock edgeQ_i^{\text{next}} = D_i \quad \text{for all } i = 0,1,\dots,N-1 \text{, at the same clock edge}

Why share the clock? So the word updates atomically. If each bit had its own clock, you could read a half-old, half-new garbage value (a race). One clock = one consistent snapshot.

Figure — Registers — N flip-flops storing N bits

Step 3 — Add a Load (enable) line

A bare register would overwrite itself every clock edge. Usually you want it to hold until told to load.

Di=LOADINi+LOADQiD_i = \text{LOAD}\cdot \text{IN}_i + \overline{\text{LOAD}}\cdot Q_i

So the actual update rule of a loadable register is:

Qinext=LOADINi+LOADQi\boxed{\,Q_i^{\text{next}} = \text{LOAD}\cdot \text{IN}_i + \overline{\text{LOAD}}\cdot Q_i\,}

Why this works: it's just a 2-to-1 multiplexer selecting "new data" vs "old self." When LOAD is low, Qinext=QiQ_i^{\text{next}}=Q_i → the bit is unchanged → memory preserved.


Worked examples


Common mistakes


Recall Feynman: explain it to a 12-year-old

Imagine a row of light switches, each either ON or OFF — that's a bit. A flip-flop is one switch that stays where you flicked it. Put 8 switches in a row and agree "we all flip at the same drumbeat (the clock)" — now you can set an 8-bit pattern in one beat and it stays frozen until the next time you say "load." That row of switches is a register: the computer's tiny, super-fast scratch pad it keeps right next to its brain.


Flashcards

What is a register?
A group of N flip-flops sharing one clock, storing an N-bit word that updates atomically on the clock edge.
How many bits does one flip-flop store?
Exactly one bit (a 0 or a 1).
How many distinct values can an N-bit register hold?
2N2^N patterns (range 0 to 2N12^N-1 unsigned).
Why share a single clock across all flip-flops?
So all bits latch simultaneously and the word updates atomically, avoiding half-updated garbage values.
What is the characteristic equation of a D flip-flop?
Qnext=DQ_{\text{next}} = D, captured at the active clock edge.
What does the LOAD line do, and what is the update rule?
It selects new data vs. holding the old value: Qinext=LOADINi+LOADQiQ_i^{next} = \text{LOAD}\cdot\text{IN}_i + \overline{\text{LOAD}}\cdot Q_i.
What happens to a bare D-register (no LOAD) each clock edge?
It reloads its input every edge, so it does NOT hold a value if the input changes.
Why are registers the fastest storage in a CPU?
They store/read all bits in parallel hardware right beside the logic, with no addressing or looping overhead.
Largest unsigned value in an 8-bit register?
281=2552^8 - 1 = 255.
Does N bits mean N stored numbers?
No — it stores ONE number of width N bits; N is the width, not the count of values.

Connections

  • Flip-Flops — 1-bit memory — the building block.
  • D Flip-Flop and the Clock Edge — how a single bit latches.
  • Multiplexers — selecting between inputs — implements the LOAD line.
  • Binary Numbers and 2^N — why capacity is 2N2^N.
  • CPU Architecture — Register File — many registers grouped and addressed.
  • Clock and Synchronous Logic — why a shared timing signal matters.
  • Counters and Shift Registers — registers with feedback that move bits.

Concept Map

remembers

characteristic eq

replicate N times

holds

all FFs share

gives

prevents

extended per bit

feedback selects new vs old

controls

added to

Qi next = LOAD IN + notLOAD Qi

D flip-flop

Stores one bit

Q next = D at clock edge

Register

Stores N-bit word

Shared clock line

Atomic parallel update

Avoids race garbage

2-to-1 multiplexer

Load enable line

Hold or overwrite

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Socho ek single flip-flop ek chhota sa switch hai jo sirf ek bit (0 ya 1) yaad rakh sakta hai. Ab agar tumhe poora number, jaise 4-bit ka 1011, store karna hai, toh tum bas 4 flip-flops ek line mein rakh do. Yahi bundle hota hai ek register. Sabse important baat: in sabhi flip-flops ko ek hi clock par jodte hain, taaki saare bits ek hi instant par, ek saath update ho. Isi parallel nature ki wajah se register CPU ki sabse fast memory hoti hai — koi looping nahi, koi addressing nahi.

D flip-flop ka rule simple hai: Qnext=DQ_{next} = D, yaani clock edge par jo input wire pe tha, wahi freeze ho jaata hai. Isko N baar copy kar do toh har bit ke liye Qinext=DiQ_i^{next} = D_i. Lekin ek problem hai: bare register har clock edge pe naya input le leta hai, toh purani value ud jaayegi. Isiliye ek LOAD line lagate hain ek multiplexer ke saath: Qinext=LOADINi+LOADQiQ_i^{next} = \text{LOAD}\cdot \text{IN}_i + \overline{\text{LOAD}}\cdot Q_i. Jab LOAD=0, register apni hi value wapas store kar leta hai — matlab "hold". Yaad rakho: "LOAD low = leave it alone."

Capacity ka funda: NN bits ke saath kitne alag-alag patterns ban sakte hain? Har bit 2 choices deta hai aur N independent bits hain, toh 2×2×=2N2 \times 2 \times \dots = 2^N. Isliye 8-bit register 28=2562^8 = 256 values rakh sakta hai, range 00 se 255255. Dhyaan rakho — register ek time pe ek hi number rakhta hai, N alag numbers nahi; N toh sirf width hai. Yeh concept aage CPU ke register file, counters, aur shift registers samajhne ki neev hai.

Test yourself — How Computers Work

Connections