Programmed I/O is one of the three techniques we use for I/O transfer. The other two methods for the same are interrupted I/O and (direct memory access) DMA. Programmed I/O is a technique or approach that we use to transfer data between the processor and the I/O module.
If we talk of programmed I/O and interrupted I/O, it is the responsibility of the processor to control the transfer from I/O to main memory as input and from main memory to I/O as output. On the other way, the DMA does not involve a processor, the main memory and I/O exchange their data directly.
In the section ahead we will discuss the need and functioning of programmed I/O.
What is the Need?
To understand the need and functioning of the programmed I/O consider a scenario of human and computer interaction where the human types something on the keyboard. Now the processor has to save this data into the memory and has to display the same data on the display device.
With the programmed I/O this entire functioning is regulated with the help of a program. This action of transferring the typed characters from the keyboard to memory and then to the display module must happen at the right time.
Let us take this in more detail the input from the keyboard is accepted when the key is being pressed on the keyboard by the user. And the output can be sent to the display module only when the module is ready to accept it.
Here the speed at which the data is transferred from the keyboard to the computer memory depends on the typing speed of the computer. On the other hand, the speed at which the output data from memory is transferred to the display module is very high.
The speed at which the character can be transmitted and displayed on the display module is still much slower if compared to the speed of the processor. So, to overcome the difference in the speed of the processor and I/O device a mechanism must be implemented to synchronize the transfer of data between the processor and I/O modules. This is we require programmed I/O
Functioning of programmed I/O
Consider the situation that the processor is busy executing any program. Meanwhile, it encounters an I/O instruction. To execute the encountered instruction the process supply an appropriate I/O command to the corresponding I/O module. Accepting the issued command, the I/O module performs the desired task and sets some appropriate bits of its I/O status registers. As we have seen in our previous content, the bus structure that each I/O interface has a set of registers.
Further, the I/O module does not notify the processor that it has performed the desired task. Moreover, it’s the processors’ responsibility to periodically check the status of the I/O module till it finds that the I/O has successfully completed the desired task.
If you have observed the function of the programmed I/O it involves two things the I/O command that is provided by the processor to the I/O module and the I/O instruction that is encountered and executed by the processor. Let us discuss these two things.
Whenever the processor experience the I/O related instruction, to execute this I/O instruction the processor issues two things I/O command and address on the bus which is decoded by every I/O module connected to the system. Whichever I/O module is addressed by the processor recognizes this address respond to the issued I/O command.
The processor issue the I/O commands to the I/O module can be of four types.
- Control: This I/O command activates the I/O module addressed by the processor and directs it to the task it has to perform. This command can be customized depending upon the type of peripherals.
- Test: This I/O command tests the status of the I/O module and its peripherals to ensure that the addressed peripheral is powered on and available for the task. This command also tests whether the most recent I/O operation has completed successfully or if any error has occurred.
- Read: This I/O command lets the I/O module extract the data from the corresponding peripheral and store it in its internal buffer. Further, the I/O module can place this data over the data bus on the processor’s demand.
- Write: This I/O command lets the I/O module accept the data over the data bus and transmit it to the corresponding peripheral.
The I/O instruction encountered by the processor is issued to the processor by the main memory. And to execute this I/O instruction the processor provides the I/O command to the corresponding I/O device. Thereby the I/O instruction cab is simply mapped onto the I/O command. Usually, there is a simple one-to-one relationship between I/O instruction and I/O command.
The I/O instruction can also be customized depending on the peripherals addressed. As we have discussed above how the external device or peripheral recognizes that the processor is addressing them and has issued them the I/O command.
So, when the processor, main memory, and I/O module share the common bus then addressing can be achieved in two ways memory-mapped I/O and isolated I/O.
With the memory-mapped I/O, the processor access memory and I/O using a single address space. Here the processor uses the same address, data, and control bus. So, the same set of machine instructions addresses both memory and I/O.
With isolated I/O the address space for memory is isolated from the address space of I/O. Though the processor uses the same data and address line for memory and I/O devices it uses a separate control line for memory and I/O devices.
The memory-mapped I/O has a large set of I/O instructions as compared to the isolated I/O.
So, with the programmed I/O for every I/O transfer or I/O operation, a program is written to implement the task. The other two methods of I/O transfer i.e. interrupted I/O and DMA involve the use of interrupt.