I/O Handling Methods: Program-Controlled I/O
To what extent is the CPU involved in transferring data into and out of the computer? Here are 4 methods:
- Program-Controlled I/O (also called Polling I/O) is when the CPU runs a single program in which it continuously polls (= checks) a special control register on each I/O device that is connected to the computer to see if that I/O device is ready to transfer data. This is literally the only action the CPU does in its free time: it doesn't run any other programs.
Only when data becomes available, the CPU performs the transfer, and then returns to that busy-waiting state.
Pros: We can easily change or add more I/O devices to the computer just by changing a few code lines in the program.
Cons: The CPU is busy waiting or just doing I/O and can't run any other program (needless to say multiple programs.)
One example of a device that might use a program-controlled I/O is a simple vending machine whose sole purpose is to wait for customers to purchase something and dispense the goods when the customer enters the right amount of money.