Skip to content
CurriculumLesson 35 ยท Architecture
Intermediate~14 min

Instruction Cycle

Every instruction follows the same rhythm: fetch, decode, execute, write back. Interrupts are checked between beats, not in the middle of one.

In plain English

The CPU is a cook: fetch the recipe line, decode it, do the step, and put the result on the plate.

By the end you will be able to

  • List the four phases of the instruction cycle.
  • Explain the role of the PC, IR, MAR, and MDR.
  • Trace a simple add instruction.
  • Know where interrupts are checked.
01

Fetch and decode

The program counter holds the address of the next instruction. The CPU copies the PC to the memory address register, reads the instruction into the memory data register, and loads it into the instruction register. The PC advances. The decoder determines the opcode, the operands, and the addressing mode.

lesson-35.osOS
MAR = PC
MDR = memory[MAR]
IR = MDR
PC = PC + instruction_size
decode(IR)
02

Execute and write back

The execution unit reads the operands, performs the operation, and writes the result to a register or memory. The write-back phase commits the result. Some instructions need several cycles: indirect addressing needs an extra memory read, and a multiply may take multiple cycles. The control unit sequences these steps.

lesson-35.osOS
operand1 = read(register or memory)
operand2 = read(register or immediate)
result = ALU(op, operand1, operand2)
write(result, destination)
03

Interrupts at instruction boundaries

The CPU checks for pending interrupts after completing an instruction. If one is pending, it saves the current PC and status, switches to kernel mode, and jumps to the handler. This is why an interrupt does not corrupt a partially executed instruction: the instruction either finishes or is restarted.

Key takeaways

  • The cycle is fetch, decode, execute, write back.
  • The PC points to the next instruction.
  • The IR holds the current instruction; MAR/MDR handle memory transfers.
  • Interrupts are checked at instruction boundaries.
  • Some instructions need extra cycles for operands.

Common pitfalls

  • Thinking the PC points to the current instruction after fetch; it advances.
  • Confusing the IR with the instruction memory.
  • Assuming every instruction completes in one cycle.

Kernel notes

  • Trace an add instruction through the four phases.
  • Name the registers and their jobs.
  • Explain why interrupts are checked at boundaries.

Quick check

0 / 2 answered

1. What does the program counter hold?

2. When does the CPU check for pending interrupts?