I/O Handling Methods: Interrupt-Driven I/O
- The interrupt mechanism goes as follows:
- A device controller, which is a piece of hardware in the device whose purpose is to control the device's I/O signals, sends a signal to the CPU via a wire called an interrupt-request line.
- In-between the execution of a program's instructions, the CPU notices that the controller issued a signal, and reads the interrupt number (which indicates what the interrupt type is.)
- The CPU uses this number as an index into the interrupt vector to call the appropriate interrupt handler.
- The handler first saves the current execution state, which includes the values inside the registers, back to main memory (so that the CPU could return executing code after the interrupt is handled,) finds the reason for the interrupt, and performs all the actions needed to resolve the interrupt.
- The CPU then restores the saved execution state from RAM and continues running the instructions of the program that was running before the interrupt occurred.