Page 103 -
P. 103
3.2 / COMPUTER FUNCTION 77
Fetch cycle Execute cycle Interrupt cycle
Interrupts
disabled
Check for
Fetch next Execute
START interrupt;
instruction instruction Interrupts
process interrupt
enabled
HALT
Figure 3.9 Instruction Cycle with Interrupts
interrupts have occurred, indicated by the presence of an interrupt signal. If no
interrupts are pending, the processor proceeds to the fetch cycle and fetches the
next instruction of the current program. If an interrupt is pending, the processor
does the following:
• It suspends execution of the current program being executed and saves its
context. This means saving the address of the next instruction to be executed
(current contents of the program counter) and any other data relevant to the
processor’s current activity.
• It sets the program counter to the starting address of an interrupt handler routine.
The processor now proceeds to the fetch cycle and fetches the first instruction
in the interrupt handler program, which will service the interrupt.The interrupt han-
dler program is generally part of the operating system.Typically, this program deter-
mines the nature of the interrupt and performs whatever actions are needed. In the
example we have been using, the handler determines which I/O module generated
the interrupt and may branch to a program that will write more data out to that I/O
module.When the interrupt handler routine is completed, the processor can resume
execution of the user program at the point of interruption.
It is clear that there is some overhead involved in this process. Extra instructions
must be executed (in the interrupt handler) to determine the nature of the interrupt
and to decide on the appropriate action. Nevertheless, because of the relatively large
amount of time that would be wasted by simply waiting on an I/O operation, the
processor can be employed much more efficiently with the use of interrupts.
To appreciate the gain in efficiency, consider Figure 3.10, which is a timing dia-
gram based on the flow of control in Figures 3.7a and 3.7b. Figures 3.7b and 3.10 as-
sume that the time required for the I/O operation is relatively short: less than the
time to complete the execution of instructions between write operations in the user
program.The more typical case, especially for a slow device such as a printer, is that
the I/O operation will take much more time than executing a sequence of user in-
structions. Figure 3.7c indicates this state of affairs. In this case, the user program
reaches the second WRITE call before the I/O operation spawned by the first call is