Skip to content
IGCSE·Tuition
Computer Science · Lessons

Explain an interrupt using a scenario

You can define an interrupt in one line, but a scenario question asks you to describe what actually happens, in order.

On this page
  1. What happens, step by step?
  2. Worked example: a key press during a calculation
  3. The mistake to watch for
  4. Check yourself
  5. Where this leads next

An interrupt is a signal to the processor that something needs attention. The processor pauses its current program, runs a short routine to deal with the event, then resumes exactly where it left off. Questions give you a scenario such as a key press, a printer fault or a power failure, and ask you to explain what happens.

This lesson follows comparing translators and uses the processor ideas from hardware and processing.

What happens, step by step?

  1. A source sends a signal: hardware (keyboard, printer, timer) or software (a program that needs a service).
  2. The processor checks for interrupts after finishing the current instruction in each fetch-decode-execute cycle.
  3. If an interrupt is waiting and its priority is high enough, the processor saves its state: the program counter and the register contents.
  4. It runs the interrupt service routine (ISR) that matches the signal.
  5. It restores the saved state and continues the original program from the next instruction.

If two interrupts arrive together, the one with the higher priority is serviced first. A power failure signal outranks a key press.

The cycle with an interrupt check can be written in pseudocode:

REPEAT
   FETCH instruction at program counter
   EXECUTE instruction
   IF interrupt signal received AND its priority is high enough THEN
      SAVE program counter and registers
      RUN interrupt service routine
      RESTORE program counter and registers
   ENDIF
UNTIL program ends

Worked example: a key press during a calculation

A program has four instructions:

I1: A ← 2
I2: B ← A * 3
I3: C ← B + 1
I4: D ← C * 2

The user presses a key while I2 is executing. Trace the processor.

StepActionABCD
1Execute I12
2Execute I2: B = 2 × 326
3Interrupt check: key press waiting, so save state (next instruction is I3, A = 2, B = 6)26
4Run ISR: store the key in the keyboard buffer26
5Restore state, resume at I326
6Execute I3: C = 6 + 1267
7Execute I4: D = 7 × 226714

The final answer is D = 14, which is the same as with no interrupt.

This is the point of the save and restore steps: the interrupted program is not harmed. Check: 2 × 3 = 6, 6 + 1 = 7, 7 × 2 = 14. You can step through a similar loop in the restricted pseudocode trace trainer.

The mistake to watch for

Mistaken answer: “The processor stops running the program until the user stops pressing keys.”

This treats the interrupt as a permanent stop, and it leaves out the saved state. Another version says the processor keeps asking the keyboard whether a key has been pressed. That is polling, and the point of an interrupt is that the device signals the processor instead.

A full answer names the signal, says the current instruction finishes, says the state is saved, names the routine and says the program resumes.

Check yourself

1. A printer runs out of paper while a document is printing. Explain how an interrupt is used.

Show answer

The printer sends an interrupt signal to the processor. The processor finishes its current instruction and saves its state. It runs a routine that tells the user the printer needs paper. Then it restores its state and continues the other program.

2. A key press and a power-failure warning arrive at the same time. Which is handled first, and why?

Show answer

The power-failure warning, because it has a higher priority. The processor may need to save work before power is lost. The key press can wait.

3. Give one thing the processor must save before running an interrupt service routine, and say why.

Show answer

The program counter (or the register contents). Without it, the processor would not know which instruction to run next, or what values the interrupted program was using, when it comes back.

Where this leads next

Now move from reacting to events to the maintenance tools on a computer, in identify a utility function. Later, the software and systems practice set mixes interrupts with the other lessons.

Writing a clean sequence of steps is a skill our teachers can coach directly in online one-to-one Computer Science tuition.

Questions people ask

What is an interrupt?

An interrupt is a signal sent to the processor to say that something needs attention now. It can come from hardware, such as a key press or a printer error, or from software, such as a program asking for a service. The processor pauses its current task briefly, deals with the signal and then carries on.

Does the processor stop immediately when an interrupt arrives?

It normally finishes the instruction it is executing first, then checks for interrupts. At that point it saves the current state, so it knows exactly where to resume. Describing this save step is what many exam mark schemes look for.

What is an interrupt service routine?

It is the small program that deals with one kind of interrupt, for example reading a key press into a buffer. The processor runs it after saving its state. When the routine finishes, the saved state is restored and the interrupted program continues.

Updated:

Your next step

If scenario answers keep jumping between steps, a one-to-one teacher can have you narrate the sequence aloud and fix the order before it reaches paper.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service