Skip to main content
SingaporeComputer ScienceSyllabus dot point

How does a CPU respond to events from devices without constantly checking them, and what is an interrupt?

Explain interrupts and interrupt handling, contrast them with polling, and describe how the CPU services and resumes after an interrupt

A focused answer to the H2 Computing outcome on interrupts. What an interrupt is, the interrupt service routine, saving and restoring state, interrupt priorities, and the contrast with polling for input and output.

Generated by Claude Opus 4.88 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

SEAB wants you to explain interrupts and how they are handled, contrast them with polling, and describe how the CPU services an interrupt and resumes afterward. The central idea is that an interrupt lets a device get the CPU's attention only when needed, so the processor does useful work instead of endlessly checking - and it can return precisely to what it was doing because it saves its state.

The answer

What an interrupt is

An interrupt is a signal to the CPU that an event needs attention - a key pressed, a packet arrived, a disk transfer finished, a timer elapsed, or a hardware error. The interrupt causes the CPU to temporarily suspend its current program and deal with the event, then continue.

Polling versus interrupts

There are two ways for the CPU to learn a device needs service:

  • Polling - the CPU repeatedly checks each device in a loop, asking "do you need attention?" even when nothing has happened. The CPU drives the checking and wastes time on idle devices.
  • Interrupt-driven - the device signals the CPU only when it actually needs service. The CPU does other work meanwhile and responds only when interrupted.

Interrupts are far more efficient, especially for rare or unpredictable events, because the CPU is not tied up busy-checking.

Servicing an interrupt

When an interrupt occurs, the CPU follows a set sequence:

  1. Finish the current instruction (the cycle completes the instruction in progress).
  2. Save its state - the program counter and registers, typically pushed onto a stack.
  3. Identify the interrupt and jump to the matching interrupt service routine (ISR) - the code that handles that event.
  4. Run the ISR to deal with the event.
  5. Restore the saved state and resume the interrupted program exactly where it left off.

Why state must be saved

Saving the program counter and registers means that, after the ISR runs (and overwrites registers), the CPU can resume the original program correctly, as if nothing had happened. Without saving, the ISR would corrupt the program's context and it could not continue.

Interrupt priorities

Interrupts are assigned priorities so that when several occur, or one occurs during another's handling, the most urgent is serviced first. A higher-priority interrupt (a hardware fault, a timer) can pre-empt the handling of a lower-priority one, ensuring critical events are not delayed.

Examples in context

Example 1. Why your computer stays responsive. While you run a heavy program, moving the mouse or pressing a key still works instantly because each input device raises an interrupt. The CPU briefly services it and returns to the heavy task, rather than ignoring you until it next happened to poll - which is what makes the system feel responsive.

Example 2. A timer interrupt for multitasking. An operating system uses a periodic timer interrupt to take control back from a running program at fixed intervals, letting it switch between tasks (a context switch). Saving and restoring state is exactly the mechanism that lets many programs appear to run at once on one CPU.

Try this

Q1. Define an interrupt. [1 mark]

  • Cue. A signal to the CPU that an event needs attention, causing it to temporarily suspend its current program to handle it.

Q2. Give one advantage of interrupt-driven input-output over polling. [1 mark]

  • Cue. The CPU does not waste time repeatedly checking idle devices, so it can do useful work and respond promptly - more efficient.

Q3. Why must the CPU save its state before running an interrupt service routine? [2 marks]

  • Cue. So it can resume the interrupted program exactly where it stopped, with the program counter and register values intact after the ISR overwrites them.

Exam-style practice questions

Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

Original6 marks(a) Define an interrupt. (b) Describe, in order, the steps the CPU takes when an interrupt occurs and is serviced. (c) Why must the CPU save its current state before running the interrupt service routine?
Show worked answer →

(a) An interrupt is a signal to the CPU that an event needs attention (for example, a key pressed, data arrived, or a hardware error), causing the CPU to temporarily suspend its current program to deal with it.

(b) The steps when an interrupt is serviced:

  1. The CPU finishes the current instruction.
  2. It saves its state (the program counter and registers), typically onto a stack.
  3. It identifies the interrupt and jumps to the matching interrupt service routine (ISR).
  4. The ISR runs, handling the event.
  5. The CPU restores the saved state and resumes the interrupted program exactly where it left off.

(c) The CPU saves its state so that, after the ISR finishes, it can resume the interrupted program exactly where it stopped, with all register values intact. Without saving, the ISR would overwrite registers and the program counter, and the original program could not continue correctly.

Markers reward the interrupt definition, the ordered finish-save-service-restore-resume steps, and saving state so the original program resumes correctly.

Original5 marks(a) Contrast interrupt-driven input-output with polling. (b) Give one advantage of interrupts over polling. (c) Why are interrupts assigned priorities?
Show worked answer →

(a) With polling, the CPU repeatedly checks each device in a loop to see if it needs attention, even when nothing has happened - the CPU drives the checking. With interrupt-driven input-output, the device signals the CPU only when it actually needs attention, so the CPU does other work in the meantime and responds only when interrupted.

(b) An advantage of interrupts: the CPU does not waste time busy-checking idle devices, so it can do useful work and respond promptly when an event finally occurs - it is far more efficient, especially for rare or unpredictable events.

(c) Interrupts have priorities so that, when several occur (or one occurs during another's handling), the CPU services the most urgent first. A higher-priority interrupt (such as a hardware failure or a timer) can interrupt the handling of a lower-priority one, ensuring critical events are not delayed by trivial ones.

Markers reward the CPU-checks (polling) versus device-signals (interrupt) contrast, efficiency as the advantage, and priorities ordering urgent events first (and pre-empting lower-priority handling).

Related dot points