Skip to content
Tutorials Center
My learning

Topics

Lesson 50 of 67 ยท Input/Output

I/O Interfaces, Handshaking and Priority Interrupts

Learn how I/O interfaces connect devices: isolated versus memory-mapped ports, strobe and handshake transfers, and daisy-chain priority interrupts, with Python models.

The I/O organization lesson showed three ways to move data: polling, interrupts and DMA. This lesson looks at what sits underneath: the interface between the CPU and a device, how the two sides agree on when a transfer happens when they run at different speeds, and how the CPU decides between several devices that all want attention at once.

You will compare isolated and memory-mapped I/O, see how strobe and handshake signals coordinate asynchronous transfers, and simulate a daisy chain priority scheme.

What an interface does

A device cannot plug into the CPU's buses directly. Its signals, speed and data format differ from the processor's. An I/O interface (also called a port or controller) sits between them and does four jobs:

  • Address decoding: responds only when the CPU addresses one of its registers.
  • Buffering: holds data so the CPU and device can run at different speeds.
  • Conversion: changes formats, for example parallel to serial.
  • Status and control: exposes registers for commands ("start"), status ("ready", "error") and data.

Isolated versus memory-mapped I/O

The CPU needs a way to tell the memory from the devices. There are two arrangements.

Isolated (port-mapped) I/O Memory-mapped I/O
Address space separate from memory shared with memory
Instructions special IN and OUT ordinary loads and stores
Control signal separate IO/M line says which space none needed
Address space cost memory keeps its full range devices use up some addresses
Flexibility fewer addresses to decode all memory instructions and addressing modes work on devices

In isolated I/O a control line (often called IO/M) says whether an address refers to a port or to memory, so port 0x60 and memory address 0x60 are different things. In memory-mapped I/O a block of addresses is reserved for devices, and a normal store to one of them sends data to a device. RISC architectures and most modern systems use memory-mapped I/O; x86 offers both.

Python An address decoder with a memory-mapped device

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The same store function writes to RAM and to the device. The decoder looks at the address and routes the access. That uniformity is the main appeal of memory-mapped I/O.

Asynchronous transfer: strobe and handshake

A synchronous transfer is easy if both sides share a clock. But a CPU and a printer do not. For asynchronous transfers the two sides use control signals to agree when data is valid.

Strobe. One side raises a single pulse to say "the data is on the lines now". In a source-initiated strobe, the sender puts data on the bus then pulses a strobe, and the receiver latches the data on the pulse. The weakness: the sender does not know whether the receiver actually took the data, and in a destination-initiated strobe the receiver does not know the data is valid. Neither can detect a problem.

Handshake. Two signals travel in opposite directions, so each step is acknowledged:

  1. Sender puts data on the bus and raises data valid.
  2. Receiver reads the data and raises data accepted.
  3. Sender sees the acceptance, drops data valid (and may change the data).
  4. Receiver sees data valid drop and drops data accepted. Ready for the next item.
sequenceDiagram
  participant S as Sender
  participant R as Receiver
  S->>R: data on bus, DATA VALID = 1
  R->>S: DATA ACCEPTED = 1 (data latched)
  S->>R: DATA VALID = 0
  R->>S: DATA ACCEPTED = 0 (ready again)

A four-phase handshake: every signal change is a reply to the previous one, so neither side needs a clock.

Handshaking works whatever the speed of either side, and a missing reply is detectable (a timeout can flag a dead device). The cost is extra signals and round trips.

Python A four-phase handshake between a fast sender and a slow receiver

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The sender never moves on until it sees the acknowledgement. If the receiver took 4 ticks or 40, the data still arrives intact.

Priority interrupts and the daisy chain

When several devices share one interrupt request line, the CPU must find out which one asked, and choose when two ask at once. The classic hardware answer is the daisy chain: the CPU's interrupt-acknowledge signal travels through the devices in series. Each device that has a request pending blocks the signal and puts its vector (an ID that selects its handler) on the bus. A device with no request passes the signal on to the next. The device physically closest to the CPU therefore has the highest priority.

flowchart LR
  CPU["CPU"] -->|"acknowledge"| D1["Device 1<br/>highest priority"]
  D1 -->|"pass if idle"| D2["Device 2"]
  D2 -->|"pass if idle"| D3["Device 3<br/>lowest priority"]
  D1 -.->|"shared request line"| CPU
  D2 -.-> CPU
  D3 -.-> CPU

In a daisy chain the acknowledge signal stops at the first device with a pending request.

Daisy chains are cheap, but priorities are fixed by wiring and low-priority devices can starve. Alternatives are parallel priority (a priority encoder with one request line per device and a mask register to disable devices) and software polling, where the handler reads status registers one by one.

Python Daisy-chain priority

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The keyboard sits earlier in the chain than the disk and the network, so it is served first, even though all three asked at the same instant.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main feature of memory-mapped I/O?

    Memory-mapped I/O reserves part of the memory address space for device registers.
  2. 2. Why is a handshake more reliable than a simple strobe?

    Valid and accepted signals confirm both that data is on the bus and that it was taken.
  3. 3. In a daisy-chain interrupt system, which device has the highest priority?

    The acknowledge signal reaches the nearest device first, and a requesting device blocks it.
  4. 4. Which is a drawback of the daisy chain?

    The order in the chain is physical, so a busy high-priority device can keep the others waiting.
  5. 5. What does an I/O interface provide besides address decoding?

    The interface buffers data, adapts formats and exposes registers the CPU can read and write.

Summary

  • An I/O interface decodes addresses, buffers data, converts formats and exposes status and control registers.
  • Isolated I/O has a separate port space and special instructions; memory-mapped I/O shares the memory space and uses ordinary loads and stores.
  • Asynchronous transfers use a strobe (one signal, no confirmation) or a handshake (valid and accepted signals, fully acknowledged).
  • A daisy chain passes the interrupt acknowledge from device to device; the nearest requester wins, so priority is set by wiring.
  • Parallel priority encoders with mask registers give more flexible priorities.

Continue with Buses and Interconnects.