When you press a key, the processor is busy doing something else. An interrupt is the signal that makes it stop, deal with the event, and then carry on exactly where it left off. Learn how interrupts are generated, handled and what happens as a result.
An interrupt is a signal sent to the processor, by a device or by software, saying that something needs attention. Hardware interrupts come from devices, e.g. pressing a key or moving the mouse. Software interrupts come from programs, e.g. division by zero or two processes trying to access the same memory location. At the end of each fetch-decode-execute cycle the processor checks for interrupts. If one has a higher priority than the current task, it saves the contents of its registers, runs the matching interrupt service routine (ISR), then restores the registers and carries on.
Fig. 1: how the processor handles an interrupt
Section 01
Where interrupts come from.
In the lab, trigger different interrupts while a program runs and watch the processor respond to them in order of priority.
Type
Generated by
Examples
Hardware interrupt
a hardware device
a key is pressed on the keyboard; the mouse is moved; the printer runs out of paper
Software interrupt
a program or process
division by zero; two processes try to access the same memory location
Examiner trap
Interrupts are not only for errors. A key press is an interrupt too: it simply tells the processor there is new input to deal with.
Section 02
How an interrupt is handled.
Learn this sequence: most interrupt questions give marks for each step in the right order.
Generated: the device or software sends an interrupt signal to the processor; it is placed with any others waiting.
Checked: at the end of the current fetch-decode-execute cycle, the processor checks for interrupts.
Priority: the interrupt's priority is compared with the current task. A lower priority interrupt waits.
Save: for a higher priority interrupt, the contents of the registers (the current task's state) are saved.
ISR: the interrupt service routine for that interrupt is run, e.g. read the key code and display the character.
Restore and resume: the saved register contents are reloaded and the original task carries on from where it stopped.
Worked example A key press
A user is typing in a word processor while a large file is being saved. Describe what happens when the user presses the letter K.
The keyboard (hardware) generates an interrupt and sends the signal to the processor.
At the end of the current cycle the processor checks for interrupts and finds the keyboard interrupt has a higher priority than the save.
The processor saves the contents of its registers for the saving task.
It runs the ISR for the keyboard: the code for K is read and the letter is displayed.
The registers are restored and saving the file continues where it left off.
Answer: Interrupt sent, checked at end of cycle, priority compared, registers saved, keyboard ISR run, registers restored, save resumes.
Examiner trap
Do not say the processor stops immediately. It finishes the current fetch-decode-execute cycle first, then checks for interrupts.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
What is an interrupt?
Quick check+10 XP
In the lab, what happens to the registers before the ISR runs?
Quick check+10 XP
Which is a hardware interrupt?
Quick check+10 XP
When does the processor check for interrupts?
Section 03
What results.
The result of an interrupt depends on what generated it.
Key press or mouse move: the input is read and the screen updates, e.g. a character appears or the pointer moves.
Printer out of paper: a message is displayed asking the user to add paper; printing resumes later.
Division by zero: the program cannot continue the calculation; an error message is displayed or the program is stopped.
Two processes and one memory location: the OS stops one process from overwriting the other's data, so one must wait.
Why it matters: without interrupts the processor would have to keep checking every device, wasting time, and urgent events would be missed. Interrupts let the computer respond quickly and multitask.
Your turn
A program tries to calculate Total / Count when Count is 0. State the type of interrupt and a likely result.
A software interrupt (division by zero); the ISR handles the error, e.g. an error message is shown and the program stops or skips the calculation.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
What is the name of the code that runs to deal with an interrupt?
Exam style+20 XP
An interrupt arrives with a lower priority than the current task. What happens?
Exam style+20 XP
Which is an example of a software interrupt?
Exam style+20 XP
Why are the register contents restored after the ISR has finished?
Skill unlocked
Interrupts, handled.
This skill is now recorded on your profile. Keep the chain going.