How a CPU Thinks
A computer's brain does the same tiny loop, billions of times a second. Run one by hand and watch it think.
The loop behind everything
A CPU does not really "think" like you. It repeats three small jobs, over and over.
FetchGet the next instruction
DecodeWork out what it means
ExecuteDo it
A CPU repeats fetch, decode, execute billions of times every second. That loop is the
whole show. Everything a computer does is this tiny cycle, run faster than you can blink.
Here is the secret: the instructions and the data are just numbers. A program is a list
of numbers, and the answers are numbers too. The CPU only ever moves and adds numbers around.
Read the program
This toy CPU knows only three commands. Here is a tiny program written in them.
The program3 instructions
0SET a, 2
1ADD a, 3
2SHOW a
SET a, 2 puts the number 2 into a box called a. ADD a, 3 adds 3 to
whatever is in a. SHOW a reads it out loud. Those boxes are called
, and each one just holds a number.
Down inside the chip, every one of these steps is built from
and
, the same switches you wired
earlier. Stack enough of them and switches turn into a machine that runs programs.
Run it, one step at a time
Press Step. Watch the CPU fetch the line, decode it, then execute it. The register fills as it goes.
Programnext line: 0
0SET a, 2
1ADD a, 3
2SHOW a
FetchGet the line
DecodeWhat does it mean?
ExecuteDo it
Ready. Press Step to start the cycle.
Registers
a
–
PC
0
PC is the "program counter": it remembers which line is next.
Output: 5
Tip: each Step moves one phase forward.
You just ran a program the slow way. A real CPU does this exact loop, but billions of times
a second, and never gets tired. That speed is the only magic. The steps are simple.
← The Foundry · every fact here is real science, kept simple. Tap the underlined words to dig deeper.