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.
| Source | How the request begins | General 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. |
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 comparison | Processor 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.
- Save state: copy the required register contents to the stack.
- Find the handler: load the address of the appropriate ISR into the PC.
- Run the ISR: the processor executes the routine for the interrupt.
- Check pending requests: after the ISR, check whether another interrupt has higher priority than the current process.
- 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.
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.
4. Check the sequence and avoid common errors
| Common error | More 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.
-
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.
-
When does the processor check for an interrupt request?
Suggested response
After finishing the current instruction, at a boundary between fetch-execute cycles.
-
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.
-
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.
-
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.