7.3 Programmed I/O
COS2621 - Computer Organisation · 7. Input/Output
7. Input/Output
7.3 Programmed I/O
Programmed Input/Output (I/O) is a method where the CPU directly controls the I/O operations. In this method, the CPU continuously checks the status of an I/O device and transfers data when the device is ready. Although programmed I/O is straightforward, it can lead to inefficiencies as the CPU may waste time waiting for I/O operations to complete.
How Programmed I/O Works
In programmed I/O, the CPU executes a series of instructions to communicate with an I/O device. The basic steps include:
- The CPU sends a command to the I/O module.
- The CPU checks the status of the I/O module.
- If the device is ready, the CPU transfers data.
- The CPU repeats the process until the operation is complete.
For example, consider a CPU reading data from a keyboard:
while (1) { // Infinite loop for continuous checking
if (keyboard_ready()) { // Check if the keyboard is ready
data = read_keyboard(); // Read data from the keyboard
process_data(data); // Process the data
}
}In this example, the CPU continuously checks if the keyboard is ready. When it is, the CPU reads the data and processes it. This loop continues indefinitely.
Watch out: Continuous polling can waste CPU cycles. It is inefficient compared to other I/O methods.
Advantages and Disadvantages of Programmed I/O
Programmed I/O has several advantages:
- It is simple to implement and understand.
- The CPU has direct control over I/O devices.
However, it also has notable disadvantages:
- The CPU is tied up while waiting for I/O operations to complete.
- This can lead to inefficient CPU usage, especially with slower devices.
Data Communication Methods
When data are moved over longer distances, to or from a remote device, the process is known as data communications. This involves the use of protocols that define rules for data exchange. Understanding these protocols is essential for effective communication between devices.
Conclusion
Programmed I/O is a basic method for managing I/O operations. While it provides direct control, it is not always efficient. Understanding its operation is crucial for grasping more advanced I/O techniques and communication methods.
Check your understanding
- What are the main steps involved in programmed I/O?
- What are the advantages and disadvantages of using programmed I/O?
- How does programmed I/O differ from interrupt-driven I/O?
- What is the process called when data is moved to or from a remote device?
Test yourself
4 quick questions on this lesson. Pick an answer to see if you're right.
1. How does programmed I/O differ from interrupt-driven I/O?
2. Which of the following is a disadvantage of programmed I/O?
3. In programmed I/O, what does the CPU do continuously while waiting for an I/O operation to complete?
4. What is the primary role of the CPU in programmed I/O?