Computer Architecture
Build a 2-bit register: two flip-flops, one LOAD
To build a 2-bit register, take two register bits, each a D flip-flop with a load picker in front of it, and give them one shared LOAD line and one shared clock. LOAD at 1 and the next tick stores both input bits at once; LOAD at 0 and every tick keeps what's there. Feed it from an adder and it becomes an accumulator, the register a simple processor keeps its working value in.
Parts
- Two D flip-flops, one per bit
- Four AND gates and two OR gates, two ANDs and an OR per bit
- One NOT, shared by both bits
- Two input switches, D1 and D0, a LOAD switch, a clock, and a display
Wire each bit
For each bit, the picker in front of D:
- One NOT LOAD, feeding both bits' keep gates.
- Load gate: AND the bit's input with LOAD.
- Keep gate: AND the bit's own Q with NOT LOAD.
- OR the two into the flip-flop's D.
- Clock: the same clock to both flip-flops, untouched.
- Display: D1's bit to the 2s input, D0's bit to the 1s.
Test it in sequence
| Step | Inputs | LOAD | Ticks | Display |
|---|---|---|---|---|
| 1 | 10 | 1 | 1 | 2 |
| 2 | 11 | 0 | 1 | still 2 |
| 3 | 11 | 1 | 1 | 3 |
| 4 | 00 | 0 | 2 | still 3 |
| 5 | 00 | 1 | 1 | 0 |
Steps 2 and 4 are the point: the inputs change, the clock ticks, and the stored value doesn't move.
Live experiment
Load, hold, load again
Two register bits share one LOAD and one clock, and their outputs drive a display. Set D1, D0 and LOAD and tick by hand, or run the test: load 2, change the inputs with LOAD off, load 3, two ticks with LOAD off, load 0. Two wrong builds show what the test catches.
“Project: Accumulator” is the project that ends Register Reef, Computer Architecture World 1. Free with an account. Lessons unlock in order, so you’ll do the 6 before it first.
What the test catches
- No keep path: a flip-flop with its input wired straight to D copies it on every tick, so step 2 shows 3 instead of 2.
- Bits swapped on the display: loading 10 shows 1 instead of 2.
- LOAD wired to the clock pin: the register loads whenever LOAD changes and ignores the real clock.
From register to accumulator
Connect the ALU's result to the inputs and the register's outputs to one of the ALU's inputs, and you have a real accumulator. An ADD instruction raises LOAD for one tick: the register takes A + B, and on the next instruction that sum is the A. Load, add, add again, and the total accumulates in two flip-flops, or in eight, or sixty-four.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Project: Accumulator” is the project that ends Register Reef, Computer Architecture World 1. Free with an account. Lessons unlock in order, so you’ll do the 6 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: Its own Q, 1: the value is kept. With LOAD at 0 the IN gate is closed and the keep gate, fed by NOT LOAD, is open: Q goes back round to D and the tick reloads the same value.
- Why not “Nothing”? D is always fed something. With LOAD at 0 it's fed Q, so the tick reloads the 1.
- Why not “IN”? IN only reaches D through the gate LOAD opens. With LOAD at 0 that gate is shut.
- Why not “0”? Nothing forces D to 0. The keep gate passes Q, which is 1.
Show the answer
Answer: To the probe, and back to the keep gate's input. Q is the output, and it's also what the keep path feeds back to D. Two wires from Q.
- Why not “To the clock”? The clock pin takes the clock. Q is data, and it goes to the probe and the keep gate.
- Why not “Only to the probe”? Without the wire back to the keep gate there's nothing to reload when LOAD is 0, so the register can't hold.
- Why not “To IN”? IN is the outside input. Q goes back through the keep gate, not onto IN.
Show the answer
Answer: LOAD is 0. The picker feeds Q back to D.
- Why not “The clock stops”? The clock never stops. The register holds by reloading its own value on every tick.
- Why not “LOAD is 1”? With LOAD at 1 the register takes IN on the next tick, replacing its value.
- Why not “IN is 0”? IN can be anything. With LOAD at 0 it's ignored; with LOAD at 1 a 0 would be loaded.
“Project: Accumulator” is the project that ends Register Reef, Computer Architecture World 1. Free with an account. Lessons unlock in order, so you’ll do the 6 before it first.
Questions people ask
What is an accumulator in a CPU?
The register that holds the working value in a simple processor. The ALU takes the accumulator and another number, and its result is loaded back into the accumulator: add, add again, and the total accumulates. The 6502 and other early processors were built around one.
Why do both bits share one NOT gate?
Both bits need NOT LOAD, and it's the same signal for each. One inverter can drive both keep gates, so a register of any width needs only one.
How many gates does an 8-bit register need?
Eight D flip-flops, and for the load picker on each: two ANDs and an OR per bit, 16 ANDs and 8 ORs in all, plus a single shared NOT. Chips like the 74HC377 put all of that in one package.
Related topics
- How a register holds a value until it's told to loadA flip-flop with a picker in front: load when told, keep what you have the rest of the time.
- How a D flip-flop worksCopy D to Q at the clock's rising edge, then hold it: one bit of memory.
- What is an ALU, and how does it work?Work out every answer at once, then let the opcode pick one: the heart of a CPU.
- The fetch-decode-execute cycle explainedFetch an instruction, decode it, carry it out, repeat: how every CPU runs.