Courses / Computer Science I
Introduction to Computers

The Instruction Execution Cycle

Computer Science I 275 words Free to read

The Instruction Cycle

A CPU runs programs by repeating the fetch–decode–execute cycle billions of times per second.

StepWhat happensKey register
FetchRead instruction at PC; advance PCProgram counter (PC)
DecodeInterpret the operation and operandsInstruction register (IR)
ExecutePerform the ALU operation or memory moveALU / registers / memory

During fetch, the PC holds the instruction address and advances immediately, assuming sequential flow: PCPC+1\text{PC} \leftarrow \text{PC} + 1. A jump or branch instruction changes this by writing a new address into the PC: PCtarget\text{PC} \leftarrow \text{target}.

Common pitfall: thinking a branch skips the cycle or works by magic. Every instruction goes through fetch–decode–execute; a branch simply overwrites a PC value that was already advanced.

Following a Real Instruction

RISC-V is an open instruction set where every instruction is 32 bits wide. Let's trace add x5, x6, x7 (add registers x6 and x7, store in x5) sitting at PC address 200:

Notice when the PC advanced: during fetch, before decoding. Hardware assumes sequential flow. A taken branch corrects it later by overwriting that already-advanced value.

Common pitfall: picturing the PC incrementing at the end of the cycle. It advances during fetch, and control-flow instructions overwrite that pre-set value.
The Instruction Execution Cycle

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

12practice questions
2interactive scenes

Introduction to Computers