Cambridge IGCSE · Topic 4.1
IGCSE Computer Science 0478 / Topic 4 / IGCSE

Stop, this first.

When you press a key, the processor is busy doing something else. An interrupt is the signal that makes it stop, deal with the event, and then carry on exactly where it left off. Learn how interrupts are generated, handled and what happens as a result.

The key idea

An interrupt is a signal sent to the processor, by a device or by software, saying that something needs attention. Hardware interrupts come from devices, e.g. pressing a key or moving the mouse. Software interrupts come from programs, e.g. division by zero or two processes trying to access the same memory location. At the end of each fetch-decode-execute cycle the processor checks for interrupts. If one has a higher priority than the current task, it saves the contents of its registers, runs the matching interrupt service routine (ISR), then restores the registers and carries on.

Handling an interrupt 1. Device or softwaresends an interrupt 2. Signal waits untilend of current cycle 3. Higher priority?Save registers 4. Run the interruptservice routine (ISR) 5. Restore thesaved registers 6. Carry on with theinterrupted task Lower priority? The interrupt is queued and handled later.
Fig. 1: how the processor handles an interrupt
Section 01

Where interrupts come from.

In the lab, trigger different interrupts while a program runs and watch the processor respond to them in order of priority.

TypeGenerated byExamples
Hardware interrupta hardware devicea key is pressed on the keyboard; the mouse is moved; the printer runs out of paper
Software interrupta program or processdivision by zero; two processes try to access the same memory location
Examiner trap

Interrupts are not only for errors. A key press is an interrupt too: it simply tells the processor there is new input to deal with.

Section 02

How an interrupt is handled.

Learn this sequence: most interrupt questions give marks for each step in the right order.

Worked example A key press
A user is typing in a word processor while a large file is being saved. Describe what happens when the user presses the letter K.
  1. The keyboard (hardware) generates an interrupt and sends the signal to the processor.
  2. At the end of the current cycle the processor checks for interrupts and finds the keyboard interrupt has a higher priority than the save.
  3. The processor saves the contents of its registers for the saving task.
  4. It runs the ISR for the keyboard: the code for K is read and the letter is displayed.
  5. The registers are restored and saving the file continues where it left off.
Answer: Interrupt sent, checked at end of cycle, priority compared, registers saved, keyboard ISR run, registers restored, save resumes.
Examiner trap

Do not say the processor stops immediately. It finishes the current fetch-decode-execute cycle first, then checks for interrupts.

Stage 1 · Learn

Check what the sim just showed you

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

What is an interrupt?

Quick check+10 XP

In the lab, what happens to the registers before the ISR runs?

Quick check+10 XP

Which is a hardware interrupt?

Quick check+10 XP

When does the processor check for interrupts?

Section 03

What results.

The result of an interrupt depends on what generated it.

Your turn
A program tries to calculate Total / Count when Count is 0. State the type of interrupt and a likely result.
Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

What is the name of the code that runs to deal with an interrupt?

Exam style+20 XP

An interrupt arrives with a lower priority than the current task. What happens?

Exam style+20 XP

Which is an example of a software interrupt?

Exam style+20 XP

Why are the register contents restored after the ISR has finished?

Skill unlocked

Interrupts, handled.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Hardware and software interrupts, priorities, saving registers, the interrupt service routine and what happens as a result.