Sub topic 2
Memory-Mapped and Isolated I/O
This chapter assumes you know the CPU, registers, memory, buses, instruction cycles, binary and hexadecimal numbers, and stack-based subroutine calls. You should also know that an address bus selects a location and that control signals identify operations such as reading and writing.
The role of I/O addressing
A peripheral device, such as a keyboard controller or disk controller, cannot usually connect directly to the CPU’s internal registers. An I/O interface module connects the device to the system bus. It contains registers that the CPU can access:
- A data register holds bytes or words being transferred.
- A status register reports conditions such as ready, busy, or error.
- A control register accepts commands such as reset, enable, or start.
The CPU must select the correct register before performing a read or write. I/O addressing is the method used to distinguish device registers from ordinary main memory.
Two common methods are memory-mapped I/O and isolated I/O, also called port-mapped I/O.
Memory-mapped I/O
In memory-mapped I/O, device registers share the same address space as main memory. A particular address may identify a RAM location, while another address identifies a device register.
For example, suppose a device uses these addresses:
| Address | Meaning |
|---|---|
| `0x4000` | Device status register |
| `0x4001` | Device data register |
| `0x4002` | Device control register |
The CPU accesses these registers with ordinary memory instructions. A load instruction can read the status or data register, and a store instruction can write the control register.
The address decoder in the interface examines the address on the bus. If the address is 0x4001, the decoder selects the device data register instead of RAM. The interface also checks whether the operation is a read or write.
Memory-mapped I/O makes device access look like normal memory access. Existing load and store instructions can be used, and high-level languages can often access registers through pointers.
However, device registers are not ordinary memory. Reading a register may clear a status bit or remove a byte from a hardware buffer. Writing may start an operation immediately. Programs must also declare such locations as volatile when using C or a similar language. This prevents the compiler from incorrectly removing or reordering accesses that hardware can change independently.
Memory-mapped I/O consumes part of the memory address space. On a processor with a limited address width, assigning many addresses to devices leaves fewer addresses available for RAM. Modern systems usually use address decoding and larger address spaces to reduce this concern.
Isolated I/O
In isolated I/O, the CPU has a separate address space for device registers. Memory addresses and I/O port addresses may have the same numeric value without conflicting because the bus identifies which address space is being used.
A processor may provide special instructions such as IN and OUT:
INcopies data from an I/O port into a CPU register.OUTcopies data from a CPU register to an I/O port.
The CPU also generates distinct control signals for I/O reads and writes. The interface responds only when the I/O control signal is active.
Isolated I/O does not consume ordinary memory addresses. It can also make the distinction between memory and devices explicit in assembly code. Its limitation is that programs need special I/O instructions, and those instructions may be less flexible than general memory instructions.
Comparing the two methods
| Property | Memory-mapped I/O | Isolated I/O |
|---|---|---|
| Address space | Shared with memory | Separate I/O address space |
| Instructions | Ordinary load and store | Special input and output instructions |
| Effect on memory range | Uses part of memory address space | Does not use memory addresses |
| Addressing flexibility | Usually broad and uniform | Limited by port-address size and instruction set |
| Common concern | Device access must be treated as volatile | Code is less uniform across processor types |
The choice is an architectural decision. Memory-mapped I/O simplifies the programming model and supports normal addressing modes. Isolated I/O preserves the full memory address space and clearly separates device operations.
> callout note > The address value alone does not identify a device in isolated I/O. The bus control signal must also indicate that the operation targets the I/O address space.
Worked reasoning pattern
When a problem gives an address and asks which component responds, use this sequence:
- Identify whether the system uses one shared address space or separate I/O ports.
- Check the address range assigned to memory and to the device.
- Examine the operation type: memory read, memory write, I/O read, or I/O write.
- Apply the interface’s address-decoding rule.
- Remember that a device register may have side effects when read or written.
For example, in a memory-mapped system, an address in the device range causes the I/O interface to respond even though the CPU executes an ordinary load instruction. In an isolated-I/O system, the same numeric address may select RAM during a memory read but select a device during an I/O read.
Exercise
A processor uses memory-mapped I/O. RAM occupies addresses 0x0000–0x3FFF, and a device data register occupies address 0x4001. Which component responds when the CPU performs a load from 0x4001?
Show answer
The I/O interface responds because 0x4001 lies in the device’s memory-mapped range. The CPU uses an ordinary memory-load instruction, but address decoding routes the operation to the device data register.