PadhaikoAll subjects

Input/Output

Computer Organization and Architecture (ENCT 303)

Open in the Padhaiko app

7.1 External devices

External devices (peripherals) connect the computer's internal CPU/memory subsystem to the outside world. Rather than attaching directly to the system bus, peripherals attach through I/O modules because external devices vary enormously in data rate, word length, electrical signaling, and mechanical timing.

External devices fall into three functional categories:

  1. Human-Readable: Communicate with human users (monitors/displays, keyboards, mice, printers).
  2. Machine-Readable: Communicate with equipment or provide secondary storage (magnetic disks, SSDs, optical drives, sensors, actuators).
  3. Communication: Exchange data with remote devices over networks or serial links (Ethernet NICs, Wi-Fi adapters, modems).

Inside an external device, control logic receives commands from the I/O module, a buffer temporarily holds data words/bytes, and a transducer converts electrical signals to/from physical energy (magnetic flux, light, keystrokes).

7.2 I/O modules: Module function, module structure

An I/O module is the hardware interface between the internal system bus (CPU + memory) and one or more peripheral devices.

Major Functions of an I/O Module

  1. Control and Timing: Coordinates bus access and internal/external timing between high-speed CPU/memory buses and slower peripherals.
  2. Processor Communication: Decodes CPU commands, exchanges data over the data bus, reports device status (BUSY, READY, ERROR), and recognizes its assigned port/memory-mapped address.
  3. Device Communication: Sends commands, status queries, and data across the external interface cable/link to the peripheral.
  4. Data Buffering: Absorbs speed mismatches between bursts on the memory bus (GB/s) and peripheral streams (KB/s–MB/s).
  5. Error Detection: Detects mechanical/device errors (paper jam, bad sector) and transmission errors (parity, CRC) and flags them in the status register.

I/O Module Structure

An I/O module connects to the system bus via data, address, and control lines, containing:

7.3 Programmed I/O, I/O commands, I/O instructions, flowchart

In Programmed I/O, the CPU retains complete control over every byte or word transferred and busy-waits (polls) the I/O module's status register until the peripheral is ready.

I/O Commands

The CPU issues four types of commands to an I/O module:

  1. Control: Activates a peripheral and tells it what to do (e.g., rewind tape, seek disk head).
  2. Test: Queries the status register of the I/O module and peripheral (power on, ready, error).
  3. Read: Causes the I/O module to obtain data from the peripheral into its internal buffer so the CPU can read it.
  4. Write: Causes the I/O module to take a word from the data bus and transmit it to the peripheral.

I/O Instructions & Addressing Modes

Programmed I/O Read Flowchart (Polling Loop)Text
[CPU issues READ command to I/O Module]
                 |
                 v
+---> [CPU reads Status Register of I/O Module]
|                |
|        (Ready bit == 1?)
|         /            \
+--- NO -+              +-- YES --> [CPU reads Word from I/O Data Reg]
     (Error -> Handle)                        |
                                              v
                                    [CPU writes Word to Memory]
                                              |
                                     (More words left?)
                                      /              \
                                    YES               NO --> [Done]
                                     |
                           [Loop to Next Word]

Drawback: Because peripherals are thousands to millions of times slower than the CPU, the CPU wastes nearly of its cycles spinning in the status-polling loop.

7.4 Interrupt driven I/O, interrupt processing and flowchart

Interrupt-Driven I/O eliminates busy-waiting: the CPU issues a READ command to the I/O module and immediately switches to executing other programs. When the peripheral finishes preparing a word, the I/O module raises an Interrupt Request (INTR) signal to the CPU.

Interrupt-Driven I/O Read FlowText
CPU Main Execution                    I/O Module & Device
------------------                    -------------------
1. Issue READ command  ------------>  2. Device prepares 1 word
3. Switch to other task               4. Word latched in Data Reg
   (CPU does useful work)             5. Assert INTR line to CPU
                                             |
6. Finish current instruction <--------------+
7. Save PC & PSW on stack; send INTA
8. Jump to ISR -> Read word from I/O Data Reg -> Write to Memory
9. Decrement count; if more words, issue next READ; IRET to resume task

Interrupt Identification Methods

