A-Level Computer Science / Unit 4: CPU Operation and Low-Level Processing

4.1.4 Interrupts

πŸ”’ Lesson slides are available to signed-in users. Sign in

Interrupts

An interrupt is a signal that asks the processor to deal with an event that needs attention. Interrupts let a processor respond to events without repeatedly checking every device while a program runs. The processor finishes its current instruction before it decides whether to service a request.

By the end of this page, you should be able to:

  • identify hardware and software causes of interrupts;
  • explain when the processor checks for an interrupt;
  • compare an interrupt's priority with the priority of the current process;
  • describe how the processor saves state, runs an ISR, restores state and resumes the process.

1. Why interrupts occur

A device or a program can raise an interrupt to request processor time. The request tells the processor that an event needs attention. The processor can then run a short routine designed to handle that event.

SourceHow the request beginsGeneral example
Hardware interrupt A hardware device sends a signal to the processor. A key is pressed, or a device reports that it has finished an operation.
Software interrupt A running program causes an interrupt request. A program requests an operating-system service.
Interrupt Service Routine (ISR): a routine that deals with a particular interrupt. An interrupt handler is the code that responds to the interrupt request.

Interrupts are useful when the processor cannot know exactly when an event will happen. A device can request attention when it is ready, instead of making the processor spend time checking the device again and again.

2. The processor checks at a safe point

The processor does not abandon an instruction as soon as a signal arrives. It completes the current instruction and checks for pending interrupts at a boundary between fetch-execute cycles. This keeps the current instruction from being left half-finished.

If a request is waiting, the processor compares its priority with the priority of the current process. A request is serviced at that point only when the interrupt has higher priority than the current process. If its priority is not higher, it stays pending while the current process continues. The processor can check again at a later boundary.

Priority comparisonProcessor action
Interrupt has higher priority than the current process Accept the request and begin interrupt handling.
Interrupt does not have higher priority than the current process Keep the request pending and continue the current process.

Do not say that the processor stops immediately

An interrupt request does not stop the processor in the middle of an instruction. The processor finishes the current instruction, then checks and makes the priority decision.

3. Save the current state and run the ISR

When the processor accepts an interrupt, it must preserve enough information to return to the task it was doing. This information is the processor's state, such as the contents of registers.

  1. Save state: copy the required register contents to the stack.
  2. Find the handler: load the address of the appropriate ISR into the PC.
  3. Run the ISR: the processor executes the routine for the interrupt.
  4. Check pending requests: after the ISR, check whether another interrupt has higher priority than the current process.
  5. Restore and resume: when no higher-priority interrupt needs service, restore the saved state from the stack and continue the previous process.

Saving the state matters because the ISR may use or change registers. Restoring the saved contents lets the interrupted process continue with its earlier information and execution position.

Keep the order clear: finish the instruction β†’ check and compare priority β†’ save state β†’ run the appropriate ISR β†’ check pending priority β†’ restore state β†’ resume the process.

Interactive: decide whether to service the request

A library loans terminal is refreshing its catalogue display. A tag reader sends a hardware interrupt because a returned item has been scanned. Choose the priority relationship, then step through what the processor does. The scenario uses no numeric priority scale: focus on the comparison with the current process.

INTERRUPT DECISION WALKTHROUGH

Choose the priority relationship

Ready

Current process

Refreshing the catalogue display

Pending request

The tag reader reports a newly scanned return

Hardware interrupt

Compared with the current process, the interrupt has:

Safe pointFinish instruction
DecisionCompare priority
PreserveSave state
HandleRun ISR
ReturnRestore and resume

Priority decision

Choose an option to see whether the processor accepts the request now or leaves it pending.

The interrupt request can wait while the current process continues. An accepted interrupt is handled between instructions.

4. Check the sequence and avoid common errors

Common errorMore accurate explanation
β€œThe processor stops as soon as the device signals.” The current instruction finishes first; the processor checks at a cycle boundary.
β€œAny interrupt is serviced immediately.” The processor compares priorities. It services the request now only if it has higher priority than the current process.
β€œThe processor can resume without saving anything.” It saves the required register contents on the stack, then restores them before resuming.
β€œThe processor jumps to the device.” The address of the appropriate ISR is loaded into the PC so the processor can run the handler.

5. Check your understanding

Answer each question before opening the suggested response.

  1. A device sends a signal to request processor attention. Is this a hardware or software interrupt?
    Suggested response

    It is a hardware interrupt because the request comes from a hardware device.

  2. When does the processor check for an interrupt request?
    Suggested response

    After finishing the current instruction, at a boundary between fetch-execute cycles.

  3. A pending interrupt does not have higher priority than the current process. What happens next?
    Suggested response

    The processor leaves the request pending and continues the current process. It can check again at a later boundary.

  4. State what is saved before the ISR and where it is saved.
    Suggested response

    The required current register contents, which form part of the processor state, are saved on the stack.

  5. What must happen after an ISR before the interrupted process resumes?
    Suggested response

    The processor checks for another higher-priority interrupt. When none needs service, it restores the saved state from the stack and resumes the previous process.

Final check

In an explanation, connect the priority decision to the outcome. Use the phrase β€œhigher priority than the current process”, and include both saving and restoring state when describing how the processor returns to its previous work.