What is a programmed I/O

It is one of the simplest forms of I/O where the CPU has to do all the work. This technique is called programmed I/O.

 It is one of the simplest forms of I/O where the CPU has to do all the work. This technique is called programmed I/O.

Consider a user process that wants to print the Nine-character string ‘‘TUTORIALS’’ on the printer with the help of a serial interface.

The software first assembles the string in a buffer in user space, as shown in the figure −

Explanation

Step 1 − The user process acquires the printer for writing by using a system call to open it.

Step 2 − If the printer is currently in use by another process, this system call fails and returns an error code or it blocks until the printer is available, depending on the operating system and the parameters of the call.

Step 3 − Once the printer is available, the user process makes a system call telling the operating system to print the string on the printer.

Step 4 − The operating system generally copies the buffer with the string to an array.

Step 5 − It then checks to see if the printer is currently available. If not, it waits until it is. Whenever the printer is available, the operating system copies the first character to the printer’s data register, In the above example use memory-mapped I/O. This action activates the printer. The character does not appear still, because some printers buffer a line or a page before printing anything.

Step 6 − In the next figure, we see that the first character has been printed and that the system has marked the ‘‘U’’ as the next character to be printed.

Step 7 − Whenever it has copied the first character to the printer, the operating system checks to see if the printer is ready to accept another one.

Step 8 − Generally, the printer has a second register, which gives its status. The act of writing to the data register causes the status to become not ready.

Step 9 − When the printer controller has processed the current character, it indicates its availability by setting some bit in its status register or putting some value in it.

Step 10 − At this point the operating system waits for the printer to become ready again.

Step 11 − It prints the next character, as shown in the third figure.

Step 12 − This loop continues till the entire string has been printed.

Step 13 − Then control returns to the user process.

Data transfer between the CPU and I/O devices can be done in variety of modes. These are three possible modes: 
 

  1. Programmed I/O
  2. Interrupt initiated I/O
  3. Direct Memory Access (DMA)

In this article we shall discuss the first two modes only. 

1. Programmed I/O : 
In this mode the data transfer is initiated by the instructions written in a computer program. An input instruction is required to store the data from the device to the CPU and a store instruction is required to transfer the data from the CPU to the device. Data transfer through this mode requires constant monitoring of the peripheral device by the CPU and also monitor the possibility of new transfer once the transfer has been initiated. Thus CPU stays in a loop until the I/O device indicates that it is ready for data transfer. Thus programmed I/O is a time consuming process that keeps the processor busy needlessly and leads to wastage of the CPU cycles. 
This can be overcome by the use of an interrupt facility. This forms the basis for the Interrupt Initiated I/O. 

2. Interrupt Initiated I/O : 
This mode uses an interrupt facility and special commands to inform the interface to issue the interrupt command when data becomes available and interface is ready for the data transfer. In the meantime CPU keeps on executing other tasks and need not check for the flag. When the flag is set, the interface is informed and an interrupt is initiated. This interrupt causes the CPU to deviate from what it is doing to respond to the I/O transfer. The CPU responds to the signal by storing the return address from the program counter (PC) into the memory stack and then branches to service that processes the I/O request. After the transfer is complete, CPU returns to the previous task it was executing. The branch address of the service can be chosen in two ways known as vectored and non-vectored interrupt. In vectored interrupt, the source that interrupts, supplies the branch information to the CPU while in case of non-vectored interrupt the branch address is assigned to a fixed location in memory. 

Difference between Programmed and Interrupt Initiated I/O : 
 

Programmed I/OInterrupt 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.

Post a Comment

© CSA. The Best Codder All rights reserved. Distributed by