Cambridge A-Level Computer Science – 4.1 CPU Architecture: Purpose of Interrupts
4.1 Central Processing Unit (CPU) Architecture
Objective: Understand the purpose of interrupts
An interrupt is a signal that temporarily halts the normal sequential execution of a program, allowing the CPU to service an event that requires immediate attention. After the interrupt is serviced, the CPU resumes the original program where it left off.
What is an interrupt?
In a typical fetch‑decode‑execute cycle, the CPU repeatedly performs the following steps:
If an external or internal event occurs, an interrupt can insert a new sequence of steps into this cycle.
Why are interrupts needed?
Responsiveness: Allows the system to react quickly to time‑critical events (e.g., keyboard input, timer expiry).
Efficient use of CPU time: The CPU can perform useful work instead of constantly polling devices.
Multitasking support: Enables the operating system to switch between processes or threads.
Resource management: Facilitates handling of I/O completion, error conditions, and hardware failures.
Types of interrupts
Type
Source
Typical Use
Hardware interrupt
External devices (keyboard, mouse, network card)
Notify CPU that data is ready or a device needs service
Software interrupt (trap)
Program instruction (e.g., system call)
Request operating‑system services
Timer interrupt
Internal timer circuit
Implement time slicing for multitasking
Exception (fault)
CPU detects illegal operation (divide by zero, page fault)
Transfer control to error‑handling routine
How an interrupt is handled
Interrupt request (IRQ) raised: A device or condition asserts an interrupt line.
CPU acknowledges: At the end of the current instruction, the CPU checks the interrupt flag.
Save context: The current program counter (PC) and status registers are pushed onto the stack.
Jump to interrupt service routine (ISR): The CPU loads the address of the ISR from an interrupt vector table.
Execute ISR: The routine performs the necessary handling (e.g., read a byte from a keyboard buffer).
Restore context: The saved PC and registers are popped from the stack.
Resume original program: Execution continues from the point where it was interrupted.
Benefits of using interrupts
Reduces wasted CPU cycles compared with polling.
Improves system throughput and latency.
Enables real‑time response for critical hardware events.
Supports pre‑emptive multitasking, allowing multiple programs to share the CPU.
Suggested diagram: Flowchart showing the normal fetch‑decode‑execute cycle with a branch that diverts to an interrupt service routine when an IRQ is detected.
Key points to remember
An interrupt temporarily suspends the current instruction stream.
The CPU must save the current execution state before servicing the interrupt.
Interrupts can be masked (disabled) to protect critical sections of code.
Prioritisation of interrupts ensures that more urgent events are handled first.