CIE IGCSE | 4.1.4 Interrupts

Lesson objective

Describe how hardware and software interrupts are generated and handled, including interrupt service routines and the effect on the current task.

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.

Hardware events can require a response while another task is running
Example from the syllabusWhat happenedWhy attention is needed
Pressing a keyboard keyAn input event has occurredThe system needs to handle the key input
Moving a mouseMovement information is availableThe 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.

Use the event and its required response in your explanation
Example from the syllabusWhat needs handling
Division by zeroAn attempted operation cannot produce an ordinary valid result
Two processes trying to access the same memory locationA 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

  1. The current task is executing.

    The processor runs its instructions in the normal way.

  2. An interrupt is generated.

    A hardware event or software condition requests attention.

  3. The request is recognised and checked.

    The system considers whether it should be handled now, including priority and whether handling is enabled.

  4. The current execution state is saved.

    Relevant register values and the return position are preserved.

  5. The appropriate ISR executes.

    The handler deals with the event.

  6. 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.

Saving state preserves the information needed for continuation
Before handlingDuring handlingAfter normal return
The task has a saved return position and register valuesThe ISR may use registers for its own instructionsThe required original values are restored
The task has reached a particular point in its computationThe handler responds to the eventThe 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.

The handler and the application have different roles
StageWhat happens in the simplified example
GenerateThe keyboard input event requests attention through the system
PreserveRelevant execution state is saved
HandleThe appropriate handler obtains or processes the input information
ReturnThe saved state is restored and the interrupted task resumes
Visible resultThe 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

Different sources; both require suitable handling
ComparisonHardware interruptSoftware interrupt / syllabus exception example
SourceHardware device or controllerAn event or condition arising during program execution
Syllabus exampleKey press or mouse movementDivision by zero or conflicting memory access
Shared ideaRequests attention and needs an appropriate handlerRequests 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.

MATCH THE INTERRUPT TERM

Terminology

Terminology

Interrupt

A signal or event requesting processor attention.

Hardware interrupt

An interrupt generated by hardware or a related controller.

Software interrupt

In the syllabus examples, an event arising during software execution that requires system attention.

Interrupt service routine (ISR)

A routine containing instructions to handle a particular interrupt.

Execution state

Information such as register values and instruction position needed to continue execution.

Saved state

Execution information preserved before a handler runs.

Restore state

Reinstate the required saved execution information.

Return address

The instruction position used to continue after a handler returns.

Program counter (PC)

The register associated with the next instruction address in the teaching model.

Interrupt priority

The ordering or importance used when considering interrupt requests.

Pending interrupt

An interrupt request awaiting handling.

Polling

Repeatedly checking whether a device or condition needs attention.

Division by zero

An invalid arithmetic operation requiring appropriate error handling.

Exception

A processor-detected execution condition, such as a fault, requiring special handling.

Handler

Code that responds to a particular event or condition.

Interrupt overhead

Processor time and other work required to recognise and handle interrupts.

Questions

Questions

CHECK YOUR UNDERSTANDING

Select all correct choices. Each exact set earns one point.

1. Which are hardware-interrupt examples in the syllabus?
2. Which are software-interrupt examples listed in the syllabus?
3. What is an ISR?
4. Why is execution state saved?
5. Which belong in normal interrupt handling?
6. Which priority statements are correct?
7. Which describe a possible benefit of interrupts?
8. Which statements about an error interrupt are correct?

EXPLAIN AND COMPARE

Write your answers before revealing each sample.

1. Define an interrupt.

2. Compare hardware and software interrupts, giving one syllabus example of each.

3. Describe the normal sequence used to handle an interrupt and resume a task.

4. Explain why register contents may need to be saved before an ISR runs.

5. Explain how interrupts can reduce unnecessary checking of an idle device.

6. Describe the role of interrupt priority.

7. Explain why a division-by-zero event may not lead to normal resumption.

APPLY IT | SPOT THE WRONG SEQUENCE

A student writes: “Run the ISR → save the original registers → restore state → continue.” Identify the problem and correct the order. Explain the risk in the original sequence.

Reveal suggested answer

The original task’s required state must be saved before the ISR changes it. Correct simplified order: save state → run the appropriate ISR → restore state → continue. Saving registers after the handler has changed them could preserve the handler’s values instead of the task’s original values.

Flashcards

Flashcards

Click to flip. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for 4.1.4 Interrupts is coming soon. Complete the matching task and written questions in your exercise book.