What are interrupts?

  • An interrupt is a signal to the processor that stops its current task and performs a different task temporarily
  • Interrupts can be hardware events or time-sensitive tasks
  • When an interrupt occurs, the processor suspends the current program execution and transfers control to an interrupt service routine (ISR)

Purpose and role of interrupts

  • Real-time Event Handling: hardware errors and signals from input devices e.g. hard disk failure
  • Device Communication: alerts from external devices e.g. printer jams and network errors
  • Multitasking: suspending processing in one application so that the user can switch to another

Types of interrupts

TypeDefinitionExample
Hardware InterruptsGenerated by external devicesKeyboard input, mouse movements, disk I/O requests
Software InterruptsTriggered by software or the operating systemDivision by zero errors
Trap InterruptsIntentionally triggered by a programSoftware debugging, handling unexpected error cases

The interrupt process

  1. Saving Current State:
    • The processor pushes the values in the registers into a memory structure called the stack.
    • These values are stored in a stack frame to preserve the program’s current state.
  2. Executing the ISR:
    • The Program Counter (PC) is updated to point to the instructions of the ISR.
    • The ISR executes its FDE cycle to handle the interrupt.
  3. Restoring State:
    • After the ISR completes, the processor retrieves the saved values by popping the stack frame, restoring the original program’s state.
    • The PC is updated to point back to the interrupted program, and the processor resumes the interrupted program.
  4. Handling Priorities:
    • If a higher-priority interrupt occurs during an ISR, the higher-priority ISR takes precedence, and its state is also saved in the stack.
Diagram illustrating interrupt handling in a CPU, showing stages: initialise program, fetch decode execute, interrupt handler, and service routines.
The Interrupt Process

What is an ISR?

  • An ISR is a special function that handles a particular interrupt type
  • Each type of interrupt has a corresponding routine, e.g. printer jam, hard disk failure, file download error, network connection error all have routines to be followed when they happen
  • ISRs should be concise, efficient, and carefully designed to minimise the time taken to execute, as they often need to handle time-sensitive events

Interrupt priority and nesting

  • Interrupt prioritisation means the processor can acknowledge and switch to resolving a higher-priority interrupt
  • Prioritising interrupts is vital because many things can go wrong at the same time
  • Lower-priority ISRs may be temporarily suspended until the higher-priority ISR completes the execution
  • Nesting of interrupts refers to the ability of the processor to handle interrupts within interrupts
  • Proper management of nested interrupts avoids potential conflicts and ensures system stability

Nesting of interrupts Nesting of interrupts

Interrupt priority handling

Diagram shows an interrupt queue with low, medium, and high priorities managed by an interrupt controller, highlighting priority handling shifts. System handling of interrupt priority