Interrupting is a mechanism by which the input or output devices of a computer informs the processor that it is ready to do its operation by raising a signal called interrupts.
It is highly related to the internal working of a computer. The input or output devices of a computer are connected to a processor by means of a
bus. It is necessary to check the status of all input or output devices repeatedly to know if the device is ready to do its operation(read or write). This consumes lot of CPU time which can be used more effectively in doing other operations. Interrupts are used to avoid this.When an input device raises an interrupt signal processor comes to know that the device is ready. Then the processor will stop the current operation that is being executed by it and will begin to process the I/O device that caused interrupt signal. After knowing which device caused the interrupt, it will call a
subroutine in response to it. This is called an
interrupt service routine.
When an interrupt occurs, the current routine that was being executed by the processor, will be put into a
stack in a known location. Later after servicing the interrupt the processor will come back to this routine. There can be interrupts in between interrupts. These are called
nested interrupts. When a nested interrupt occurs, the last interrupt will be pushed to the stack again. Likewise, after servicing the last interrupt like that, the processor will 'run back' by popping previous routines that was saved in the stack. The process of saving instructions are done automatically by saving
When an interrupt occurs, the processor must inform the I/O device that it had identified the interrupt after doing so. This is done by an
interrupt acknowledge signal that is sent back to it through the BUS.
Following is the typical scenario when an interrupt signal is raised:
- The I/O device raises an interrupt request.
- The processor stops(interrupts) the routine currently being executed.
- Further interrupts are disabled.
- The I/O device is informed that the interrupt is recognized. In response the I/O device deactivates the interrupt request signal.
- The action required by the interrupt is performed by the interrupt service routine.
- After completion, the interrupts are enabled and execution of the program that was previously interrupted was continued.
Vectored interruptsOnce a device raises an interrupt signal, the processor just knows that an interrupt is raised and not which device raised the interrupt. So it is necessary for processor to
poll all the devices to know which device raised the interrupt. To avoid this, the interrupt signal itself can include the address of device raising the interrupt. Such interrupts are called
vectored interrupts. The code supplied by the device will represent the starting address of the interrupt service routine for that device.