Skip to content
Step 4 of 105–7 minutes

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 4-Stage Model

The Fetch-Decode-Execute-WriteBack Cycle

What Happens Behind the Silicon:

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.

Simplified Educational CPU Model
Interactive 8-Bit Assembly Simulator

CPU Hardware Registers & Machine Stepper

Cycle Stage: READY
Select Assembly Program:Sequential Arithmetic

A straight 5-instruction linear pipeline computing 15 + 27 = 42 and writing back to RAM.

ROM Instruction Memory (5 instructions):
0x00MOV R0, 15
◀ CURRENT PC
0x01MOV R1, 27
0x02ADD R0, R1
0x03STORE [0x10], R0
0x04HALT

Each click performs one full fetch → decode → execute pass for the highlighted line.

Hardware Register File & RAM:
PC (Program Counter)
0x00
IR (Instruction Register)
MOV R0, 15
ACC (Accumulator)
0
R0 Register
0
R1 Register
0
RAM [0x10]
0x00
MOV = COPY: MOV R0, 15 copies 15 into R0. It does not erase 15.
[0x10] = Address: Square brackets mean "look inside RAM address 0x10".
Hardware Trace: Press “Step Instruction Cycle” (or the → key) to fetch and execute ROM[0x00].
Tip: click here, then use → to step and R to reset.

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 an if statement, loop, or function call (like JUMP), the PC is forcefully overwritten with a completely different address, jumping execution to another part of memory!
Active Learning — Predict Register Values

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 edit

Learning graph

Discussion

0 comments

Loading discussion…

Sign in to ask a question.