Computer ScienceExam code: 0984

Types of Software

Software

An interrupt is a signal delivered to the CPU telling it to pause the current task and deal with something more urgent.

The CPU spends almost all its time in the fetch-decode-execute cycle, working through whatever program is currently running. An interrupt breaks the loop so a more urgent task can be handled at once.

How interrupts are generated

Interrupts come from two sources:

  • Hardware interrupts are raised by physical components when they need attention.
    • The keyboard has been pressed.
    • The mouse has been moved or clicked.
    • The printer has run out of paper.
    • A USB device has been plugged in.
    • The power button has been pressed.
  • Software interrupts are raised by running programs or by the OS itself.
    • A program tries to divide by zero (an error).
    • A program asks the OS to perform a service (e.g. open a file).
    • Two programs collide on the same memory address.
    • A program has stopped responding.

Common exam question

Stating what an interrupt is and giving examples

Question: State the purpose of an interrupt, name the signal that lets multitasking happen, or give examples of hardware and software interrupts (1–2 marks).

Asked in 3 of the 17 papers. An interrupt is a signal that tells the processor something needs its attention; interrupt is also the one-word answer when a question asks which signal is sent so that multitasking can occur. Hardware interrupts come from devices: a key pressed, the mouse moved or a button clicked, a device plugged in, a printer jammed or out of paper. Software interrupts come from running programs: division by zero, two processes trying to use the same memory location, a null value. Asked for an input device and an interrupt it can generate, make the pair match: keyboard with a key pressed, mouse with a movement or a click.

How the CPU handles an interrupt

The standard step-by-step sequence for handling an interrupt:

  1. The current fetch-decode-execute cycle finishes so the CPU is at a clean stopping point.
  2. The CPU saves the contents of its registers (PC, ACC and others) to a special area in RAM called the stack, so the original task can be resumed later.
  3. The CPU looks up the in the Interrupt Service Routine (ISR) table. The ISR is a small program that knows how to handle this particular kind of interrupt.
  4. The CPU runs the ISR; for example, it reads the keystroke from the keyboard buffer and passes it to the active program.
  5. When the ISR finishes, the CPU restores the saved register values from the stack.
  6. The CPU resumes the original task exactly where it left off.

Common exam question

Explaining how the processor handles an interrupt

Question: Describe how interrupts are used when a key is pressed, or explain how the processor manages the program it is running and an interrupt it receives (5 marks).

Set in 2 of the 17 papers, five marks from a list of steps, so give the whole sequence. The interrupt is generated, given a priority, sent to the CPU and placed in the interrupt queue. The processor finishes the current fetch-decode-execute cycle and checks the queue. If the interrupt's priority is lower than the running process's, the processor simply continues with that process. If it is higher, the processor saves the current process's registers on the stack, identifies the source of the interrupt and calls the matching interrupt service routine (ISR), which handles it. If another higher-priority interrupt is waiting the steps repeat; otherwise the processor retrieves the registers from the stack and continues the original program. The queue, the priority check and the lower-priority case are separate credited points.

Interrupt priorities

Not every interrupt is equally urgent. The OS assigns priorities:

  • A power-failure interrupt is critical and must be handled immediately.
  • A keyboard interrupt is high-priority (the user expects an instant response).
  • A printer "out of paper" interrupt is less urgent than a CPU temperature warning.

If a higher-priority interrupt arrives while a lower-priority one is being handled, the CPU can save its state again and switch to the more urgent one (nested interrupts).

Why interrupts matter

Interrupts let the CPU respond instantly to outside events without having to constantly poll every device. They are what make multitasking feel responsive: every keystroke, mouse movement, network packet and disk-completion message reaches the CPU through an interrupt.

Quick check

4 short questions on this note. See what has stuck, and where to look if something hasn't.

About 2 minutes

Build on this topic