1. Gyanastra
  2. Computer Organisation and Architecture
  3. I/O Interface and Interrupts
  4. Programmed I/O and Busy Waiting
Free lesson, no account needed 5 min read 21 practice questions after it
Asked in past papers2 times
  • GATE CSE2023
  • UGC NET2015

Computer Organisation and Architecture · I/O Interface and Interrupts

Programmed I/O and Busy Waiting

Overview

Programmed I/O is a data-transfer technique in which the CPU runs a small I/O program to move data to or from a device, repeatedly testing the device's status flag before each transfer.
Because the CPU sits in a loop doing nothing useful while the device is not ready, the technique is also called busy waiting (polling). Its cost is that the CPU is tied up while waiting for a slow device.

Key concepts

  • Programmed I/O: a data-transfer technique in which the CPU itself runs an I/O program (a small loop of instructions) to transfer data to/from an I/O device.
    The CPU continuously tests the device's status flag and only reads/writes the data register when the flag indicates the device is ready.
  • Busy waiting (polling): the repeated testing of the device status flag while the CPU waits; the CPU is occupied in the loop and does no useful work during that time.
  • Input flag: a status bit set to 1 by the I/O device when it has data ready in its input register; it is 0 while no data is available. The device, not the CPU, sets the flag.
  • I/O program: three instructions at consecutive memory locations (200, 201, 202 in the example) that test the flag, loop back if not ready, and read the data when ready.

How it works

The I/O program occupies three consecutive memory locations:

AddressInstructionPurpose
200Skip if input flag = 1Test the device status flag; if the flag is 1 (data available), skip the next instruction
201Branch unconditional (back to 200)If the flag was 0, jump back and test again
202INP (input)Read the data from the input register into the CPU
  1. The I/O device sets the input flag to 1 when it has data ready in its input register; the flag is 0 while no data is available.
  2. The CPU executes the "skip if input flag = 1" instruction at 200.
    • If the flag is 0 (data not available), the skip does not happen, so the CPU executes the unconditional branch at 201, which sends it back to 200.
      The CPU keeps testing the flag over and over — this repeated testing is the busy waiting.
    • If the flag is 1 (data available), the skip takes effect, instruction 201 is skipped, and the CPU executes INP at 202, reading the data from the input register.
  3. The device itself makes the flag 1 when data becomes available; only then is the data read.
Figure. Programmed I/O. At 200 the CPU tests the input flag and skips the next instruction if it is 1. If the flag is 0, nothing is skipped, so the branch at 201 sends the CPU back to 200 to test again: this loop is the busy waiting. When the flag is 1, 201 is skipped and INP at 202 reads the data.

Formulas

  • 1 microsecond=10−6 seconds1 \text{ microsecond} = 10^{-6} \text{ seconds}
  • Instructions per second=11 microsecond=106=1 million\text{Instructions per second} = \dfrac{1}{1 \text{ microsecond}} = 10^6 = 1 \text{ million}
  • MIPS=million instructions per second\text{MIPS} = \text{million instructions per second}

Worked examples

Cost of busy waiting. Assume the complete instruction cycle (instruction fetch, decode, execute — everything together) takes 1 microsecond on average per instruction.

  • 1 microsecond = 10−610^{-6} seconds.
  • In 1 second the CPU can execute 10610^6 = 1 million instructions; this rate is symbolically written as MIPS (million instructions per second). This is the capability of the simple computer.
  • Suppose the input is typed by a user on the keyboard at only a few characters per second (e.g. 10 characters per second).
    The CPU must keep executing the polling loop (test flag, branch back, test flag, …) for the entire time between characters.
    All of those instruction cycles are spent merely checking the flag, not doing useful work — the CPU is stuck in the I/O program while the device is slow.

Revision summary

  • Programmed I/O = CPU-driven transfer using an explicit I/O program; the CPU polls the device status flag.
  • Polling loop order: Skip if input flag = 1 → Branch unconditional back to the test → INP (addresses 200, 201, 202 in the example).
  • Flag = 0: no skip, branch back, test again (busy waiting).
    Flag = 1: skip the branch, execute INP and read the data.
  • The device, not the CPU, sets the flag to 1 when data is ready.
  • Main disadvantage: the CPU is tied up in the polling loop and cannot do other useful work while waiting for the slow I/O device.
  • Numerical anchor: if one instruction takes 1 microsecond, the CPU executes 10610^6 instructions per second = 1 MIPS.

Previous-year exam insights

  • In programmed I/O (polling), the fraction of CPU time consumed by polling equals (number of polls per second) × (time per poll); the fraction spent processing equals (number of actual transfers per second) × (time per transfer).
    Asked inGATE 2023
  • Programmed I/O wastes CPU cycles only while the device is not ready; the CPU cannot execute any other program during polling, whereas interrupt-driven I/O frees the CPU until the device signals readiness.
    Asked inGATE 2023
  • In programmed I/O the CPU repeatedly reads the device status register and checks the ready/busy flag; the actual data transfer happens only when the flag indicates readiness, and the device (not the CPU) sets the flag.
    Asked inGATE 2023
  • DMA transfers data directly between memory and the device without CPU involvement per word, interrupting the CPU only once per block, so it is preferred over programmed I/O for fast block devices.
  • In interrupt-driven I/O the device raises an interrupt request when ready; the CPU saves context, runs an interrupt service routine to transfer the data, then resumes the interrupted program, so no busy waiting occurs.
  • Memory-mapped I/O uses the same address space and instructions as memory (no special IN/OUT instructions), while isolated (port-mapped) I/O uses separate I/O instructions and a distinct I/O address space.
Pages 1–2 of 2