Cambridge O Level Computer Science · Syllabus 2210 · Software
Interrupt
What is Interrupt?
An interrupt is a signal generated by hardware or software that tells the CPU an event has occurred which requires its attention, causing the CPU to pause the current program, run an interrupt service routine and then resume the interrupted program.
This definition is part of the Software chapter in Cambridge O Level Computer Science.
Interrupt in context
A computer is built in layers, and each layer only works because the layer beneath it is already running. Hardware executes machine instructions and nothing else. Firmware, held in non-volatile memory, starts the hardware and its bootloader loads the operating system. The operating system then manages files, memory, peripherals, users and security, and provides the platform on which application software runs. While all of that is happening, interrupts let an urgent event — a key press, a division by zero — reach the CPU without it having to keep asking. And because a CPU can only execute machine code, every program a person writes must first be put through a translator: an assembler, a compiler or an interpreter.
An operating system is system software that manages the computer's hardware and resources and provides a platform on which application software can run. It is not one job but nine, carried out at the same time and constantly interacting: managing files, handling interrupts, providing an interface, managing peripherals and drivers, managing memory, managing multitasking, providing a platform for running applications, providing system security, and managing user accounts. Every one of those functions exists because a shared machine with limited resources needs someone to be in charge of them.
An interrupt is a signal, generated by hardware or by software, that tells the CPU an event has occurred which needs its attention. Without interrupts a processor would have to keep asking every device and testing every condition — "has a key been pressed? has the transfer finished? has anything gone wrong?" — over and over, wasting time on the overwhelming majority of checks that have nothing to report. An interrupt reverses that: the event announces itself, and the CPU only does work when there is work to do.
The two kinds of interrupt are separated by what raised the signal. A hardware interrupt is raised by a physical device: the syllabus names pressing a key on the keyboard and moving the mouse. A software interrupt is raised by a program that is running: the syllabus names division by zero and two processes trying to access the same memory location. Once raised, both kinds are handled the same way — the difference is only in the origin.
Interrupt handling is a save, service, restore sandwich. The processor's state is saved so that nothing is lost; the interrupt service routine for that particular cause is located and executed, which services the event; then the saved state is restored and the interrupted program continues from exactly the point at which it stopped. Get those three words in that order and the sequence writes itself.
Common mistakes with Interrupt
- 3. Saying an interrupt "stops" or "closes" the program. Why it fails The whole point of saving the state is that the interrupted program is resumed. If interrupts ended programs, moving the mouse would close your work. Fix Always finish the sequence with "the state is restored and the program continues from the point at which it was interrupted." See the interrupt laboratory.
- 4. Swapping the two interrupt types. Why it fails The syllabus names the examples explicitly. A key press and a mouse movement are hardware interrupts because a physical device raised them. Division by zero, and two processes trying to access the same memory location, are software interrupts because a running program caused them. Fix Ask "did a physical device raise this, or did a running program?" See section 4.1 G.
- "A key press is a software interrupt, because software reacts to it." Why it fails The classification is about what raised the signal, not what deals with it. Software deals with every interrupt; that cannot be the distinguishing feature. Corrected model A key press is raised by the keyboard, a physical device, so it is a hardware interrupt. Exam-safe sentence "Pressing a key on the keyboard is a hardware interrupt, because the signal is raised by a physical device."
- "Division by zero is a hardware interrupt, because the processor's arithmetic unit detects it." Why it fails The detection happens in hardware, but the cause is an instruction in a running program. No device asked for attention; a program did something it could not complete. Corrected model Division by zero is a software interrupt, and so is two processes trying to access the same memory location. Exam-safe sentence "Division by zero is a software interrupt, because the condition arises inside a program that is executing."
- M8. "An interrupt always closes the current program." Why it fails If it were true, moving the mouse would close your work. It also makes the whole save-and-restore mechanism pointless — why save a state you will never return to? Corrected model The current instruction completes, the state and return location are saved, the ISR runs, the state is restored, and the interrupted program resumes from where it stopped. A process only ends if the operating system decides that an unrecoverable fault requires it. Exam-safe sentence "After the interrupt service routine has finished, the saved state is restored and the interrupted program continues from the point at which it was interrupted." Show the retrieval checkHide the check Check: Why is the state saved at step 3 of interrupt handling?Answer: So that it can be restored at step 8 and the interrupted program resumed at step 9 exactly where it stopped.
- M9. "A keyboard press is a software interrupt." Why it fails It classifies by what deals with the interrupt rather than what raised it. Software deals with every interrupt, so that cannot be the distinguishing feature. Corrected model A key press is raised by the keyboard, a physical device, so it is a hardware interrupt — one of the two examples the syllabus names, along with moving the mouse. Exam-safe sentence "Pressing a key on the keyboard is a hardware interrupt, because the signal is generated by a physical device." Show the retrieval checkHide the check Check: What is the single question that classifies any interrupt?Answer: Did a physical device raise the signal, or did a running program?
- M10. "Division by zero is a hardware interrupt." Why it fails The condition is detected by the processor, which tempts candidates to call it hardware — but nothing external asked for attention. A program executed an instruction it could not complete. Corrected model Division by zero is a software interrupt, as is two processes trying to access the same memory location. Both are conditions arising inside executing software. Exam-safe sentence "Division by zero is a software interrupt, because the condition arises inside a program that is executing." Show the retrieval checkHide the check Check: Name the two software-interrupt examples the syllabus gives.Answer: Division by zero, and two processes trying to access the same memory location.
- M11. "An ISR is an ordinary user application." Why it fails An application provides a service the user requires and is started when the user asks for it. An ISR is never started by a user, provides no user service, and exists solely to service one particular interrupt. Corrected model An interrupt service routine is a specialised routine executed to service a particular interrupt. Each cause has its own. When it finishes, control returns to the interrupted process. Exam-safe sentence "An interrupt service routine is a specialised routine that is executed to service a particular interrupt, after which control returns to the interrupted process." Show the retrieval checkHide the check Check: Is there one ISR for the whole computer, or more than one? Why does it matter?Answer: More than one — each cause has its own. That is why the interrupt must be identified before the correct routine can be located.
Questions students ask about Interrupt
What is the difference between a hardware interrupt and a software interrupt?
A hardware interrupt is raised by a physical device, such as pressing a key on the keyboard or moving the mouse. A software interrupt is raised by a program that is running, such as a division by zero or two processes trying to access the same memory location. Both are handled the same way once raised: the current instruction finishes, the processor's state is saved, an interrupt service routine runs, and then the state is restored so the interrupted program continues from where it stopped.
Does an interrupt close the program that was running?
No. An interrupt pauses a program rather than ending it. The current instruction completes, the processor's state is saved, an interrupt service routine executes to service the event, and then the saved state is restored so the interrupted program resumes from exactly the point at which it was interrupted. A process ends only if the operating system decides that an unrecoverable fault requires it, not simply because an interrupt occurred.

