Explain the process of handling an interrupt that occurs during a program? 9m jun2006

By | January 30, 2015

Explain the process of handling an interrupt that occurs during the execution of a program, with the help of an example. 9m jun2006


Interrupt Handling and Instruction Cycle

 On the occurrence of an interrupt, an interrupt request (in the form of a signal) is issued to the CPU. The CPU on receipt of interrupt request suspends the operation of the currently executing program, saves the context of the currently executing program and starts executing the program which services that interrupt request. This program is also known as interrupt handler. After the interrupting condition/ device have been serviced the execution of original program is resumed.

Thus, an interrupt can be considered as the interruption of the execution of an ongoing user program. The execution of user program resumes as soon as the interrupt processing is completed. Therefore, the user program does not contain any code for interrupt handling. This job is to be performed by the processor and the operating system, which in turn is also responsible for suspending the execution of the user program, and later after interrupt handling, resumes the user program from the point of interruption.


But when can a user program execution are interrupted?

It will not be desirable to interrupt a program while an instruction is getting executed and is in a state like instruction decode. The most desirable place for program interruption would be when it has completed the previous instruction and is about to start a new instruction. Figure 7 shows instruction execution cycle with interrupt cycle, where the interrupt condition is acknowledged. Please note that even interrupt service routine is also a program and after acknowledging interrupt the next instruction executed through instruction cycle is the first instruction of interrupt servicing routine.

In the interrupt cycle, the responsibility of the CPU/Processor is to check whether any interrupts have occurred checking the presence of the interrupt signal. In case no interrupt needs service, the processor proceeds to the next instruction of the current program.


In case an interrupt needs servicing then the interrupt is processed as per the following.

  •  Suspend the execution of current program and save its context.
  •  Set the Program counter to the starting address of the interrupt service routine of the interrupt acknowledged.
  •  The processor then executes the instructions in the interrupt-servicing program. The interrupt servicing programs are normally part of the operating system.
  •  After completing the interrupt servicing program the CPU can resume the program it has suspended in step 1 above.