Nib asked
How does a CPU process data?
A CPU only ever repeats one loop, fetch, decode, execute, write back, on tiny instructions; caches and pipelines exist to hide how slow memory is next to that loop.
11 steps, drawn by Nib. Read it here, or watch him draw it. Updated .
1the loop
A processor knows no photos, no words, no Python. It repeats one loop: fetch an instruction, decode it, execute it, store the result. At four gigahertz, that is four billion loops a second.
2four instructions
Take x equals a plus b. The compiler turns it into four instructions: load a, load b, add, store x. Instructions and data are both just numbers in memory.
3the machine
Here is the machine. Memory on the left holds instructions and data. Inside the chip, a program counter tracks the next instruction, and a few registers hold the numbers being used.
4load
Instructions one and two load the numbers: seven and five are copied from memory into registers r1 and r2. Registers are the only storage the arithmetic unit touches.
5the ALU
Instruction three, add, goes to the arithmetic logic unit, the A-L-U: a circuit of logic gates that takes two inputs and produces their sum.
6write back
The sum, twelve, lands in register r3. Instruction four stores it back to memory as x. Then the program counter steps on and the loop begins again.
7memory is slow
Here is the catch. A register answers in about a quarter nanosecond, the closest cache in about one, but main memory takes roughly a hundred. That is hundreds of cycles for one read.
8caches
So chips keep recently used data in small, fast caches, betting you will reuse it. A hit costs a few cycles. A miss stalls the core while it waits.
9the pipeline
Doing the loop one instruction at a time would leave most of the hardware idle. A pipeline overlaps the stages: while one executes, the next decodes and the one after is fetched.
a common mix-upA CPU core does not finish one instruction before starting the next: pipelining overlaps their stages, and wider cores start several per cycle.
10going wide
Modern cores go further. They run several pipelines side by side, execute out of order, guess which way branches go, and a chip packs many cores, each with its own loop.
11the whole idea
So, the whole idea: every program is that loop of fetch, decode, execute and write back, with fast caches and overlapped stages hiding the slow trip to memory.
Under every app, a chip repeats one humble loop billions of times a second, and its real art is hiding the wait for memory.