◆ Rebuild

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 →

You need first

Integrated CircuitsLogic and Binary

This unlocks

Displays, Printers and Data StorageMicroprocessors and Personal ComputersNetworks and the InternetProgrammingUltrasound, CT and MRISpaceflight and Spacecraft
The full path from nothing — 51 steps before this one
  1. Fire
  2. Cordage and Rope
  3. Stone Tools
  4. Finding and Preparing Clay
  5. Finding and Identifying Ores
  6. Sulfur
  7. Writing and Numbers
  8. Hunting and Trapping
  9. Basic Woodworking
  10. The Kiln
  11. Pottery
  12. Charcoal
  13. Arithmetic and Fractions
  14. Hides and Leather
  15. Lime
  16. Bricks
  17. Salt
  18. Mercury
  19. Lye and Potash
  20. Fermentation
  21. The Wheel and Axle
  22. Logic and Binary
  23. Glass
  24. Firebrick and Refractories
  25. Bellows
  26. Saltpeter
  27. The Lathe
  28. Gears
  29. Copper Smelting
  30. Iron (the Bloomery)
  31. Lead
  32. Laboratory Glassware
  33. Sulfuric Acid
  34. Pumps
  35. The Waterwheel
  36. Lenses
  37. Blacksmithing
  38. Gold and Silver
  39. Hydrochloric Acid
  40. The Battery
  41. The Vacuum Pump
  42. Magnets
  43. The Light Bulb
  44. Copper Wire
  45. Photography
  46. The Generator
  47. The Vacuum Tube
  48. The Electric Arc Furnace
  49. Pure Silicon
  50. Semiconductors and the Transistor
  51. Integrated Circuits
  52. 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.

Memory addressholds 01LOAD 120 23ADD 321 42STORE 522 610OUT 70 80HALT … 207data 215data 2212answer …to 255 Processor Control unitreads each instructionand switches the otherparts on in order Clocksteady ticks PCprogram counter:address of next step IRinstruction register:the instruction being done FlagsZ: result zero; N: negative Aaccumulator:the working number ALUadds, subtracts addressbus data bus Inputswitches, keyboard,tape or card reader Outputlamps, printer,screen Storagepunched tape, magnetictape, drum or disk
Fig. 1 Inside a simple computer. The processor sends an address along the address bus; the memory answers along the data bus. The memory holds a short program (at addresses 0 to 9) and its data (20 to 22), all as plain numbers.

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:

  1. Fetch: copy the code at the address in PC into the instruction register (IR), and the next cell into the operand register.
  2. Advance: add 2 to PC, ready for next time.
  3. Decode: the control unit looks up which steps this code needs.
  4. Execute: do them. A jump simply puts a new address into PC. Then round again, until HALT.
The cycle every stored-program computer repeats, millions of times a second 1. Fetch copy memory[PC] into IR, and the next cell as the operand 2. Advance PC becomes PC + 2, ready for next time 3. Decode the control unit looks up which steps this order needs 4. Execute do them; for ADD: A becomes A + memory [operand] and round again, until HALT Running the example program (memory 20 holds 7, memory 21 holds 5) PC Instruction What happens A after memory[22] 0 1 20 = LOAD 20 A ← memory[20], which holds 7 7 0 2 3 21 = ADD 21 A ← 7 + memory[21] (5) 12 0 4 2 22 = STORE 22 memory[22] ← A 12 12 6 10 0 = OUT show A on the lamps: 00001100 12 12 8 0 0 = HALT stop 12 12
Fig. 2 The fetch–execute cycle, and the example program run step by step.

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.

  1. 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.
  2. Registers. Build A and the output register; load them from switches; check every bit.
  3. 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).
  4. 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.
  5. Program counter and IR. Add the counter; make "examine next" step through memory. Add the instruction register.
  6. 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.
  7. 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.
  8. 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).
  9. 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.
  10. 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.

A plane of core memory: 16 bits tiny rings of ferrite, 1–2 mm across, threaded on a grid of wires Y wires ½ current ½ current X wires Dashed: the sense wire, threaded through every core. Red core: the only one that gets the full current, so the only one that can flip. How a core holds a bit 10 magnetised clockwiseanticlockwise It stays magnetised one way or the other with no power at all. Half the flipping current does nothing. Send half along one X wire and half along one Y wire: only the core where they cross flips. To read: try to write 0. If the core held 1, it flips, and the sense wire gets a small pulse. Then write the 1 back.
Fig. 3 Core memory. Each ferrite ring holds a bit as the direction of its magnetism, with no power at all. Half the flipping current is sent along one X wire and half along one Y wire, so only the core where they cross is flipped.
  1. 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.
  2. 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.
  3. 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.
  4. 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

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