Lesson6 Input and Output Devices and Interrupts
Lesson6 Input and Output Devices and Interrupts
Chapter Objectives
At the end of the chapter the learner shall be able to;
Explain input and output devices and the role they play in a computer
Define the term interrupt and explain the different types of interrupts
Explain how an interrupt handler operates
The input and output devices are discussed in details in chapter 2 of the module.
5.3 Interrupts
An interrupt is a signal from some device or source seeking the attention of the
processor. The interrupt signal is sent along a control line to the processor, and
the currently executing program is suspended while control is passed to an
interrupt service routine.
The following are the different types of interrupt that could occur;
41
Program check interrupts; these are caused by various types of error such
as division by zero.
Machine check interrupts; these are caused by malfunctioning hardware
There is a special register in the CPU called the interrupt register. At the
beginning of each fetch-execute cycle, the interrupt register is checked. Each
bit of the register represents a different type of interrupt, and if a bit is set,
the state of the current process is saved and the operating system routes
control to the appropriate interrupt handler.
What happens when, for example, a key on the keyboard is pressed, thus
generating an interrupt? A small program called an interrupt service routine
(ISR) or interrupt handler is executed to transfer the character value f the key
pressed into main memory. A different ISR is provided for each different
source of interrupt. A typical sequence of actions when an interrupt occurs
would be:
42
1. The current fetch-execute cycle is completed
2. The contents of the program counter, which points to the next instruction of
the program to be executed, must be stored away safely so it can be restored
after servicing the interrupt.
3. The contents of other registers used by the user program are stored
away safely for later restoration
4. The source of the interrupt is identified
5. Interrupts of a lower priority are disabled
6. The program counter is loaded with the start address of the
relevant interrupt service routine.
7. The interrupt service routine is executed
8. The saved values belonging to the user program for registers other than the
program counter are restored to the processor’s registers
9. Interrupts are re-enabled
10. The program counter is restored to point to the next instruction to
be fetched and executed in user program