9.4Interrupt handling
The idea
Handling an interrupt means: finish the current instruction, save context, jump to the interrupt service routine, run it, then return.
Think of it like this: You pause your reading with a bookmark, answer the doorbell, then return to your page.
Why it exists
The program must not notice it was interrupted.
How it works
- Device asserts INTR, CPU completes the instruction and acknowledges.
- PC and flags are pushed on the stack; further interrupts may be disabled.
- PC loads the ISR address from the vector table.
- IRET pops the saved state and resumes.
Worked example: Vectored interrupt
The device supplies a vector number that selects the ISR address; non-vectored needs polling to find the source.
Now play with it
- →Step through all eight stages.
- Device asserts INTR while the CPU is running the main program
- CPU finishes the current instruction (interrupts are recognised at instruction boundaries)
- CPU checks the interrupt is not masked, then sends INTA (acknowledge)
- Vectored device places its vector on the data bus (or CPU uses a fixed address)
- CPU saves PC and flags on the stack, and disables further interrupts
- PC ← address of the ISR (from the interrupt vector table)
- ISR runs: service the device, then restore registers
- IRET pops flags and PC, interrupts re-enabled, main program resumes
Check yourself
Which values must the CPU save before running the ISR?
Exam notes (the dense version)
Finish current instr → ack → save PC/flags → get vector → run ISR → restore → resume. Vectored = device supplies ISR address. Maskable vs non-maskable. Priority via daisy chain (closest device wins) or priority encoder.
Previous year questions: I/O Interface, Interrupts & DMA (8)
PYQs are grouped by topic, so this is the full set for I/O Interface, Interrupts & DMA; try the ones that match this subtopic. Open all 8 on the topic page.