← IGCSE Computer Science Paper 1

Interrupt handling step by step

The ordered steps: an interrupt is generated, the CPU finishes its cycle and detects it, saves its state, runs the ISR, restores its state, then resumes the original task.

Understanding Interrupt handling step by step in IGCSE Computer Science Paper 1

What it does: The ordered sequence is the same for any interrupt, including a key press: generate, detect, save, run the ISR, restore, resume. The CPU checks for interrupts at the end of each cycle, so the current instruction is completed first. The state (registers and program counter) must be saved BEFORE the ISR runs, or the original task's progress would be lost when the ISR overwrites the registers. Order: key pressed (generated), CPU finishes cycle and detects, saves state, runs the keyboard ISR, restores state, resumes. Resuming comes last.

Common mistakes: The CPU must finish the current fetch-decode-execute cycle before it detects the interrupt. It does not abandon the cycle. The line should be 'CPU finishes the current cycle'. After the keyboard sends the interrupt, the CPU first finishes its cycle and detects the interrupt. Restoring the state happens after the ISR has run. The line should be 'CPU finishes cycle, detects it'.

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
Which step happens FIRST when an interrupt occurs?
The CPU runs the interrupt service routine (ISR)The interrupt is generated by a device or by software
Matches
detect -> run ISR -> save state -> restore -> resume
↓
The CPU must save its state BEFORE running the ISR. If it runs the ISR first, the register values and program counter of the interrupted task are overwritten and lost.
Applying
Meanings
Term
interrupt handling sequence
Meaning
The ordered steps: an interrupt is generated, the CPU finishes its cycle and detects it, saves its state, runs the ISR, restores its state, then resumes the original task.
Practice
interrupt ← GENERATED
Testing
Gaps
STEP 2: CPU finishes cycle and it
Check Answer
Spots
1INTERRUPT generated
2CPU abandons the current cycle

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

The 'Kangaroo Rat' badge — Speed Typer, 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. Which step happens FIRST when an interrupt occurs?
A. The interrupt is generated by a device or by software ✓
B. The CPU runs the interrupt service routine (ISR)
The sequence starts when the interrupt is generated. Only later does the CPU detect it, save its state and run the ISR.
2. When the CPU detects an interrupt, what has it just done?
A. Stopped halfway through an instruction
B. Finished its current fetch-decode-execute cycle ✓
The CPU checks for interrupts at the end of each cycle, so the current instruction is completed first.
3. Which is the correct order for the middle steps?
A. Save the CPU's state, then run the ISR ✓
B. Run the ISR, then save the CPU's state
The state (registers and program counter) must be saved BEFORE the ISR runs, or the original task's progress would be lost when the ISR overwrites the registers.
4. Why does the CPU save its state before running the ISR?
A. So it can return to the original task exactly where it left off ✓
B. So the ISR can run faster
Saving the register contents and the program counter lets the CPU restore them afterwards and resume the interrupted task.
5. In the key press example, what happens right after the CPU saves its state?
A. It resumes the program it was running before
B. It runs the keyboard ISR to read the key that was pressed ✓
Order: key pressed (generated), CPU finishes cycle and detects, saves state, runs the keyboard ISR, restores state, resumes. Resuming comes last.

Match the Pairs

PUSH registers; PC -> stack → Step 3: the CPU saves its state (register values and the program counter) so the interrupted task can be resumed later.
POP registers; resume task → Steps 5 and 6: the CPU restores its saved state and carries on with the original task where it left off.
Key press worked example: the keyboard sends a signal, the CPU finishes its cycle, saves its state, runs the keyboard ISR, restores its state and resumes. → generate -> detect -> save -> run ISR -> restore -> resume
Division by zero worked example: the software generates an interrupt, the CPU detects it after its cycle, saves its state and runs an ISR that shows an error message. → x = 10 / 0 -> interrupt -> ISR: error message
detect -> run ISR -> save state -> restore -> resume → The CPU must save its state BEFORE running the ISR. If it runs the ISR first, the register values and program counter of the interrupted task are overwritten and lost.
generate -> CPU stops instantly -> save -> ISR → The CPU does not stop instantly. It finishes the current fetch-decode-execute cycle first and then detects the interrupt, and the sequence must also end with restore and resume.

Key Term

interrupt handling sequence
The ordered steps: an interrupt is generated, the CPU finishes its cycle and detects it, saves its state, runs the ISR, restores its state, then resumes the original task.

Fill in the Blanks

1. STEP 1: key press generates an interrupt STEP 2: CPU finishes cycle and detects it
Hint: Type the verb for what the CPU does to notice the interrupt after finishing its cycle.
2. STEP 3: CPU saves its state (registers, PC)
Hint: Type the verb for storing the CPU's state so the original task can continue later.
3. STEP 3: CPU saves its state STEP 4: CPU runs the ISR
Hint: Type the abbreviation for the routine that deals with the interrupt.
4. STEP 5: CPU restores the saved state STEP 6: CPU resumes the original task
Hint: Type the verb for putting the saved registers and PC back before resuming.
5. result = 10 / 0 A software interrupt is generated
Hint: Type the kind of interrupt that a program error such as dividing by zero causes.

Spot the Error

Question 1
A INTERRUPT generated
B CPU abandons the current cycle
C CPU detects the interrupt
D CPU saves its state
E ISR runs
Line B — The CPU must finish the current fetch-decode-execute cycle before it detects the interrupt. It does not abandon the cycle. The line should be 'CPU finishes the current cycle'.
Question 2
A Key is pressed
B Keyboard sends an interrupt
C CPU restores its state
D CPU saves its state
E ISR reads the key code
Line C — After the keyboard sends the interrupt, the CPU first finishes its cycle and detects the interrupt. Restoring the state happens after the ISR has run. The line should be 'CPU finishes cycle, detects it'.
Question 3
A Program runs x = 10 / 0
B Software interrupt generated
C CPU ignores the interrupt
D CPU saves its state
E ISR shows an error message
Line C — The CPU checks for interrupts and detects them, so it does not ignore them. Detecting the interrupt must come before saving the state. The line should be 'CPU detects the interrupt'.
Question 4
A Interrupt generated
B CPU detects it after cycle
C CPU saves registers and PC
D ISR is skipped
E CPU restores saved state
F Original task resumes
Line D — After the CPU saves its state it must run the interrupt service routine (ISR), which deals with the interrupt. Skipping it means the interrupt is never handled. The line should be 'ISR runs'.
Question 5
A ISR starts without any signal
B CPU finishes and detects it
C CPU saves its state
D ISR runs
E CPU restores its state
F Original task resumes
Line A — The first step is that an interrupt is generated, because the ISR only runs after an interrupt has been generated and detected. The line should be 'Interrupt is generated'.

Student with a class code? Join your class →