Part 14 · Electronics and Computing
The Computer
A machine that keeps its own instructions in its memory, as numbers, and carries them out one by one, millions of times a second. What the parts are — processor, memory, storage, input and output — how a stored-program computer works, how to build a small one, and how computers went from relays to tubes to chips.
- Difficulty
- ●●●●●
- Time
- Months for a small computer from bought or home-made chips; years from scratch for the whole chain behind it
- Steps from zero
- 51 prerequisites →
This unlocks
Displays, Printers and Data StorageMicroprocessors and Personal ComputersNetworks and the InternetProgrammingUltrasound, CT and MRISpaceflight and SpacecraftThe full path from nothing — 51 steps before this one
- Fire
- Cordage and Rope
- Stone Tools
- Finding and Preparing Clay
- Finding and Identifying Ores
- Sulfur
- Writing and Numbers
- Hunting and Trapping
- Basic Woodworking
- The Kiln
- Pottery
- Charcoal
- Arithmetic and Fractions
- Hides and Leather
- Lime
- Bricks
- Salt
- Mercury
- Lye and Potash
- Fermentation
- The Wheel and Axle
- Logic and Binary
- Glass
- Firebrick and Refractories
- Bellows
- Saltpeter
- The Lathe
- Gears
- Copper Smelting
- Iron (the Bloomery)
- Lead
- Laboratory Glassware
- Sulfuric Acid
- Pumps
- The Waterwheel
- Lenses
- Blacksmithing
- Gold and Silver
- Hydrochloric Acid
- The Battery
- The Vacuum Pump
- Magnets
- The Light Bulb
- Copper Wire
- Photography
- The Generator
- The Vacuum Tube
- The Electric Arc Furnace
- Pure Silicon
- Semiconductors and the Transistor
- Integrated Circuits
- The Computer
Do them roughly in this order. See it on the tech tree →
Why it matters
Every machine in this book does one thing. A loom weaves; a The Mechanical Clock keeps time; a The Relay Computer follows a short list of sums. A stored-program computer is different: it does whatever its program says, and its program is just a list of numbers kept in its own memory. Change the numbers and the same machine calculates tables for Navigation, keeps accounts, designs bridges, controls a furnace, sends messages across a network, or simulates a new medicine before anyone mixes it.
That flexibility makes the computer the most powerful tool in this book, and also the most dependent on everything else: it needs electricity, Semiconductors and the Transistor and Integrated Circuits, and above all people who can program it. This chapter explains how a computer works inside, describes one small enough to build and understand completely, and shows the realistic path from relays to chips.
How it works
Five parts
Every computer since the late 1940s has the same five parts:
- Processor — the part that does things. It contains a few registers (fast one-number memories), an ALU (arithmetic and logic unit: an adder like the one in The Relay Computer, plus AND, OR and NOT), and a control unit that sets everything else working in the right order. A clock gives it a steady beat.
- Memory — a long row of numbered cells, each holding one number. The cell's number is its address. The processor can read or write any cell, in any order, quickly.
- Storage — slower memory that keeps its contents with the power off: punched paper tape, punched cards, magnetic tape, drums, disks.
- Input — switches, keyboards, tape readers, sensors.
- Output — lamps, printers, screens, motors.
They are joined by buses: bundles of wires, one per bit, that carry an address from the processor to the memory, and data back and forth.
The stored program
The key idea is that instructions are numbers, kept in the same memory as the data. Each kind of instruction gets a code number. Here is a complete, small instruction set for a computer with 8-bit cells (numbers 0–255) and 256 cells of memory. Each instruction takes two cells: the code, then an address or a number. The register A (the accumulator) holds the number being worked on. The Programming chapter uses this same machine.
| Code | Name | What it does |
|---|---|---|
| 0 | HALT | Stop |
| 1 | LOAD a | A ← the number in cell a |
| 2 | STORE a | cell a ← A |
| 3 | ADD a | A ← A + cell a |
| 4 | SUB a | A ← A − cell a |
| 5 | LOADI n | A ← n itself (a constant) |
| 6 | JUMP a | Take the next instruction from cell a |
| 7 | JZ a | Jump to a if A is zero |
| 8 | JNEG a | Jump to a if A is negative |
| 9 | IN | A ← a number from the input |
| 10 | OUT | Show A on the output |
| 11 | LOADP a | A ← the cell whose address is in cell a (a pointer) |
| 12 | STOREP a | the cell whose address is in cell a ← A |
The two jump orders are what make a computer more than a calculator. With JZ and JNEG the program can decide: repeat a loop until a count reaches zero, or take one path or another depending on a result. With jumps, memory and enough time, a machine like this can compute anything that any computer can. Alan Turing proved this kind of universality in 1936, before any electronic computer existed.
Negative numbers use two's complement (see The Relay Computer): in 8 bits, 0 to 127 are positive, and 255 means −1, 254 means −2, down to 128 meaning −128. A number is negative when its top bit is 1. Letters are numbers too: in the common ASCII code "A" is 65, "B" 66, "a" 97, the digit "0" is 48 and a space is 32.
The cycle
The processor has a special register, the program counter (PC), holding the address of the next instruction. It repeats one cycle for ever:
- Fetch: copy the code at the address in PC into the instruction register (IR), and the next cell into the operand register.
- Advance: add 2 to PC, ready for next time.
- Decode: the control unit looks up which steps this code needs.
- Execute: do them. A jump simply puts a new address into PC. Then round again, until HALT.
How the control unit knows what to do
Each instruction is really a short sequence of tiny steps, one per clock tick, and each step just turns on a few control lines: "put PC on the address bus", "memory onto data bus", "data bus into IR", "add one to PC", "ALU result into A", and so on. For ADD:
| Tick | Control lines turned on |
|---|---|
| 1 | PC → address bus; memory → data bus → IR |
| 2 | PC + 1; PC → address bus; memory → operand register |
| 3 | PC + 1 |
| 4 | operand → address bus; memory → ALU input |
| 5 | ALU (A + input) → A; set the zero and negative flags |
Write this out for every instruction and you have a table. Build the table as a diode matrix: one horizontal wire for each (instruction, tick) pair, one vertical wire for each control line, and a diode (Semiconductors and the Transistor) wherever a line must be on. Later, the table is stored in a read-only memory chip and called microcode. Either way, the control unit — the "brain" of the processor — is nothing but a table and a counter.
What it is built from
The design above stays the same whatever the switches are made of. Only speed, size and power change:
| Switches | Memory | Additions per second | Size | Power |
|---|---|---|---|---|
| Relays (The Relay Computer) | Relay latches | 1–10 | A room | Hundreds of watts |
| Vacuum tubes | Delay lines, cathode-ray tubes, magnetic drums | 1,000–100,000 | A large room | Tens to hundreds of kilowatts |
| Separate transistors (Semiconductors and the Transistor) | Magnetic cores | 100,000–1,000,000 | Several cabinets | A few kilowatts |
| Chips | Chips | Millions to billions | A board, then a single chip | Watts |
For a rebuilding society, the realistic order is: relays first (to learn, and for a reliable calculator), then a small machine from simple home-made logic chips, with core or chip memory. Vacuum-tube computers work, but thousands of tubes burn out one every few hours; they were a stepping stone only because nothing better existed.
What you need
A small 8-bit computer running the instruction set above, built from simple chips:
| Part | Made from | Roughly |
|---|---|---|
| Clock | An oscillator chip or a ring of inverters, with a switch for slow, fast and single-step | 1–2 chips |
| Registers: A, IR, operand, output | 8 flip-flops each | 4–8 chips |
| Program counter | An 8-bit counter that can also be loaded (for jumps) | 2–4 chips |
| ALU | 8 full adders, plus XOR gates to flip B for subtraction, plus zero detection | 6–10 chips |
| Memory | 256 cells × 8 bits: one memory chip, or 2,048 ferrite cores | 1–8 chips |
| Control | Tick counter and a diode matrix or ROM | 3–5 chips plus a few hundred diodes |
| Front panel | 8 address switches, 8 data switches, "deposit", "examine", "run", "stop", "step"; a lamp on every bit of every register | About 25 switches, 50 lamps or LEDs |
| Power | A steady 5 V supply (for most chip families) from a The Transformer, rectifier and regulator, or from batteries | |
| Wiring | Hundreds of short wires, a soldering iron, a board with sockets | Soldering and Brazing |
That is 30–40 simple chips — the same as the hobby computers of the 1970s. If your chips hold only a few gates each, count on 400–600 gates; if you build from separate transistors, about 3,000–5,000 transistors and as many resistors.
Where to find it
Chips, transistors and diodes come from Integrated Circuits and Semiconductors and the Transistor; lamps from The Light Bulb; switches and wire from Copper Wire and Sheet Metal and Rolling.
For core memory, ferrite is made from iron oxide — rust, or powdered hematite (Finding and Identifying Ores) — mixed with oxides of manganese (from the black, sooty manganese ores also used in Glass making) and magnesium. Old machines and electronics in ruins are full of usable chips and memory; test them and use them, but this chapter does not depend on them.
Step by step
Build it one block at a time, and give every register its own row of lamps. A computer you can watch, one tick at a time, is a computer you can debug.
- Clock and single step. Make the clock first, with a push button that gives exactly one tick per press. You will use single-step far more than full speed.
- Registers. Build A and the output register; load them from switches; check every bit.
- ALU. Wire the adder between A and a switch register standing in for memory. Test additions and subtractions, with the carry and zero lamps, exactly as for the relay adder: 0+0, 1+1, 127+1 (should show negative), 255+1 (zero, with carry), 5−5 (zero flag on).
- Memory and front panel. Connect the memory with the address switches and data switches. "Deposit" writes the data switches into the cell set on the address switches; "examine" shows a cell on the lamps. Fill all 256 cells with 01010101, then 10101010, then each cell with its own address; read them all back. This finds stuck bits and addressing faults.
- Program counter and IR. Add the counter; make "examine next" step through memory. Add the instruction register.
- Control unit. Write the tick table for each instruction on paper first. Build the diode matrix. Start with only LOAD, STORE, ADD and HALT. Single-step through a three-instruction program and check every lamp against your paper at every tick.
- The rest of the instruction set, one at a time, with a tiny test program for each. JZ and JNEG need the program counter to load from the operand register when the flag is set.
- Output and input. A row of lamps first; later a typewriter worked by relays or a The Teleprinter so the computer can print letters (see Displays, Printers and Data Storage).
- Storage. Paper tape is the simplest lasting storage: a strip of strong Paper 2.5 cm wide with up to eight holes across, one row per number. Read it by shining a light through it onto eight photocells, or with spring fingers that drop through holes to touch a metal drum. Punch it with eight solenoid-driven punches. Later you can record numbers as tones on magnetic tape (Recording Sound): for example one pitch for 0 and twice that pitch for 1, a few hundred bits per second.
- A loader. The first program to write and keep: a short routine, entered by hand on the switches, that reads a paper tape into memory and then jumps to it. After that, you never need to enter a long program by hand again.
Core memory, if you build it
Before memory chips, nearly all computers from the mid-1950s to the mid-1970s used magnetic cores: tiny rings of ferrite, each storing one bit as the direction it is magnetised.
- Make the ferrite: grind iron oxide with manganese and magnesium oxides to a fine powder, mix with a little binder (gum or wax), press into rings about 2 mm across with a 1.2 mm hole, and fire at about 1,200–1,350 °C. The exact mix and firing make the difference between a core that snaps cleanly from one direction to the other (good) and one that drifts (useless). Expect many trial batches; test each batch as below.
- Test a core: thread a drive wire and a sense wire through one ring. Send a current pulse one way, then the same way again: the second pulse should give almost nothing on the sense wire. Then a pulse the other way: a clear kick. Find the current that just flips it (typically a few hundred milliamps for cores this size); half of it must never flip it.
- Thread a plane: 16 × 16 cores on X and Y wires, with a sense wire through all of them and an "inhibit" wire (used to write 0s) through all of them. Eight planes make 256 eight-bit words. It is slow, fiddly needle work, best done under a magnifier.
- Drive and sense: transistor switches send the half-currents; an amplifier on each sense wire detects the small pulse. Reading erases the core, so every read is followed at once by writing the same value back.
How to tell it worked
- Every block passes its own tests before the next is added (steps 1–7).
- A memory test program — the computer writes a pattern into every cell, reads it back and halts with an error lamp if any cell is wrong — runs all night without stopping.
- An instruction test program exercises every instruction and every jump, and ends by showing a known number.
- A real program — a times table, a square root, the sum of a list — gives the same answers as careful hand calculation.
Note Troubleshooting. Works on single-step, fails at speed → some path is too slow (often the carry through the adder, or memory). Slow the clock until it works, then find and speed up the slow part. Random errors that come and go → noisy or sagging power. Put a capacitor across the supply at every chip, use thick supply wires, and connect all the grounds firmly together. A bit is always 1 or always 0 → an input left unconnected ("floating") or a broken wire. Every unused input must be tied to + or −. Garbage on the bus → two things are driving the bus at once. Check that the control table never turns on two "→ bus" lines in the same tick. A jump goes to the wrong place → the flags are being set by the wrong instruction, or the PC loads at the wrong tick. Core memory reads all 0s → current too low to flip the cores, or the sense amplifier is too weak. Reads all 1s → current too high, so half-selected cores flip too.
Dangers
Danger High voltage. Vacuum-tube machines and the power supplies for cathode-ray displays use hundreds to thousands of volts, and their filter capacitors hold a lethal charge for minutes after switching off. Mains-powered supplies for any computer can kill. Switch off, wait, and discharge capacitors with an insulated wire before touching anything inside. See Wiring and Electrical Safety.
- Fire. A short on a low-voltage supply can deliver tens of amps. Fuse every supply.
- Lead solder and its fumes: work in moving air; wash hands before eating.
- Eyes: clipped wire ends fly; wear something over your eyes when cutting.
- Data loss is not a danger to life, but it can destroy years of work: see Programming for keeping programs and knowledge safe.
What this unlocks
- Programming: making the computer do useful work, and keeping that work safe.
- Networks and the Internet: computers talking to each other, over wires and by Radio.
- Control of machines, from furnaces to looms, by a computer reading sensors and switching motors (Process Controllers and Control Valves, Microcontrollers).
- Faster and bigger computers: more bits per word, more memory, many chips becoming one chip (Microprocessors and Personal Computers).
How it was first done
The idea of a programmable calculating machine is Charles Babbage's Analytical Engine (designed from 1834, never finished), for which Ada Lovelace wrote what is often called the first program, in 1843. In 1936 Alan Turing described an imaginary "universal machine" that could imitate any other calculating machine given its description as data — the theory of the stored program.
The first electronic machines came in the 1940s: the Atanasoff–Berry Computer (Iowa, 1942) solved equations with a few hundred tubes and a rotating drum of capacitors; Colossus (Bletchley Park, 1944) broke German codes with about 1,600 and then 2,400 tubes; ENIAC (Philadelphia, 1945) had 17,468 tubes, used 150 kilowatts, did 5,000 additions a second, and was programmed by plugging cables. In 1945 John von Neumann wrote a report describing a machine that would keep its program in its own memory. The first program ever to run from electronic memory ran on 21 June 1948 on the "Manchester Baby", built by Frederic Williams, Tom Kilburn and Geoff Tootill, which stored 32 words on the face of a cathode-ray tube. EDSAC at Cambridge, using mercury delay lines, began regular work in May 1949.
Magnetic core memory, developed for MIT's Whirlwind computer and working from 1953, made memory reliable. Transistor computers followed from the mid-1950s; integrated circuits flew to the Moon in the Apollo Guidance Computer in 1969; and in 1971 Intel put a whole simple processor on one chip, the 4004. From 1975, hobbyists were building computers like the Altair — programmed, at first, by flipping front-panel switches exactly as described in this chapter.
Source: content/entries/electronics/computer.md