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
| Type | Definition | Example |
|---|---|---|
| Hardware Interrupts | Generated by external devices | Keyboard input, mouse movements, disk I/O requests |
| Software Interrupts | Triggered by software or the operating system | Division by zero errors |
| Trap Interrupts | Intentionally triggered by a program | Software debugging, handling unexpected error cases |
The interrupt process
- 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.
- 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.
- 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.
- 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.
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
Interrupt priority handling
System handling of interrupt priority