← IGCSE Computer Science Paper 1

Saving the CPU's state before handling an interrupt

Before running the ISR, the CPU stores its register contents, including the program counter, so the interrupted task can later carry on exactly where it stopped.

Understanding Saving the CPU's state before handling an interrupt in IGCSE Computer Science Paper 1

What it does: Restoring the saved values returns the registers and program counter to how they were before the interrupt. The register contents are stored so the interrupted task can carry on later. Deleting them would lose the task's work. Saving the state means no progress is lost. The task resumes from the point it was interrupted. The program counter holds the address of the next instruction, so saving it lets the CPU return to the right place after the ISR.

Common mistakes: The save, ISR and restore steps only happen when an interrupt has been received. The test should be interrupt_flag = TRUE. After the ISR the CPU must restore the saved program counter, not throw it away. Without it, the interrupted task cannot carry on where it stopped.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 409–418) and word search (Modules 390–418).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does the CPU do with its register contents before it runs the ISR?
It deletes them to make room for the ISRIt saves them so they can be restored later
Matches
run ISR -> save register contents
↓
The state is saved after the ISR has already run. The ISR may already have overwritten the registers and the program counter, so the interrupted task's data is lost.
Applying
Meanings
Term
save register contents
Meaning
Before running the ISR, the CPU stores its register contents, including the program counter, so the interrupted task can later carry on exactly where it stopped.
Practice
IF interrupt received THEN
Testing
Gaps
registers
Check Answer
Spots
1IF interrupt_flag = FALSE
2 SAVE registers

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Dolphin' badge — Reef Streak, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does the CPU do with its register contents before it runs the ISR?
A. It deletes them to make room for the ISR
B. It saves them so they can be restored later ✓
The register contents are stored so the interrupted task can carry on later. Deleting them would lose the task's work.
2. Which value must be saved so the CPU knows which instruction to carry on with after the interrupt?
A. The program counter ✓
B. The keyboard buffer
The program counter holds the address of the next instruction. If it is saved, the CPU can return to the right place.
3. Why is the state of the interrupted task saved?
A. So the task can carry on exactly where it stopped ✓
B. So the task can start again from the beginning
Saving the state means no progress is lost. The task resumes from the point it was interrupted.
4. When does the CPU save its registers during interrupt handling?
A. After the ISR has finished
B. Before the ISR starts running ✓
The ISR will use the registers and overwrite them, so the old values must be saved first.
5. What could happen if the program counter was NOT saved before the ISR ran?
A. The CPU would lose its place in the interrupted program ✓
B. The ISR would run twice
The ISR changes the program counter to point at its own code. Without a saved copy, the CPU cannot find the next instruction of the old task.

Match the Pairs

save register contents → Before the ISR runs, the CPU stores the values held in its registers so they are not overwritten
save program counter → The CPU stores the address of the next instruction so it knows where the interrupted task stopped
The saved state is put back into the registers after the ISR finishes, so the old task carries on exactly where it stopped → restore register contents
The correct order is to save the state first, then run the ISR, then restore the state → save state -> run ISR -> restore state
run ISR -> save register contents → The state is saved after the ISR has already run. The ISR may already have overwritten the registers and the program counter, so the interrupted task's data is lost.
Only the data registers are saved; the program counter is not saved → Not saving the program counter means the CPU forgets the address of the next instruction, so the interrupted task cannot carry on from where it stopped.

Key Term

save register contents
Before running the ISR, the CPU stores its register contents, including the program counter, so the interrupted task can later carry on exactly where it stopped.

Fill in the Blanks

1. STORE registers RUN ISR RESTORE registers
Hint: Type the action that puts the saved values back into the registers after the ISR has finished, so the old task can carry on.
2. STORE registers RUN ISR RESTORE registers
Hint: Type the three-letter abbreviation for the routine that deals with the interrupt.
3. STORE registers RUN ISR RESTORE registers
Hint: Type the action the CPU performs on its registers before it runs the ISR, so the task does not lose its place.
4. savedPC ← PC
Hint: Type the short name of the register that holds the address of the next instruction, which must be saved before the ISR runs.
5. IF interrupt THEN STORE registers RUN ISR
Hint: Type the name of the signal the CPU checks for, which triggers saving the state before the ISR runs.

Spot the Error

Question 1
A IF interrupt_flag = FALSE
B SAVE registers
C RUN ISR
D RESTORE registers
Line A — The save, ISR and restore steps only happen when an interrupt has been received. The test should be interrupt_flag = TRUE.
Question 2
A Interrupt arrives
B CPU saves PC to the stack
C CPU runs the ISR
D CPU discards PC from stack
Line D — After the ISR the CPU must restore the saved program counter, not throw it away. Without it, the interrupted task cannot carry on where it stopped.
Question 3
A Keyboard key pressed
B CPU skips saving registers
C ISR reads the key
D CPU restores register contents
Line B — The CPU must save its register contents before running the ISR. Otherwise the ISR overwrites them and the interrupted task loses its place.
Question 4
A Interrupt arrives
B CPU runs ISR, then saves state
C ISR finishes
D CPU restores state
Line B — The state must be saved BEFORE the ISR runs. If the ISR runs first, it changes the registers and the original values are lost.
Question 5
A Interrupt: printer error
B Save registers and PC
C Run printer ISR
D Load registers from the ISR
E Resume the interrupted task
Line D — The CPU must restore the values it saved from the interrupted task, not use values left by the ISR. Line 4 should restore the registers and PC.

Student with a class code? Join your class →