When multiple I/O modules share interrupt lines, the CPU identifies the source using:

  1. Multiple Interrupt Lines: Dedicated INTR pins (limited by CPU pin count).
  2. Software Poll: CPU polls each module's status register sequentially in the ISR (simple, slow for many devices).
  3. Daisy Chain (Hardware Poll): One shared INTR line and an Interrupt Acknowledge (INTA) line chained serially through modules in priority order; the highest-priority requesting module blocks INTA from passing downstream and places its vector on the bus.
  4. Bus Arbitration / Vectored Controller (PIC / APIC): An interrupt controller prioritizes requests and sends the winning device's interrupt vector directly to the CPU.

7.5 Direct memory access (DMA): Drawbacks of programmed and interrupt-driven I/O, DMA function, typical DMA block diagram and possible DMA configuration

Drawbacks of Programmed and Interrupt-Driven I/O

DMA Function and Block Diagram

A Direct Memory Access (DMA) controller is a specialized bus master module that transfers entire blocks of data directly between an I/O device and main memory without CPU intervention per word:

  1. The CPU initializes the DMA controller with:
    • Starting memory address (in the DMA Address Register)
    • Word/byte transfer count (in the Data Count Register)
    • Transfer direction (Read or Write in the Control Register)
    • Target I/O device
  2. The CPU resumes other work. When the peripheral has data ready, the DMA controller asserts Bus Request (BR / HOLD) to acquire the system bus; the CPU finishes its current bus cycle, puts its bus drivers into high impedance, and replies with Bus Grant (BG / HLDA).
  3. The DMA controller drives the address, data, and control buses directly (Memory <-> I/O), incrementing the address register and decrementing the count register after each word (via Burst Mode or Cycle Stealing).
  4. When the count reaches 0, the DMA controller releases the bus and asserts a single interrupt to notify the CPU that the entire block transfer is complete.

Possible DMA Configurations

  1. Single-Bus, Detached DMA: Both DMA and I/O modules sit on the shared system bus; transferring one word takes two bus cycles (I/O -> DMA, then DMA -> Memory).
  2. Single-Bus, Integrated DMA-I/O: DMA logic is integrated inside the I/O module (or shares a local path with one or more I/O devices), cutting system-bus usage to one cycle per word (Device -> Memory directly).
  3. Separate I/O Bus: An independent I/O bus connects all I/O modules directly to the DMA controller, keeping peripheral transfers completely off the main system bus except for the single DMA <-> Memory cycle.

7.6 I/O channels and processors: The evolution of the I/O function, characteristics of I/O channels

As computers scaled from simple microcontrollers to mainframes, I/O hardware evolved through five stages of increasing CPU offload:

  1. CPU directly controls peripherals (no I/O module).
  2. I/O controller added (Programmed I/O).
  3. Interrupts added (Interrupt-Driven I/O).
  4. DMA Controller takes over raw block transfers, interrupting CPU only once per block.
  5. I/O Channel / I/O Processor (IOP): An autonomous special-purpose processor with its own local instruction set tailored for I/O. The CPU builds a channel program (sequence of Channel Command Words) in main memory and instructs the IOP to execute it; the IOP manages multiple devices, error retries, scatter-gather transfers, and status reporting independently.

Types of I/O Channels

7.7 The external interface: Types of interfaces, point-to point and multiple configurations, small computer system interface (SCSI)

An external interface links an I/O module to external peripherals:

Small Computer System Interface (SCSI)

SCSI is an intelligent, high-speed peripheral interface standard originally designed as a parallel multipoint daisy-chained bus (connecting up to 7 or 15 devices plus a host adapter via unique SCSI IDs and resistive bus terminators), and later evolved into Serial Attached SCSI (SAS) point-to-point fabrics:

Worked Out Examples

Example 1

1 (6 marks)

A CPU transfers a (-byte) file from a disk in -byte chunks under Interrupt-Driven I/O versus DMA:

Compare the CPU overhead (in cycles and percentage of the disk transfer window) for Interrupt-Driven I/O vs. DMA! (Use , during which the CPU has clock cycles.)

Computing CPU cycles consumed by Interrupt-Driven I/O: One interrupt per byte across bytes at cycles per interrupt:

