Courses / Computer Science I
Introduction to Computers

Input-Output and Peripheral Communication

Computer Science I 263 words Free to read

Talking to the Outside World

A CPU on its own is deaf and mute; input/output (I/O) is how it communicates with peripherals — keyboards, disks, networks, displays. The challenge is that devices are enormously slower than the CPU and operate on their own schedule, so the machine needs disciplined ways to coordinate.

The simplest method is polling (programmed I/O): the CPU repeatedly asks a device "are you ready yet?" in a loop. It is simple but wasteful — the CPU burns cycles spinning while it waits, doing no useful work.

The better method is interrupts. The CPU issues a request and then goes on with other work; when the device is ready, it sends an interrupt signal. The CPU pauses what it is doing, saves its state, runs a short interrupt handler (interrupt service routine) to deal with the device, then restores its state and resumes. Interrupts let a slow device get attention only when needed, freeing the CPU in the meantime.

For moving large blocks of data (say, from disk to memory), even interrupts-per-byte would swamp the CPU. Direct memory access (DMA) solves this: a dedicated DMA controller transfers data between a device and main memory without the CPU moving each byte, interrupting the CPU only once when the whole transfer is complete.

Common pitfall: assuming polling is generally better because it is simpler. Polling wastes the CPU by busy-waiting; for anything but the most trivial or timing-critical cases, interrupts (and DMA for bulk transfers) are far more efficient, because they let the CPU do useful work instead of spinning.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes
Start Computer Science I free

Introduction to Computers