Part one: Electrons · Day 9 of 60
From gates to a computer
A computer needs four abilities: to hold a number, to do arithmetic, to compare and to choose what to do next. Today you build each from gates, put them together into a small processor and run a program on it.
By the end of today you can
- Show how gates add two binary numbers and how feedback lets a circuit remember
- Describe the fetch, decode and execute cycle of a processor
- Read a short program in machine code and say what an instruction set is
Instructions are numbers
In June 1945 the mathematician John von Neumann circulated a 101-page draft describing a machine that had not yet been built. Its central idea was that a computer's instructions should be kept in the same memory as its data, as numbers, and fetched one after another.
Before that, a new problem meant days of rewiring. After it, a new problem meant loading a different list of numbers. Every computer since has worked this way, from a mainframe to the chip in a thermostat. It is called the stored program.
Today you assemble such a machine from yesterday's gates. The one in the playground has sixteen bytes of memory and eleven instructions, and it is a real computer.
Numbers in bits
Computers count in binary: every digit is 0 or 1, and each place is worth twice the one to its right. Eight bits make a byte.
Everything else is a convention for what the numbers mean. Text is numbers: a capital A is stored as 65. A negative number is stored in two's complement, a scheme in which 1111 1111 means −1, chosen because it lets the same adding circuit do subtraction. A color is three bytes. An instruction, as you will see, is a byte too.
Arithmetic from gates
Add two bits. There are four cases: 0 + 0 is 0, 0 + 1 and 1 + 0 are 1, and 1 + 1 is 2, which in binary is 10: write 0, carry 1.
Look at the pattern. The sum digit is 1 when the inputs differ. That is XOR from yesterday. The carry is 1 when both are 1. That is AND.
A half adder: one XOR and one AND
To add longer numbers, each column also has to take in the carry from the column to its right. That needs a slightly larger circuit, the full adder.
A full adder: three inputs, two outputs
Chain eight of these, each passing its carry to the next, and you have an adder for two bytes. Subtraction is addition of a two's-complement number. Multiplication is repeated adding and shifting. Arithmetic is gates and nothing more.
Memory from feedback
Yesterday's gates have no memory. Their outputs depend only on what the inputs are now. To remember, a circuit needs its output fed back to its own input.
Cross two NOR gates, so that each one's output is an input to the other, and the pair settles into one of two stable states and stays there. Pulse one input and it flips to the other state and stays there. You have stored one bit.
Add a few more gates so that the stored bit can change only at one precise moment, and you have a flip-flop. Put eight side by side and you have a register, which holds one byte.
Fast memory inside a processor works on this principle, with six transistors for each bit. The bulk memory in a computer uses yesterday's cheaper trick, one transistor and one capacitor per bit, at the price of having to refresh it.
The clock
The moment at which every flip-flop is allowed to change is set by the clock, a square wave ticking between 0 and 1, timed by a quartz crystal.
The clock solves yesterday's glitch problem. Between ticks, signals ripple through the gates and outputs flicker while they settle. Nothing captures those wrong values. At the tick, every register takes whatever is at its input, which by then is correct. The clock can run no faster than the slowest path through the logic allows.
Choosing
Two more small circuits complete the kit. A multiplexer is a switch made of gates: a few control bits choose which of several inputs passes through to the output. A comparator checks whether a result is zero. With those, a machine can do different things depending on its own results.
Putting a processor together
The parts of a small processor
- MemoryNumbered cells, one byte each. Holds the program and the data together.
- Program counterA register holding the number of the cell where the next instruction is.
- Instruction registerHolds the instruction being carried out now.
- Register AThe working register. Results of arithmetic land here.
- Arithmetic logic unitThe adder and its relatives. Also sets flags: was the result zero, did it overflow?
- Control logicGates that read the instruction and open the right paths between the other parts.
The arithmetic logic unit, or ALU, is where the adder lives. The program counter is what makes the machine go: it says where to look next.
On every tick, or every few ticks, the processor does the same three things.
The cycle that every processor repeats
- FetchCopy the byte at the address in the program counter into the instruction register. Add one to the program counter.
- DecodeThe control logic works out which instruction the byte stands for.
- ExecuteCarry it out: load, add, store, or change the program counter to jump.
That loop is the fetch-decode-execute cycle. A processor is a machine for running it, billions of times a second.
Instructions are numbers, again
An instruction is a byte, or a few bytes, that the control logic understands. In the playground's machine the first four bits say what to do. That part is the opcode. The last four bits give a memory address.
| Bits | Name | What it does |
|---|---|---|
| 0001 aaaa | LDA | Load register A from memory cell a |
| 0010 aaaa | ADD | Add the number in cell a to A |
| 0011 aaaa | SUB | Subtract the number in cell a from A |
| 0100 aaaa | STA | Store A into cell a |
| 0110 aaaa | JMP | Jump: take the next instruction from cell a |
| 1000 aaaa | JZ | Jump to cell a only if the last result was zero |
| 1110 0000 | OUT | Copy A to the display |
| 1111 0000 | HLT | Halt |
A program is a list of these bytes. That raw form is machine code. The short names, LDA and ADD, are assembly language, a notation for people. Languages such as Python and C are translated down to machine code by other programs before they run.
Notice what the machine cannot tell. Cell 14 holds 0001 1100. As data that is 28. If the program counter ever pointed there, the very same byte would be read as an instruction, LDA 12. A byte is an instruction only because the processor happens to fetch it as one. That is the source of the computer's flexibility, since programs can write other programs. It is also the source of a large class of security holes, which come down to tricking a machine into running data.
The jump instructions are what turn a calculator into a computer. JZ lets a program test a result and take one path or another. With that it can loop, count and decide.
From this to the chip in your laptop
The set of instructions a processor understands is its instruction set architecture, or ISA. Three matter today.
- x86, from Intel in 1978, runs most desktop computers and servers.
- Arm, designed in Britain in the 1980s, runs nearly every phone and a growing share of everything else. For 35 years Arm only sold the design, and other companies built the chips. In March 2026 it released the first chip of its own, a processor for AI data centers (checked November 2026).
- RISC-V, begun at Berkeley in 2010, is an open standard that anyone may use without a license.
A real processor has 64-bit registers where ours has 8, billions of bytes of memory where ours has 16, and hundreds of instructions. It runs several instructions at once in a pipeline, guesses which way jumps will go and keeps copies of recent data close by. The loop is the same.
Speed came less from the clock than you might think. Intel's 4004 ran at 740 kilohertz in 1971. A fast processor today runs at about 5 gigahertz, around 7,000 times faster. In the same period the number of transistors rose by a factor of twelve million. Most of the gain came from doing more work on each tick.
A graphics processor takes this to an extreme: thousands of small arithmetic units performing the same operation on many numbers at once. That turned out to be exactly what neural networks need, which is the story of day 20.
Playground · 10 minutes
A tiny computer
Eight-bit numbers, sixteen bytes of memory and eleven instructions. Step through a program and watch each instruction change the machine.
Try these
Scenario · 2 decisions
What would you do?
This case is invented. A founder building a controller for factory machines explains a design choice: "We picked a four-core chip at 2 gigahertz over a single-core chip at 4 gigahertz. Four times two is eight, and eight beats four."
Quiz · 5 questions
Check what stayed
Bench work · 30 minutes
Take it to the bench
Things to measure, take apart, look up or work out by hand. No equipment is needed unless a prompt says so. Your notes are saved in this browser and collected on the Lab notes page.
Words to keep
- Binary
- Counting with two digits, 0 and 1, where each place is worth twice the one to its right.
- Byte
- A group of eight bits, able to hold 256 different values.
- Hexadecimal
- Counting with sixteen digits, 0 to 9 and A to F, used as shorthand for groups of four bits.
- Two's complement
- The usual way of storing negative numbers in binary, chosen so that one adder handles both addition and subtraction.
- Adder
- A circuit of gates that adds two binary numbers.
- Flip-flop
- A circuit that stores one bit and changes only on a tick of the clock.
- Register
- A row of flip-flops holding one number.
- Clock
- The regular signal that tells every register in a processor when to take a new value.
- Multiplexer
- A circuit that passes one of several inputs to its output, chosen by control bits.
- Arithmetic logic unit
- The part of a processor that adds, subtracts and compares, usually shortened to ALU.
- Program counter
- The register holding the address of the next instruction.
- Instruction
- One step of a program, stored as a number that the processor's control logic understands.
- Opcode
- The part of an instruction that says which operation to carry out.
- Machine code
- A program in the form the processor runs: a list of numbers.
- Assembly language
- Machine code written with short names in place of numbers.
- Stored program
- Keeping a computer's instructions in the same memory as its data.
- Instruction set architecture
- The set of instructions a processor understands, usually shortened to ISA.
- Fetch-decode-execute cycle
- The loop a processor repeats: get the next instruction, work out what it is, carry it out.
Watch, read and build
- Watch: Ben Eater, "Building an 8-bit breadboard computer". He builds a machine much like today's playground from chips and wire, one part per video.
- Read: But How Do It Know? by J. Clark Scott. A complete computer, gate by gate, with nothing left out.
- Play: Turing Complete, a game in which you build a processor from gates and then program it.
- Read: John von Neumann, "First Draft of a Report on the EDVAC" (1945). The document today's lesson opened with.
Sources for dated facts checked November 2026
- TechCrunch: Arm is releasing its first in-house chip in its 35-year history March 24, 2026. A server processor for AI data centers, with Meta as the first customer. Until then Arm only licensed its designs.