Page 102 -
P. 102

76  CHAPTER 3 / A TOP-LEVEL VIEW OF COMPUTER FUNCTION

                       Because the I/O operation may take a relatively long time to complete, the
                  I/O program is hung up waiting for the operation to complete; hence, the user
                  program is stopped at the point of the WRITE call for some considerable period
                  of time.
                  INTERRUPTS AND THE INSTRUCTION CYCLE With interrupts, the processor can
                  be engaged in executing other instructions while an I/O operation is in progress.
                  Consider the flow of control in Figure 3.7b. As before, the user program reaches a
                  point at which it makes a system call in the form of a WRITE call.The I/O program
                  that is invoked in this case consists only of the preparation code and the actual I/O
                  command. After these few instructions have been executed, control returns to the
                  user program. Meanwhile, the external device is busy accepting data from computer
                  memory and printing it. This I/O operation is conducted concurrently with the exe-
                  cution of instructions in the user program.
                       When the external device becomes ready to be serviced—that is, when it is
                  ready to accept more data from the processor,—the I/O module for that external
                  device sends an interrupt request signal to the processor. The processor responds by
                  suspending operation of the current program, branching off to a program to service
                  that particular I/O device, known as an interrupt handler, and resuming the original
                  execution after the device is serviced. The points at which such interrupts occur are
                  indicated by an asterisk in Figure 3.7b.
                       From the point of view of the user program, an interrupt is just that: an inter-
                  ruption of the normal sequence of execution.When the interrupt processing is com-
                  pleted, execution resumes (Figure 3.8). Thus, the user program does not have to
                  contain any special code to accommodate interrupts; the processor and the operat-
                  ing system are responsible for suspending the user program and then resuming it at
                  the same point.
                       To accommodate interrupts, an interrupt cycle is added to the instruction cycle,
                  as shown in Figure 3.9. In the interrupt cycle, the processor checks to see if any


                                            User program               Interrupt handler

                                        1

                                        2
                                                •                           •
                                                •                           •
                                                •                           •

                                        i
                         Interrupt
                         occurs here
                                     i   1
                                                •
                                                •
                                                •

                                        M
                         Figure 3.8  Transfer of Control via Interrupts
   97   98   99   100   101   102   103   104   105   106   107