Account
Play free

Build a CPU

First chapter free with a free account. Runs in your browser. Pricing

levels
23
chapters
6
things to install
0
Build a CPU Level 21 · Fetch, decode, execute · program running

Before a level, and after it.

Before Level 21 · Fetch, decode, execute
A Build a CPU level before it is played: the lesson and its goals, the processor on the board with a program in its memory, and the instrument that says what each clock beat does.
After Level 21 · Fetch, decode, execute
The same Build a CPU level finished: the program has run and halted, the display shows its answer, both goals are met, and the level says what it adds.

23 levels, 6 chapters.

Free

01Charge

  1. 01 A loop of charge Current flows only round a closed loop Experiment
  2. 02 Voltage is the push More volts, more current, until the filament burns Experiment
  3. 03 Resistance holds it back Ohm’s law: current is voltage over resistance Experiment
  4. 04 Two ways to draw a current Electron flow and conventional current Experiment

02Switches

  1. 05 Two switches in a row Switches in series make AND Experiment
  2. 06 Two switches side by side Switches in parallel make OR Experiment
  3. 07 A switch with no moving parts The transistor: a channel opened by a gate voltage Experiment

03Gates

  1. 08 NOT, the first gate The CMOS inverter, from one P and one N transistor Challenge
  2. 09 NAND from four transistors Pull-up and pull-down networks Challenge
  3. 10 NAND builds everything A universal gate, and building in blocks Challenge
  4. 11 XOR: one or the other Exclusive-OR from OR, NAND and AND Challenge

04Numbers

  1. 12 Counting with two symbols Binary place values, bits and bytes Experiment
  2. 13 Adding two bits The half adder: a sum and a carry Challenge
  3. 14 Carry in, carry out The full adder, from two half adders Challenge
  4. 15 Four bits at once A ripple-carry adder, and why it takes time Challenge

05Memory

  1. 16 A circuit that remembers The SR latch: feedback that holds one bit Challenge
  2. 17 Store on command The D latch and its enable wire Challenge
  3. 18 The clock and the register Flip-flops that capture on one clock edge Challenge

06The machine

  1. 19 Sixteen numbered cells RAM: addresses, writing and reading Experiment
  2. 20 One circuit, many operations The ALU and its zero and carry flags Experiment
  3. 21 Fetch, decode, execute The stored program and the instruction cycle Experiment
  4. 22 Your first program Machine code: load, subtract, add, show, halt Challenge
  5. 23 A loop that ends Jumps and a test: a loop that knows when to stop Challenge

A working model, not a real chip.

Modelled

  • A loop of wire solved with Ohm’s law: current from voltage and resistance, a lamp that brightens with current and burns out past its rating, and current that divides between parallel branches.
  • A transistor as a switch worked by voltage: no channel below about 2 V on the gate, a full one by 3.5 V.
  • A switch-level circuit simulator. Wires join pins into nets, the + and − rails and the switches drive them, a conducting transistor joins its source to its drain, and a net driven both ways is reported as a short circuit.
  • Gates that update one at a time, so a carry visibly ripples through an adder, and two cross-coupled NOR gates settle into a latch.
  • Every wiring puzzle is checked exhaustively: each row of its truth table on a fresh circuit, or each step of a test sequence for a circuit with memory. The 4-bit adder is tested on all 256 pairs of inputs.
  • An 8-bit accumulator processor with 16 bytes of RAM and ten instructions, stepped one clock beat at a time through fetch, decode and execute.

Simplified or left out

  • Analogue behaviour: capacitance, rise times, noise. On the wiring boards a wire is 1, 0, unconnected or shorted.
  • The LED’s own forward voltage, the way a lamp’s resistance changes as it heats, and the battery’s internal resistance.
  • How the control logic, the instruction decoder and the memory’s address decoder are wired from gates. In the last chapter they are blocks.
  • Interrupts, a stack, subroutines, pipelines, caches and everything else a modern processor adds.

Volts, amperes and ohms are real units and obey Ohm’s law. Electrons are drawn far larger, far fewer and far slower than they are, and the clock is slowed to a beat you can watch.

Primary sources

Level 1 takes a few minutes.

Also in the library: Kafka: Siege, Redis: Voxel Defense