The fetch-decode-execute cycle and interrupts

A-Level Computer Science · Hardware and Processor Fundamentals

The cycle, in register transfer terms

Learn it as a sequence of register transfers, because that is how it is marked:

$\text{MAR} \leftarrow [\text{PC}]$ — copy the next address into MAR
$\text{PC} \leftarrow [\text{PC}] + 1$ — increment ready for the following instruction
$\text{MDR} \leftarrow [[\text{MAR}]]$ — fetch the contents of that memory location
$\text{CIR} \leftarrow [\text{MDR}]$ — move the instruction into the CIR
then decode the opcode in the control unit, and execute.

Why PC is incremented so early

Incrementing before execution means a jump instruction can simply overwrite the PC during execute, and the cycle continues correctly from the new address. Explaining this is a standard three-mark answer.

Interrupts

An interrupt is a signal from hardware or software requesting the processor's attention — a key press, a completed disk transfer, a division by zero. At the end of the current cycle the processor checks the interrupt register. If an interrupt is present and has higher priority than the current task, the processor pushes the contents of the registers (the process state) onto the stack, loads the address of the appropriate interrupt service routine, runs it, then pops the saved state back and resumes.

Two details that earn marks

First, the check happens at the end of a cycle, not mid-instruction — otherwise the machine state would be inconsistent. Second, saving to a stack is what allows nested interrupts: a higher-priority interrupt can interrupt an interrupt, and the last-in-first-out order restores everything correctly.

Worked example: tracing the cycle and a jump instruction

Memory contains: address $100$: LDD 200; $101$: ADD 201; $102$: JMP 100. Location $200$ holds $7$, location $201$ holds $5$. The PC starts at $100$, the ACC at $0$.

Trace the first three cycles, stating the values of the PC, CIR and ACC after each cycle.

Solution

Cycle 1.

$\text{MAR}\leftarrow100$; $\text{PC}\leftarrow101$; $\text{MDR}\leftarrow$ LDD 200; $\text{CIR}\leftarrow$ LDD 200.

Decode: load the contents of location $200$ directly into the ACC ⇒ $\text{ACC}=7$.

After the cycle: $\text{PC}=101$, $\text{CIR}=$LDD 200, $\text{ACC}=7$.

Cycle 2.

$\text{MAR}\leftarrow101$; $\text{PC}\leftarrow102$; $\text{CIR}\leftarrow$ADD 201.

Execute: $\text{ACC}=7+5=12$.

After the cycle: $\text{PC}=102$, $\text{ACC}=12$.

Cycle 3: the important part.

$\text{MAR}\leftarrow102$; $\text{PC}\leftarrow103$ (still incremented as usual!); $\text{CIR}\leftarrow$JMP 100.

Execute: the jump instruction overwrites the PC ⇒ $\text{PC}=100$.

After the cycle: $\text{PC}=100$, $\text{ACC}=12$.

Takeaway. The PC is still incremented to $103$ in the fetch phase and only then overwritten to $100$ in the execute phase. Precisely because the PC increment happens EARLY and independently, the control unit does not need to know in advance whether this instruction is a jump; it just fetches, increments, and lets the execute phase decide. The next cycle will run again from $100$, forming an infinite loop that keeps adding $5$ to the ACC.

Common mistake

Writing that the PC is incremented AFTER executing the instruction. If so, every jump would be overwritten back by the PC and no jump instruction could work. The correct order is: copy the PC to the MAR, increment the PC, and only then fetch and execute.

Key takeaway

Learn the cycle as four register transfers, be able to explain why the PC is incremented early, and for interrupts remember two details: the check is made at the end of the cycle, and state is saved to the stack so nested interrupts are still restored correctly.

← Von Neumann architecture, registers and buses · All A-Level Computer Science lessons · Practice A-Level Computer Science questions (free, instant scoring) · Assembly language, addressing modes and system software →