Input/output is how the CPU exchanges data with slow, varied peripherals. This topic covers I/O interfaces and ports, isolated versus memory-mapped addressing, programmed, interrupt-driven and DMA transfer, interrupt priority schemes, I/O channels, and strobe, handshake and serial timing.
High-yield 70 minSyllabus: “Processor input/output and DMA”
Mark as
The idea in one minute
Picture a busy chef (the CPU) and deliveries arriving at the back door (the devices). He could keep walking to the door to check (programmed I/O, or polling). He could fit a doorbell and cook until it rings (interrupt-driven I/O). Or he could hire a porter who carries the whole truckload into the store-room and only says “done” at the end (DMA). The receiving counter that checks and translates every delivery is the I/O interface.
Key points — the night-before list
An I/O interface matches speed, data format and signal levels between CPU and device; it holds data, status and control registers selected by address decoding.
Isolated (I/O-mapped) I/O: separate port space, IN/OUT instructions, IOR̅/IOW̅ lines. Memory-mapped I/O: devices take memory addresses, any memory instruction works, less memory left.
Programmed I/O busy-waits on a status flag — simple but wasteful. Interrupt-driven I/O lets the device signal readiness; the ISR still moves every word.
Vectored interrupt: the device supplies its vector, identifying itself. Software polling is the simplest priority scheme; daisy chaining fixes priority by position on the acknowledge chain.
A DMA controller has address, word-count and control registers. The CPU programs them; the DMAC borrows the bus (BR/HOLD → BG/HLDA) and interrupts when the count reaches zero.
Burst mode moves a whole block at once; cycle stealing takes one bus cycle per word; transparent mode uses only bus cycles the CPU leaves idle.
A DMA request is granted at the end of a bus (machine) cycle; an interrupt is recognised only at the end of an instruction.
Strobe control uses one line; handshaking adds a reply line (data valid / data accepted). Asynchronous serial frames each character with a start bit and stop bit(s).
01Why the CPU needs an I/O interface
Input/output (I/O) is every exchange between the computer and the outside world: keyboards and sensors (input), displays and printers (output), disks and network cards (both). The devices themselves are called peripherals. They cannot simply be wired onto the CPU's bus, for four reasons that every textbook lists:
Speed mismatch — a keyboard produces a few characters per second, a disk or network card millions of bytes per second, and the CPU works in nanoseconds. Somebody must synchronise them.
Different data formats — devices may be serial or parallel, use their own codes, and transfer bits, bytes or whole blocks.
Different signals — many peripherals are electromechanical or magnetic and need voltage levels and timing that the CPU does not produce.
Different operating modes, many devices — each device must be selected, controlled and monitored without disturbing the others.
The answer is an I/O interface — also called an I/O module, controller or adapter — between the system bus and each device. Toward the CPU it looks like a few addressable registers; toward the device it speaks the device's own language. Each addressable register is an I/O port.
Register (port)
Direction
Purpose
Data register (buffer)
In and out
Holds the byte or word in transit; buffering absorbs the speed difference
Status register
Read by the CPU
Flags such as ready/busy, data available, error (parity, overrun)
Inside the interface an address decoder compares the address on the bus with the interface's own address and enables it (chip select); register-select lines then pick one register. The interface also provides control and timing, data buffering, error detection and device communication. The CPU issues four kinds of I/O command: control (activate the device and tell it what to do), status (test its condition), data output and data input.
Three registers: D-S-C
Data to move, Status to read, Control to write. Almost every interface chip — the 8255, 8251, a disk controller — is some arrangement of these three.
02Addressing I/O: isolated versus memory-mapped
The CPU reaches a port by putting its address on the address bus — but which address space does that number belong to? In isolated I/O (also called I/O-mapped or port-mapped I/O) ports have their own address space, reached by special instructions (IN, OUT) and separate control lines (IOR̅ and IOW̅, or a single M/IO̅ pin). In memory-mapped I/O a block of ordinary memory addresses is handed to device registers, and the normal memory instructions and read/write signals are used.
Isolated (I/O-mapped) I/O
Separate address spaces for memory and I/O
Dedicated IN/OUT instructions; only they reach the ports
IOR̅/IOW̅ (or M/IO̅) tell memory to ignore I/O cycles
The whole memory address space stays available for memory
Short port addresses (8 or 16 bits), simpler decoding
Examples: Intel 8085 (256 ports), 8086 and x86 (64K ports)
Memory-mapped I/O
One common address space shared by memory and I/O
Any memory instruction (MOV, ADD, AND, TEST…) can work on a device register
Same MEMR̅/MEMW̅ signals; no extra control lines
Device addresses reduce the space left for memory
Full-width address decoding for every port
Examples: Motorola 68000, ARM and most RISC processors; video RAM on a PC
Memory-mapped I/O gives programmers more power: a device register can be incremented or bit-tested in one instruction, and the OS can protect devices with the same memory-protection hardware it uses for RAM. Isolated I/O keeps devices out of the memory map and makes I/O instructions easy to spot. Either way, device registers must never be cached, because a status bit can change on its own.
Bus organisation
How memory and I/O share the wires
Separate buses
Memory and I/O have independent address, data and control buses; an I/O processor runs the I/O bus
Common bus, separate control lines
Address and data lines are shared, but memory and I/O have their own read/write lines — this is isolated I/O
Common bus, common control lines
Everything is shared and the address alone decides — this is memory-mapped I/O
KPSC wording
Keyed as TRUE: "In I/O-mapped I/O, dedicated I/O instructions are used to access I/O devices." Common false options: memory-mapped I/O uses separate address spaces (it uses one), and the interrupt mechanism repeatedly checks device status (that is polling).
03Three ways to move data — starting with programmed I/O
Once a port can be addressed, the real question is who moves the data, and who decides when. There are three modes of transfer, from the simplest to the most efficient.
Mode
Who moves each word
How the CPU learns the device is ready
CPU cost
Programmed I/O
The CPU, by executing I/O instructions
It keeps reading the status register (polling, busy-wait)
Very high — the CPU is tied up for the whole transfer
Interrupt-driven I/O
The CPU, inside the interrupt service routine
The device raises an interrupt request
Moderate — useful work between words, but ISR overhead per word
DMA
A DMA controller, directly between device and memory
The device raises a DMA request; the CPU hears one interrupt per block
Low — the CPU only loses some bus cycles
Programmed input of a block (busy-wait loop)
Issue the command
The CPU writes a read command into the interface's control register.
Read the status register
It reads the status port and tests the ready flag.
Not ready? Loop
If the flag is 0 it goes back to the previous step — this is the wasteful busy-wait.
Transfer the word
When the flag is 1 the CPU reads the data register into a CPU register and stores it in memory.
Update and repeat
It advances the memory address, decrements the count, and repeats until the block is complete.
8086 assemblyEvery byte costs a status test loop that may run thousands of times
; Programmed input of COUNT bytes into BUFFER (8086 syntax)
LEA DI, BUFFER
MOV CX, COUNT
POLL: IN AL, STATUS ; read the status port
TEST AL, 01H ; bit 0 = data ready?
JZ POLL ; no: keep busy-waiting
IN AL, DATA ; yes: read the data port
MOV [DI], AL ; store the byte in memory
INC DI
LOOP POLL ; next byte until CX = 0
Why it wastes time. Suppose one pass of the test loop takes 1 µs and the device delivers 100 bytes per second — one byte every 10,000 µs. The CPU checks the flag about 10,000 times for every byte it moves, so more than 99.9% of its time is spent waiting. Programmed I/O suits very fast devices or tiny embedded systems that have nothing else to do; for slow devices it is hopeless.
Classification varies
Microprocessor books often list three programmed data transfer schemes — synchronous, asynchronous (handshake) and interrupt-driven — because a program (the ISR) still moves each byte, and treat DMA separately. Either way, DMA is the only scheme in which the CPU does not move the data itself.
04Interrupt-driven I/O and the interrupt cycle
In interrupt-driven I/O the CPU issues a command and returns to useful work. When the interface is ready it raises an interrupt request. The CPU finishes its current instruction, saves where it was, runs the device's interrupt service routine (ISR) and returns. No time is lost polling — but every word still passes through the CPU, and every word costs an ISR entry and exit.
Handling one interrupt
Request
The device, through its interface, asserts the interrupt request line.
Recognise
At the end of the current instruction the CPU checks the line; if interrupts are enabled (an IEN or IF flag) it accepts the request.
Save the context
The return address (PC) and the status word (PSW or flags) are saved, usually on the stack, and further interrupts are disabled.
Find the routine
The CPU loads the ISR's address — either fixed (non-vectored) or supplied by the device (vectored).
Service
The ISR saves the registers it uses, transfers the data, clears the device's request and restores the registers.
Return
A return-from-interrupt instruction restores the PSW and PC, and the interrupted program resumes.
During the instruction cycle (Mano's basic computer):
T0'T1'T2' (IEN) (FGI + FGO): R ← 1 ; a device flag is up
Interrupt cycle, entered instead of the next fetch when R = 1:
RT0: AR ← 0, TR ← PC ; location 0 will hold the return address
RT1: M[AR] ← TR, PC ← 0 ; save the old PC in location 0
RT2: PC ← PC + 1, IEN ← 0, R ← 0, SC ← 0 ; continue at location 1, interrupts off
The interrupt cycle is a hardware subroutine call: save PC, disable interrupts, branch to the handler
Kind
Source
Examples
External (hardware)
Devices, through interrupt pins
Keyboard, timer tick, disk transfer done, power failure
Internal (traps, exceptions)
The CPU itself, caused by the running instruction
Divide by zero, overflow, invalid opcode, page fault, protection violation
Software
An instruction that deliberately requests an interrupt
INT n, supervisor call (system call), breakpoint
Maskable interrupt
Can be disabled by clearing an enable flag (CLI, IF = 0) or masked individually
Used by ordinary devices
8086 INTR; 8085 RST 7.5, 6.5, 5.5 and INTR
Non-maskable interrupt
Cannot be disabled by software
Reserved for emergencies that need immediate attention
A processor checks for interrupts at the end of each instruction, before fetching the next. KPSC has keyed "interrupt signalled" as the stage that switches the CPU from the user program to interrupt processing, and "unless enabled, the CPU won't process an interrupt" as true for maskable interrupts.
05Many devices: polling, vectored interrupts, daisy chain and parallel priority
With several devices sharing interrupt hardware the CPU must answer two questions: who interrupted? and who goes first when two ask at once? A priority interrupt system answers both. Software polling is the simplest: all requests share one line and one common ISR address, and the ISR tests each device's flag in turn. The first device tested has the highest priority, and the order can be changed just by re-ordering the tests. It needs no extra hardware and is the easiest to implement, but with many devices the polling time becomes long.
Vectored versus non-vectored. In a non-vectored interrupt the branch address is fixed in memory, so software must discover the source (by polling). In a vectored interrupt the interrupting device identifies itself by placing an interrupt vector — an address or a type number — on the data bus during the acknowledge cycle, and the CPU jumps straight to that device's ISR. Hardware priority schemes are normally vectored.
Daisy chaining is serial hardware priority. All devices drive one shared interrupt-request line, but the CPU's interrupt acknowledge passes through the devices one after another. Each device has a priority-in (PI) and a priority-out (PO) terminal. A device with no pending request passes the acknowledge on; a requesting device that receives PI = 1 blocks it (PO = 0) and puts its vector address (VAD) on the bus. Priority is fixed by position — the device nearest the CPU always wins — so the scheme is cheap but inflexible, and a far device can starve.
PI
Request flag
PO
VAD enabled
Meaning
0
0
0
No
Acknowledge already taken upstream
0
1
0
No
Requesting, but blocked by a higher-priority device; waits its turn
1
0
1
No
Not requesting: pass the acknowledge to the next device
1
1
0
Yes
Winner: block the devices downstream and place its vector on the bus
One stage of a daisy chain
Parallel priority uses hardware in one place. Each device sets its own bit in an interrupt register; a program-loadable mask register can disable any bit; the unmasked requests feed a priority encoder, whose output forms the vector address of the highest-priority device. An interrupt-status flip-flop and the global enable (IEN) complete the logic. The 8259 PIC (see the 8086 page) is this circuit on a chip. If an ISR re-enables interrupts, a higher-priority device may interrupt it — interrupt nesting.
Two keyed answers
"The device requesting service identifies itself to the processor" → vectored interrupt. "When handling interrupts from multiple devices, the method that is easy to implement" → polling.
06Direct memory access (DMA)
Even interrupt-driven I/O pushes every word through the CPU, costing tens of instructions per word. For block devices such as disks and network cards, direct memory access (DMA) takes the CPU out of the data path: a DMA controller (DMAC) borrows the system bus and moves the block directly between the device and memory, at memory speed. The CPU only sets up the transfer and takes one interrupt at the end.
DMAC register or signal
Role
Address register
Memory address of the next word; incremented (or decremented) after each transfer
Word-count register
Words still to move; decremented after each transfer — zero ends the block
Control (mode) register
Direction (device → memory is a write, memory → device a read), transfer mode, enables
DREQ / DACK
The device requests service / the DMAC acknowledges the device
BR (HOLD) / BG (HLDA)
The DMAC asks for the buses / the CPU grants them
Interrupt (TC, EOP)
Terminal count or end of process: tells the CPU the block is complete
A DMA block transfer
CPU programs the DMAC
It writes the starting memory address, the word count and the direction and mode, starts the device, and returns to other work.
Device requests
When the device has a word ready (or can accept one) it asserts DREQ.
Bus request
The DMAC asserts BR (HOLD) to the CPU.
Bus grant
The CPU finishes its current bus cycle, puts its address, data and control lines in the high-impedance state and asserts BG (HLDA).
Transfer
The DMAC drives the address, sends DACK to the device and activates the read/write strobes; the word moves between device and memory without entering the CPU.
Update
Address ± 1 and word count − 1. In burst mode the DMAC keeps the bus; in cycle stealing it releases the bus after each word and repeats from the device request.
Finish
When the count reaches zero (terminal count) the DMAC drops BR and interrupts the CPU, which checks the status in a short ISR.
DMA mode
Bus use
Effect on the CPU
Suits
Burst (block)
The DMAC keeps the bus until the whole block (or burst) has moved
Held off the bus for the entire burst
Fast devices with buffers, e.g. disk block reads
Cycle stealing
The DMAC takes the bus for one word, then hands it back — it steals one bus cycle at a time
Suspended for one bus cycle per word; slowed slightly
Devices slower than memory, steady streams
Transparent (hidden)
The DMAC uses only cycles in which the CPU does not need the bus
No slowdown at all
Systems where CPU speed must not suffer; slowest transfers, extra logic
Note the breakpoints. A DMA request can be granted at the end of any bus (machine) cycle — even in the middle of an instruction — because the CPU only has to let go of the bus. An interrupt is recognised only at the end of an instruction, because the CPU must save its context. Also, a simple DMAC on a single bus moves each word across the bus twice (device → DMAC → memory), whereas fly-by controllers such as the 8237 do a device-to-memory transfer in one cycle.
Interrupt-driven I/O
One interrupt per word (or per small buffer)
The CPU runs the ISR that moves the data
Context saved and restored for every word
Suits slow character devices: keyboard, mouse, serial line
DMA
One interrupt per block
The DMAC moves the data; the CPU only programs it
The CPU loses only the stolen bus cycles
Suits fast block devices: disk, network card, sound card
PSC keys on DMA
"The DMA module forces the processor to suspend operations temporarily to take control of the bus" → cycle stealing. "An entire block transferred in one contiguous sequence" → burst mode. For "huge amounts of data" → DMA. "In cycle-stealing mode a complete block is transferred without interruption" → false.
07I/O channels and I/O processors
Large systems go one step further. An I/O processor (IOP), called a channel on IBM mainframes, is a processor dedicated to I/O. It fetches and executes its own channel program — a list of I/O commands stored in main memory — so the CPU merely says "start I/O with this program" and is interrupted when the whole job, possibly many blocks on several devices, is finished. A DMAC carries out one programmed block; an IOP follows a whole program and handles errors and format conversion itself.
Stage
How I/O is handled
1
The CPU directly controls each device
2
A controller or I/O module is added; the CPU uses programmed I/O
3
Interrupts are added, so the CPU no longer busy-waits
4
DMA: blocks move between device and memory without the CPU
5
I/O channel: the module becomes a processor with its own I/O instruction set
6
I/O processor with local memory: effectively a computer in its own right
The evolution of the I/O function (after Stallings)
Selector channel
Controls several high-speed devices but serves only one at a time
Dedicates itself to that device for the whole transfer
Typical devices: disks, magnetic tapes
Multiplexer channel
Serves many devices at once by interleaving their transfers
Byte multiplexer: interleaves single bytes from slow devices (terminals, printers, card readers)
Block multiplexer: interleaves whole blocks from several fast devices (IBM System/370)
CPU and IOP communicate through memory: the CPU prepares a command block and issues a start-I/O instruction; the IOP reports back through a status word and an interrupt. In today's PCs the idea lives on in intelligent controllers — disk controllers, network cards and GPUs that carry their own processors.
Memory aid
Selector = single device at a time (both start with S). Multiplexer = many devices interleaved.
08Timing the transfer: strobe, handshaking and serial links
Two units driven by the same clock can transfer synchronously: data is simply valid at agreed clock edges. Most CPU–device pairs run on independent clocks, so the transfer is asynchronous and needs control signals that say when data is valid and when it has been taken. Strobe control uses a single line. With a source-initiated strobe the source places the data and then pulses the strobe, and the destination latches it on that pulse; with a destination-initiated strobe the destination pulses the strobe to ask for data. The weakness: with one line, the source never learns whether the data actually arrived.
Source-initiated handshake (two lines: data valid and data accepted)
Data valid ↑
The source puts the data on the bus and raises data valid.
Data accepted ↑
The destination reads the data and raises data accepted.
Data valid ↓
Seeing the acceptance, the source removes the data and drops data valid.
Data accepted ↓
The destination drops data accepted; both lines are back to rest and the next word can begin.
In the destination-initiated version the destination starts by raising ready for data; the source answers with the data and data valid, and the two signals are withdrawn in the same interlocked way. Because every step waits for a reply, handshaking adapts to any speed and allows a timeout: if the reply does not arrive in time, the unit reports an error.
Parallel transfer
n bits move at once on n lines, plus control lines
Fast over short distances
Bulky cables; skew between lines limits the length
Examples: system buses, Centronics printer port, 8255 ports
Serial transfer
One bit at a time on a single line (or pair)
Cheap, works over long distances and networks
Needs serial–parallel conversion by shift registers or a UART
Examples: RS-232, USB, SATA, Ethernet
Asynchronous serial frame (the line idles at 1)
idle 1 | start 0 | d0 d1 d2 d3 d4 d5 d6 d7 | parity | stop 1 (1, 1½ or 2 bits) | idle 1
bits per frame = 1 start + data bits + parity bit (if used) + stop bits
characters / s = baud rate ÷ bits per frame (baud = bits/s for two-level signals)
efficiency = data bits ÷ bits per frame
Example: 1200 baud, 1 start + 8 data + 1 stop = 10 bits → 120 characters/s, 80% efficient
Framing costs bits: count start, parity and stop bits in every character
The receiver relies on simple rules: the idle line is 1; a falling edge marks the start bit (always 0); the data bits follow, least significant first; the line then returns to 1 for at least one stop bit. A UART — or a USART such as the 8251 on the 8086 page — does the framing in hardware. Synchronous serial transfer sends long blocks behind sync characters with no start or stop bits per character, so it is more efficient, but both ends must stay clock-locked.
Step through · DMA block transfer: disk to memory
step 1 / 11
Step 1: Program address, count, direction
The CPU writes the starting memory address, the word count and 'device → memory' into the DMAC registers, starts the disk, then resumes its own program.
Worked examples
Try the problem first, then reveal the working one step at a time.
EX 1Serial link throughput (classic PSC numerical)
A 7200-baud asynchronous link frames each character with 1 start bit, 8 data bits, 1 parity bit and 2 stop bits. (a) How many characters can it carry per second? (b) What fraction of the line rate is useful data? (c) How long does a 3,000-character message take? (d) How many characters per second would a synchronous link of the same bit rate carry, ignoring sync characters?
EX 2CPU load: interrupt-driven I/O versus DMA
A device delivers 40,000 bytes per second to a CPU running 10 million instructions per second (10 MIPS). (a) With interrupt-driven I/O, each byte costs an ISR of 50 instructions. (b) With DMA the data moves in 4,000-byte blocks, and each block costs 2,000 instructions (programming the DMAC plus the completion ISR). What fraction of the CPU does each method consume?
EX 3Cycle stealing versus burst mode
A DMA controller serves a device producing 2,000,000 bytes per second over a 16-bit bus, so each transfer moves 2 bytes; one bus cycle takes 50 ns. (a) In cycle-stealing mode, what fraction of bus time is stolen? (b) For a 64 KB block (65,536 bytes), how long is the bus actually busy, and how long does the transfer take? (c) What changes in burst mode if the device already holds the whole block in its buffer?
EX 4Tracing a daisy chain
Three devices are daisy-chained: D1 nearest the CPU, then D2, then D3. D2 and D3 raise interrupt requests at the same moment while D1 is idle. Trace the acknowledge signal and say who is served first and what happens next.
Practice session
Work each problem on paper first, then check. Marking one solved earns 10 XP.0/5 solved
Q1
A CPU executes 2 million instructions per second. A printer accepts 500 characters per second under programmed I/O. Each status check takes 3 instructions and the transfer of a character takes 5. (a) How many status checks does the CPU make per character? (b) What percentage of CPU time is useful transfer work?
Q2
A processor with 16-bit addresses uses memory-mapped I/O and reserves F000H–FFFFH for device registers. (a) How many I/O register addresses are available? (b) How much memory remains? (c) What would change with isolated I/O using 8-bit port numbers?
Q3
A disk must send 512 words into memory starting at word address 3000H using DMA. (a) What does the CPU write into the DMA controller before the transfer? (b) What does the DMAC do after each word and at the end? (c) Which address receives the last word?
Q4
How long does it take to send a 1,200-character file over a 9600-baud asynchronous line using 1 start bit, 7 data bits, 1 parity bit and 1 stop bit? How much longer does it take with 2 stop bits?
Q5
A parallel-priority interrupt unit serves four devices I3–I0, with I0 the highest priority. The interrupt register holds 1110 (bits I3 I2 I1 I0) and the mask register holds 1101. (a) Which device is serviced, and what 2-bit code does the priority encoder output? (b) What changes if the mask register is 1111?
Exam traps
'Vectored' has two meanings. In COA books (Mano, Hamacher) and KPSC keys, a vectored interrupt is one where the device supplies the vector and identifies itself, while non-vectored means a fixed address. 8085 books instead call TRAP and RST 7.5/6.5/5.5 'vectored' because they jump to fixed addresses, and INTR 'non-vectored'.
A DMA request is honoured at the end of a bus (machine) cycle, even in the middle of an instruction; interrupts wait for the instruction to finish. 'DMA waits for the current instruction to complete' is false.
Cycle stealing is not burst mode: cycle stealing returns the bus after every word, burst holds it for the whole block, and transparent DMA never slows the CPU. 'The DMA module forces the processor to suspend temporarily' → cycle stealing.
Memory-mapped I/O shares one address space (any memory instruction works, but memory space shrinks); isolated I/O keeps separate spaces and needs IN/OUT with IOR̅/IOW̅. Examiners often swap the two descriptions.
DMA does not run without the CPU: the CPU initialises the address, count and direction, and services the completion interrupt. 'The CPU is not involved at all' is false.
Baud equals bits per second only for two-level signalling. Characters per second = baud ÷ (start + data + parity + stop bits); forgetting the framing bits is the commonest numerical slip.
Quiz — KPSC style
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.