From Switches to CPU · LogicLab
Build all the way from a single switch to a working CPU: flip series and parallel switches and a relay to discover AND, OR, and NOT; watch signals travel down glowing wires through logic gates and X-ray the transistors switching inside; wire up every gate from NAND gates alone, then build a half adder and a full adder and package them into chips; line up four full adders like column addition to watch carries ripple bit by bit to the top; finally, step the clock as your adder executes programs inside a tiny 4-bit CPU, and zoom out to see how many transistors fit on a chip.
Chapters
Can Switches “Think”?
A switch has only two states: open and closed. Write open as 0 and closed as 1, lamp off as 0 and lamp on as 1, and a circuit becomes a true-or-false question.
Click the switches directly in the scene. Put two switches in series and both must close to light the lamp; put them in parallel and closing either one lights it. Test all four combinations and watch the truth table on the right fill in row by row.
Then switch to the relay: energizing its coil turns it into an electromagnet that pulls open a contact in another loop. It is an electrically operated switch. In 1937, 21-year-old Claude Shannon showed in his master's thesis that switching circuits express logical “AND”, “OR”, and “NOT”. For the laws of circuits themselves, see VoltLab.
Logic gates
Pack last lesson's switching circuits into a box with only inputs and an output exposed, and you get a logic gate. Voltage on a wire is written as 1 (lit) and no voltage as 0 (dark).
Toggle the input switches on the left and watch signals travel into the gate, pause for a tiny delay, and light the output lamp. Switch gate types on the right to uncover each truth table: AND Y = A · B, OR Y = A + B, NOT Y = A; bubble-output NAND and NOR compute first and then invert; XOR outputs 1 when its two inputs differ.
Click “X-ray” to look inside: there are no moving parts at all, only a handful of transistors — tiny voltage-controlled switches. Use the top-left button to toggle between distinctive shapes and IEC symbols (&, ≥1, 1, =1).
The Universal NAND Gate
In this lesson you wire the board yourself. There are only NAND gates on the breadboard, and your job is to build the other gates out of them.
Wiring: drag from one pin to another (or click one pin, then the other). A wire must go from an output to an input; one output can feed several inputs, while each input accepts only one wire. Click any wire to remove it. Toggle the left switches anytime to watch signals flow through your circuit.
When ready, press Verify: every input combination is tested automatically against the target truth table. Once every row matches, package it as a chip. Real fabs work the same way: a CMOS NAND gate takes just four transistors — compact and fast — making it the universal building block. Stuck? Press “Hint a wire”.
Counting with Only 0 and 1
A single wire can represent only 0 or 1 — one bit. To represent larger numbers, line up several wires side by side: just like ones, tens, and hundreds in decimal, each position has its own place weight — except here the weights are 1, 2, 4, 8, carrying every two.
Flip the four switches: the lamp under each switch shows whether that bit is 0 or 1, while the seven-segment display on the right shows the decimal value. 1011 means 8 + 0 + 2 + 1 = 11.
Then press “Add 1” step by step: adding 1 when the lowest bit is already 1 resets it to 0 and sends a carry to the left. Adding 1 to 0111 ripples a carry across three bits; adding 1 when all four bits are 1 causes overflow.
Half adder
Adding two 1-bit binary numbers has only four cases: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10. The answer needs two bits: this column's Sum S and the Carry C to the next column.
Compare with the target truth table on the right: which gate matches column S, and which gate matches column C? Four gates sit on the board — pick the right two, wire A and B to them, and connect their outputs to lamps S and C. Leave the unused gates disconnected.
Once verified, package it into a half adder chip. In 1937, George Stibitz of Bell Labs brought home a few relays and two flashlight bulbs and wired up this exact binary adder on his kitchen table.
Full adder
In column addition, each column actually adds three bits: this bit of A, this bit of B, and the incoming carry Cin from the lower bit. A circuit that adds all three is called a full adder.
On the board sit two of the half adder chips (HA) you just packaged. Use the first HA to add A and B, then feed its sum into the second HA together with Cin; the second HA's sum is the final S.
Each half adder also has a carry output — if either one is 1, a carry goes to the next column. Pick the right gate to merge them into Cout, verify all eight rows, and package your full adder chip (FA).
4-Bit Adder
Four full adders stand in a row just like column addition: the top row of switches sets A, the second row sets B, and the bottom lamps show the Sum. Each full adder's carry-out feeds the carry-in of the next higher bit on the left — the orange wires are the carries.
Flip switches to pose a sum and watch signals propagate stage by stage. Try 1111 + 0001: a carry born in the lowest bit must ripple through all four full adders before the upper bits settle, which is why this is called a ripple-carry adder. The timing trace on the right records when each sum bit stabilizes.
On the right sits a “Sub” switch M: turn it on and every bit of B is inverted through an XOR gate while an extra 1 enters the lowest carry-in. Since A − B = A + B + 1, the very same adder handles subtraction too.
From Adder to CPU
The 4-bit adder you built now serves as this tiny CPU's ALU. Around it sit a few new blocks: registers A and B hold numbers; program memory stores instructions; the program counter PC tracks which instruction is next; and the control unit decodes each instruction to route numbers into the adder.
Each press of the clock runs one instruction in four beats: Fetch → Decode → Execute → PC + 1. Step through “3 + 4” first, then run “Countdown” and “3 × 4” — with no multiplier hardware, it multiplies by looping addition. You can edit the program on the right: click − and + beside an operand and run it again.
Finally, press “Zoom out” to count how many transistors take us from one switch to a modern chip. The 1971 Intel 4004 was 4-bit too, with 2,300 transistors. To see how machines “learn” with vast numbers of additions and multiplications, visit NeuroLab.
In-class testing
Look back over the eight topics and answer the multiple-choice questions below.
More labs
- VoltLab Circuit Lab
- Earth Motion Lab
- Cell · 3D structure
- Periodic Table · PeriodicLab
- Water Cycle 3D Sandbox · WaterCycle
- Neural Networks Reading Digits · NeuroLab
- Shenzhou Launch & Return · RocketLab
- We Were Here · ArtHistory
- Mendel's Pea Hybridization · PeaLab
- Humoral immunity · ImmuneLab
- The Cell's Energy Currency · ATPLab
- Solid Geometry · GeoSpace
- Contour 3D Lab
- Atmospheric Circulation Lab
- How Tides Form · TideLab
- Land and Sea Change
- Fluvial Landforms · RiverLab
- Geological Structures and Karst Sandbox · KarstLab
- Fly into the Eye · TyphoonLab
- Through the Earth · QuakeLab
- Microscope Bench · MicroLab
- The Structure of DNA · DNALab
- A Plant's Life · PlantLab
- The Stomach · StomachLab
- Cell Differentiation · StemLab
- Gene Expression · GeneLab
- Ecosystems · EcoLab
- Four Billion Years · DeepTime
- Preparing Gases in the Lab · GasLab
- Chemical Analysis Bench · AnalytLab
- Reaction Mechanisms · Molecular Animation
- Catalysts · CatalystLab
- Galvanic & Electrolytic Cells · ElectroLab
- Molecular Geometry · VSEPR
- Atomic Orbitals · Electron Cloud
- Chemical Reactions · The Micro World
- Conic Sections · ConicLab
- Function Graphs · FuncLab
- Compass & Straightedge · ConstructLab
- Pythagorean Theorem · PythagoLab
- Math Wonders · WonderLab
- Motion & Force · MotionLab
- Simple Machines · MachineLab
- Pressure & Buoyancy · FloatLab
- Thermodynamics · ThermoLab
- Heat & Changes of State · HeatLab
- Sound · SoundLab
- Optics Bench · OpticsLab
- Photoelectric Effect and Photons · PhotonLab
- Atomic Structure and Spectra · AtomLab
- Oscillations & Waves · WaveLab
- Electric & Magnetic Fields · FieldLab
- Famous Battles Sand Table · WarTable
- Changing Territories · HistoryAtlas