← 🔌 I/O Interface, Interrupts & DMA
Subtopic 4 of 8

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

  1. Device asserts INTR, CPU completes the instruction and acknowledges.
  2. PC and flags are pushed on the stack; further interrupts may be disabled.
  3. PC loads the ISR address from the vector table.
  4. 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?

Remember: Save PC and flags, run ISR, restore, resume.
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.