A program that runs only on data that is already in memory is not useful. The computer must also read data from a keyboard and show results on a screen. The basic computer does this through a small input-output interface, and it deals with urgent events through interrupts.
Input-Output Configuration
The keyboard sends an 8-bit character to the input register INPR, and a flag FGI is set to show that a character is waiting. For output, the program puts a character in OUTR, and a flag FGO shows whether the output device is ready. The instruction INP moves INPR to the accumulator and OUT moves the accumulator to OUTR. SKI and SKO skip the next instruction if the flag FGI or FGO is set.
Definition: Interrupt. A signal that makes the processor stop its current program temporarily, save its state and run a special routine to service an event, after which the program resumes.
Programmed and Interrupt-Driven Input-Output
In programmed input-output, the program repeatedly tests a flag until the device is ready. This wastes processor time. With interrupt-driven input-output, the device signals the processor when it is ready, and the processor performs other work in the meantime. A flip-flop IEN, set by ION and cleared by IOF, enables or disables interrupts. An interrupt flip-flop R is set when the interrupt is accepted.
Interrupt Cycle
When R = 1 at the end of an instruction, the computer enters the interrupt cycle instead of fetching the next instruction. Return address is saved at memory location 0, and execution continues from location 1, where the service routine begins.
Table 3.4: Programmed and interrupt-driven input-output
| Property | Programmed | Interrupt-driven |
|---|---|---|
| Who checks the device | The program | The device signals the CPU |
| Use of CPU time | Wasted in waiting | Used for other work |
| Hardware needed | Flags only | Flags, IEN and R |
| Response | Depends on the program | Immediate after the instruction |
Example 3.5: Servicing a keystroke
Problem: A key is pressed while interrupts are enabled, and the PC holds 45 when the instruction in progress completes. State where the return address is kept and where the service routine starts.
Solution:
- RT0: AR is cleared to 0 and the return address 45 is copied to TR.
- RT1: the return address is stored in memory location 0, and PC is set to 0.
- RT2: PC becomes 1, and IEN and R are cleared so that no second interrupt arrives.
Result: The return address 45 is kept at location 0 and the service routine starts at location 1.
Common mistakes
- Believing that the interrupt stops the instruction in progress. It is serviced after the instruction ends.
- Forgetting to clear IEN, which allows an interrupt during the service routine.
- Assuming the return address is stored in the accumulator.
Key takeaways
- FGI and FGO are the input and output flags.
- Programmed input-output wastes CPU time in waiting.
- The interrupt cycle saves the PC at location 0 and starts the routine at location 1.
- ION and IOF enable and disable interrupts.
Practice questions
- What is the function of the instruction INP?
- Where is the return address stored in the interrupt cycle of the basic computer?
- Why is interrupt-driven input-output better than programmed input-output?
Answers to the practice questions
- It transfers the character in INPR to the accumulator.
- In memory location 0.
- The CPU can do other work while the device is busy.
Sources
- Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit III
