How Does a CPU Execute Instructions?
A CPU cannot think ahead or get bored. From the moment you turn on your computer until you power it down, the CPU repeats a relentless, four-step routine billions of times per second: Fetch → Decode → Execute → Write-Back.
This continuous loop is known as the Instruction Execution Cycle (or the Fetch-Execute cycle).
Why A Standard Cycle?
Without a strict sequence, electrical signals would collide and corrupt data. By breaking instruction handling into synchronized stages driven by the clock metronome, hardware guarantees that values are safely transferred before the next step begins.
The Factory Assembly Line Analogy
Think of a manufacturing robot: 1. Fetch: picks up a raw part from the supply shelf. 2. Decode: identifies the blueprint. 3. Execute: welds the piece into place. 4. Write-Back: places the assembled product into the output bin. Then repeats immediately!
The Fetch-Decode-Execute-WriteBack Cycle
Fetch Phase
The Control Unit looks at the address in the Program Counter (PC), reaches out over the memory bus into RAM, and copies the instruction bytes into the Instruction Register (IR). Then, the PC automatically increments.
Interactive CPU Hardware Stepper
Step through real instructions one clock tick at a time. Watch the Program Counter advance, registers update, and the ALU add 15 + 27.
CPU Hardware Registers & Machine Stepper
A straight 5-instruction linear pipeline computing 15 + 27 = 42 and writing back to RAM.
Each click performs one full fetch → decode → execute pass for the highlighted line.
MOV R0, 15 copies 15 into R0. It does not erase 15.Common Beginner Misconceptions
- "MOV cuts or deletes the source value."
Reality: The name "MOV" (Move) is a historical misnomer in assembly language. It does not cut-and-paste. It duplicates the electrical bits into the destination register, leaving the original source completely intact and unchanged. - "A CPU finishes an entire instruction before starting the next one."
Reality: While our educational simulator steps instructions one at a time, real modern CPUs use Instruction Pipelining. While instruction #3 is executing, instruction #2 is already being decoded, and instruction #1 is already being fetched! - "The Program Counter is just a counter that adds 1."
Reality: Normally it increments sequentially. But when your code hits anifstatement, loop, or function call (likeJUMP), the PC is forcefully overwritten with a completely different address, jumping execution to another part of memory!
In the CPU simulator, register R0 holds 15 and register R1 holds 27. When “ADD R0, R1” completes its Write-Back phase, what value will R0 and the Accumulator hold?
Lesson 04 Key Takeaways
- The CPU repeats the Fetch → Decode → Execute → Write-Back cycle continuously.
- Fetch reads from RAM at PC; Decode translates opcodes; Execute runs ALU math.
- Write-back saves the result to registers or memory for subsequent instructions.
Notessaved locally+
Notes stay in this browser. They are not uploaded.
Suggest an editLearning graph
Discussion
Loading discussion…
Sign in to ask a question.