先决条件– I / O接口(中断和DMA模式)
CPU和I / O设备之间的数据传输可以采用多种模式进行。这是三种可能的模式:
- 编程的I / O
- 中断启动的I / O
- 直接内存访问(DMA)
在本文中,我们将仅讨论前两种模式。
1.编程的I / O:
在这种模式下,数据传输由计算机程序中编写的指令启动。需要输入指令将数据从设备存储到CPU,并且需要存储指令将数据从CPU传输到设备。通过此模式进行的数据传输需要CPU不断监视外围设备,并且一旦传输开始就监视新传输的可能性。因此,CPU保持循环状态,直到I / O设备指示它准备好进行数据传输为止。因此,编程的I / O是一个耗时的过程,它会使处理器不必要地保持繁忙,并导致CPU周期的浪费。
这可以通过使用中断工具来克服。这构成了中断启动的I / O的基础。
2.中断启动的I / O:
当数据可用并且接口准备好进行数据传输时,此模式使用中断工具和特殊命令来通知接口发出中断命令。同时,CPU继续执行其他任务,无需检查该标志。设置标志后,将通知接口并启动中断。该中断导致CPU偏离其对I / O传输的响应。 CPU通过将来自程序计数器(PC)的返回地址存储到存储器堆栈中来响应该信号,然后跳转到处理I / O请求的服务。传输完成后,CPU返回到它正在执行的上一个任务。服务的分支地址可以通过两种方式选择,即向量中断和非向量中断。在向量中断中,中断源将分支信息提供给CPU,而在非向量中断的情况下,分支地址被分配到内存中的固定位置。
编程和中断启动的I / O之间的区别:
Programmed I/O | Interrupt Initiated I/O |
---|---|
Data transfer is initiated by the means of instructions stored in the computer program. Whenever there is a request for I/O transfer the instructions are executed from the program. | The I/O transfer is initiated by the interrupt command issued to the CPU. |
The CPU stays in the loop to know if the device is ready for transfer and has to continuously monitor the peripheral device. | There is no need for the CPU to stay in the loop as the interrupt command interrupts the CPU when the device is ready for data transfer. |
This leads to the wastage of CPU cycles as CPU remains busy needlessly and thus the efficiency of system gets reduced. | The CPU cycles are not wasted as CPU continues with other work during this time and hence this method is more efficient. |
CPU cannot do any work until the transfer is complete as it has to stay in the loop to continuously monitor the peripheral device. | CPU can do any other work until it is interrupted by the command indicating the readiness of device for data transfer |
Its module is treated as a slow module. | Its module is faster than programmed I/O module. |
It is quite easy to program and understand. | It can be tricky and complicated to understand if one uses low level language. |
The performance of the system is severely degraded. | The performance of the system is enhanced to some extent. |