Since cycles exceeds the cycles available in ( CPU load!), the CPU cannot even keep up with a byte-by-byte interrupt rate!

Computing CPU cycles consumed by DMA:

Percentage of CPU capacity over the window ( cycles):

Answer:

Interrupt-Driven I/O demands CPU cycles (overloading of the CPU), whereas DMA consumes only cycles—just of CPU time over the transfer window.

Example 2

2 (5 marks)

A CPU operates at ( cycle) and runs a -cycle program while a DMA controller steals bus cycle every to transfer a block of words ( word per stolen cycle). Assuming each memory word takes stolen cycle from the CPU, calculate:

  1. Total CPU time added by DMA cycle stealing.
  2. Percentage slowdown experienced by the CPU program during the DMA transfer.

Counting stolen cycles for the -word transfer: Since word is transferred per stolen cycle, transferring words steals CPU cycles. At per cycle:

Calculating CPU percentage slowdown: During the transfer, the DMA steals cycle out of every CPU cycles, so the CPU slows down by:

Equivalently, stolen cycles occur across total elapsed cycles ().

Answer:
  1. DMA adds cycles () of bus wait to the CPU; 2. The CPU experiences only a slowdown during the transfer.
Example 3

3 (5 marks)

Explain why Memory-Mapped I/O and Isolated (Port-Mapped) I/O differ in instruction set, address decoding, and bus control signals, and write short comparison pseudocode/instructions showing how a CPU reads a status flag and data byte from a keyboard controller at address 0x60 (data) / 0x64 (status) under each scheme.

Comparing Memory-Mapped I/O and Isolated I/O:

  • Memory-Mapped I/O: I/O registers share the main memory address space; CPU uses ordinary memory instructions (LOAD, STORE) and standard MEMR/MEMW signals. Full addressing modes and ALU-memory instructions work directly on I/O, at the cost of consuming part of the physical address space.
  • Isolated I/O: Dedicated IN/OUT instructions and separate IOR/IOW control lines keep the entire memory address space free for RAM/ROM, while restricting I/O transfers to accumulator/register IN/OUT opcodes.

Illustrating status polling + read under both schemes:

Memory-Mapped I/O vs. Isolated I/O PollingText
; Memory-Mapped I/O (Status at 0xFF64, Data at 0xFF60)
WAIT_MM: LOAD  R1, [0xFF64]   ; read status via normal memory read
         AND   R1, #0x01      ; test bit 0 (Data Ready)
         JZ    WAIT_MM
         LOAD  R2, [0xFF60]   ; read keyboard byte

; Isolated I/O (Status port 0x64, Data port 0x60)
WAIT_IO: IN    AL, 0x64       ; read I/O port using IOR# line
         TEST  AL, 0x01
         JZ    WAIT_IO
         IN    AL, 0x60       ; read keyboard byte
Answer:

Memory-mapped I/O uses standard memory instructions and control lines within a unified address space, whereas isolated I/O uses dedicated IN/OUT instructions and separate IOR/IOW lines in an independent I/O port space.

Exercises

Exercise — Input/Output

Question 1

Why are external devices not connected directly to the CPU system bus? List the five main functions of an I/O module and sketch its internal structural blocks.

Explaining why an I/O module is necessary:

  1. Peripherals operate at vastly slower, diverse data rates compared to the CPU and RAM.
  2. Peripherals use different word formats, voltage levels, and mechanical timing than the system bus.
  3. Connecting hundreds of heterogeneous devices directly to CPU control lines would overload the CPU and instruction set.

Listing the five I/O module functions and structure:

  • Functions: (1) Control and timing, (2) Processor communication (command decode, data, status, address recognition), (3) Device communication, (4) Data buffering, and (5) Error detection.
  • Structure: System bus interface Data Registers + Status/Control Registers + I/O Logic External Device Interface Logic connected to external peripherals.
Answer:

I/O modules bridge speed, format, and electrical differences between peripherals and the system bus by providing control/timing, CPU communication, device communication, buffering, and error detection via data, status/control, and interface logic blocks.

Question 2

Compare Programmed I/O, Interrupt-Driven I/O, and Direct Memory Access (DMA) across CPU wait behavior, data path, interrupt frequency, and best application domain.

