Learn
4.1.4 | INTERRUPTS
01 | A REQUEST FOR ATTENTION
An interrupt is a signal or event that requests the processor’s attention. It tells the system that something needs to be handled while other instructions may be running.
Imagine a student editing a report while a printer finishes a job. The computer needs to respond to the printer event without losing the student’s current work.
In the usual teaching model, the current task is temporarily paused, its state is saved, a suitable routine handles the event, and the original task can resume afterwards.
Interrupt does not mean delete or restart. It means diverting attention to an event that requires handling.
02 | HARDWARE INTERRUPTS
A hardware interrupt is generated by a hardware device or related controller to request attention.
| Example from the syllabus | What happened | Why attention is needed |
|---|---|---|
| Pressing a keyboard key | An input event has occurred | The system needs to handle the key input |
| Moving a mouse | Movement information is available | The system needs to handle the new input |
A device can also signal that an operation has completed or that an error needs handling. For example, a storage controller can report that requested data is ready.
The exact route varies by hardware. Some input information passes through controllers and drivers, so do not assume every individual movement produces exactly one direct CPU interrupt.
03 | SOFTWARE INTERRUPTS AND EXCEPTIONAL EVENTS
A software interrupt, in the syllabus’s examples, arises while software is executing and needs system attention.
| Example from the syllabus | What needs handling |
|---|---|
| Division by zero | An attempted operation cannot produce an ordinary valid result |
| Two processes trying to access the same memory location | A conflicting or invalid access needs appropriate handling |
These are not hardware-input events. They arise from program execution or access conditions.
Technical context: real systems often call events such as division by zero exceptions or traps. For this syllabus, recognise them as the listed software-interrupt examples.
Two processes can legitimately share memory when properly managed. The concern here is conflicting or invalid access, rather than a claim that every shared-memory access is an error.
04 | THE INTERRUPT SERVICE ROUTINE
An interrupt service routine (ISR) is a routine that handles a particular interrupt. It contains the instructions needed to respond to that event.
The processor does not invent those instructions when an event occurs. The system selects the appropriate handler, with the OS and device drivers involved as required.
Keyboard example: the relevant handler can obtain the available input information and arrange for it to be processed by the system. A printer-related handler would perform different work.
An ISR handles the event; it is not simply a saved copy of the interrupted program.
05 | SAVE, HANDLE, RESTORE
- The current task is executing.
The processor runs its instructions in the normal way.
- An interrupt is generated.
A hardware event or software condition requests attention.
- The request is recognised and checked.
The system considers whether it should be handled now, including priority and whether handling is enabled.
- The current execution state is saved.
Relevant register values and the return position are preserved.
- The appropriate ISR executes.
The handler deals with the event.
- State is restored and execution can resume.
For a normally returning interrupt, the task continues from its saved position.
This is a simplified model. Real processors have defined points at which they recognise interrupts, and some faults lead to an error response or program termination instead of normal resumption.
06 | WHAT DOES SAVING STATE MEAN?
The processor’s current state includes information needed to continue correctly, such as the instruction return position and relevant register contents.
For example, an accumulator may contain a partial calculation result. If the handler changes registers, that task must not simply continue with the handler’s values.
| Before handling | During handling | After normal return |
|---|---|---|
| The task has a saved return position and register values | The ISR may use registers for its own instructions | The required original values are restored |
| The task has reached a particular point in its computation | The handler responds to the event | The task continues from its saved position |
The program counter (PC) is associated with the instruction position. Saving an appropriate return address helps the system know where to continue.
Saving execution state is not the same as saving the user’s document to disk. It also does not normally mean copying the whole application into a new file.
07 | WORKED EXAMPLE: A KEY PRESS
A word processor is running when a student presses a key.
| Stage | What happens in the simplified example |
|---|---|
| Generate | The keyboard input event requests attention through the system |
| Preserve | Relevant execution state is saved |
| Handle | The appropriate handler obtains or processes the input information |
| Return | The saved state is restored and the interrupted task resumes |
| Visible result | The system delivers input to the appropriate application, which can display the character |
Important: obtaining input in the handler is not the same as deciding how the application should display it. A game and a word processor can interpret the same key differently.
08 | PRIORITY AND WAITING
More than one request can occur. Interrupt priority helps determine which pending request should be handled first.
A request may wait if it cannot currently be serviced. Some systems permit a higher-priority interrupt to interrupt a lower-priority handler; this depends on the system’s rules.
Do not memorise one universal ranking. Priorities are system-dependent. The useful principle is that requests are managed rather than every event immediately interrupting everything else.
Once a handler finishes, another pending interrupt may be serviced before the original task runs again.
09 | WHY USE INTERRUPTS?
Without an interrupt-based response, a program might repeatedly check whether a device needs attention. This repeated checking is called polling.
With interrupts, the processor can perform other work until an event requests attention. This can avoid unnecessary repeated checks and support a timely response.
Interrupt handling still takes processor time. A very large number of events can create overhead, so interrupts do not make every situation automatically faster.
For this course, focus on explaining the benefit through the situation: the processor can continue useful work rather than continually checking an idle device.
10 | WILL THE ORIGINAL TASK ALWAYS RESUME?
For a routine device event, a handler normally returns and the saved task can continue.
For an error such as division by zero, the appropriate response may report an error, invoke program error-handling code or stop the affected process. Continuing as though the invalid calculation succeeded would be incorrect.
Exam wording matters: when asked to describe normal interrupt handling, explain saving state, executing the ISR and restoring state. When an error scenario is given, explain the consequence appropriate to that error.
11 | HARDWARE VERSUS SOFTWARE
| Comparison | Hardware interrupt | Software interrupt / syllabus exception example |
|---|---|---|
| Source | Hardware device or controller | An event or condition arising during program execution |
| Syllabus example | Key press or mouse movement | Division by zero or conflicting memory access |
| Shared idea | Requests attention and needs an appropriate handler | Requests attention and needs an appropriate handler |
Developed explanation: the current task’s state is saved because the ISR may change registers. Restoring the original values afterwards allows the task to continue correctly, rather than using values left by the handler.
12 | COMMON MISTAKES
- The interrupt is the ISR: the interrupt requests attention; the ISR handles it.
- Every interrupt restarts the program: normal handling can preserve and restore state.
- Saving state means saving the document: it preserves execution information.
- The keyboard is a software interrupt: its input is a hardware example.
- Division by zero always resumes normally: an error may stop the affected process.
- Every interrupt is handled instantly: recognition, priority and system rules affect timing.
- Every shared-memory access is invalid: managed sharing is possible.