A CPU runs one tiny loop forever: fetch, decode, execute. That loop is all “running code” means.
- Fetch: read the next instruction from memory. The program counter (PC) holds that instruction’s address. It’s a register, a tiny storage slot inside the CPU.
- Decode: work out what the instruction means, like “add these two numbers”.
- Execute: do it. The ALU, the CPU’s math unit, does the arithmetic.
Then the PC moves to the next instruction, and a jump or an
ifjust changes the PC.
Think of a cook with a finger on the current line of a recipe. The finger is the PC, reading the line is fetch, understanding it is decode, and cooking is execute.
Every for, if and function call in your Rust ends up as this loop, billions
of times a second.
Try this
Paste this into Compiler Explorer, pick Rust, and count the assembly instructions — each one is one trip around the loop:
fn add(a: i32, b: i32) -> i32 { a + b }
Source: Instruction cycle on Wikipedia