Comparing the three I/O transfer mechanisms:

Programmed I/O vs. Interrupt-Driven I/O vs. DMA
CriterionProgrammed I/OInterrupt-Driven I/ODMA
CPU Wait StateBusy-waits polling status flagExecutes other tasks until interruptedExecutes other tasks; interrupted once per block
Data Path directly
InterruptsNone interrupt per word/byte interrupt per entire block
Best Use CaseSimple microcontrollers / ultra-fast portsLow-rate devices (keyboard, mouse, UART)High-speed bulk transfers (HDD, SSD, NIC)
Answer:

Programmed I/O polls in the CPU, interrupt-driven I/O eliminates polling but still interrupts per word through the CPU, and DMA transfers whole blocks directly between device and memory with only one completion interrupt.

Question 3

Describe how a DMA controller acquires the system bus using HOLD/HLDA (BR/BG), contrast Burst Mode with Cycle Stealing Mode, and name the three standard DMA bus configurations.

Explaining DMA bus arbitration and transfer modes:

  • Arbitration: DMA asserts Bus Request (BR/HOLD); CPU completes its current bus cycle, tri-states its address/data/control lines, and asserts Bus Grant (BG/HLDA). DMA then drives memory read/write cycles directly until Data Count == 0.
  • Burst Mode: DMA holds the bus continuously until the entire block finishes—maximizing I/O speed while temporarily stalling CPU memory access.
  • Cycle Stealing Mode: DMA steals one bus cycle at a time to transfer one word and immediately returns the bus to the CPU—slowing CPU execution minimally.

Listing the three DMA configurations:

  1. Single-bus, detached DMA (2 bus cycles per word).
  2. Single-bus, integrated DMA-I/O module (1 bus cycle per word).
  3. Separate I/O bus connecting peripherals to the DMA controller (1 system-bus cycle per word).
Answer:

DMA uses BR/BG (HOLD/HLDA) handshaking to master the bus either in continuous Burst Mode or interleaved Cycle Stealing Mode, across detached single-bus, integrated single-bus, or separate I/O-bus topologies.

Question 4

A CPU initiates a DMA transfer of a (-byte) block over a -bit (-byte) memory bus. Suppose DMA setup and completion ISR together take CPU cycles, and the disk delivers data at (), stealing CPU cycle per -byte word. How many CPU cycles are consumed by DMA, and what percentage of CPU cycles during the transfer window are spent on I/O?

Computing transfer window duration and available CPU cycles:

  • Transfer window ().
  • Total CPU cycles in : .

Computing DMA CPU overhead:

  • Number of -byte words .
  • Total CPU cycles used .
  • Percentage of CPU time .
Answer:

DMA consumes CPU cycles ( setup/ISR stolen), representing only of the CPU cycles during the transfer window.

Question 5

Trace the evolution of the I/O function up to I/O Channels / I/O Processors (IOPs), distinguish between a selector channel and a multiplexor channel, and explain the key characteristics of SCSI (including disconnect/reconnect and serial SAS evolution).

Tracing I/O evolution and channel types: I/O evolved from direct CPU polling I/O module (Programmed I/O) Interrupt-Driven I/O DMA controller I/O Channel / IOP (a dedicated processor executing memory-resident channel programs independently):

  • Selector Channel: Dedicates itself to one high-speed device (disk/tape) at a time for an entire block transfer.
  • Multiplexor Channel: Interleaves bytes or blocks concurrently across multiple slow/medium-speed devices.

Summarizing SCSI characteristics:

  • Peer-to-peer multipoint bus supporting multiple initiators and targets identified by unique SCSI IDs (or point-to-point lanes in Serial Attached SCSI, SAS).
  • Uses standardized Command Descriptor Blocks (CDBs) and allows a target device to disconnect from the bus during slow mechanical seeks and reconnect when data is ready, freeing the bus for other devices.
Answer:

I/O progressed from CPU-controlled polling through interrupts and DMA to programmable I/O channels (selector for single high-speed streams; multiplexor for interleaved devices). SCSI supports peer-to-peer arbitration, standardized CDB commands, disconnect/reconnect during seeks, and evolved into point-to-point serial SAS.

← Pipelining and Vector ProcessingMultiprocessor System →