IO Interfacing
Memory mapped IO vs Peripheral mapped IO.
A microprocessor-based system must interact with the external world through input and output devices. IO interfacing is the technique of connecting peripheral devices to the 8086 so that the CPU can send data to or receive data from them. A fundamental design decision in any microprocessor system is whether to use memory mapped IO or peripheral mapped IO (also called isolated IO), and understanding the difference between these two approaches is important for both system design and competitive examinations.
Core Concept Explanation
When the 8086 executes an instruction that accesses memory, it asserts its M/IO (Memory/IO) control line HIGH. When it executes an IO instruction (IN or OUT), it asserts M/IO LOW. External hardware uses this signal to determine whether the current bus cycle is a memory access or an IO access. The address bus carries either a memory address (20-bit, using A19-A0) or an IO port address (16-bit, using A15-A0) depending on M/IO.
In memory mapped IO, the designer maps the IO device registers into the same address space as RAM and ROM. The device responds when a specific memory address is placed on the bus, just like a RAM chip would. The CPU uses standard memory access instructions like MOV to communicate with the device. There are no special IO instructions. The M/IO line stays HIGH during these accesses.
In peripheral mapped IO (also called isolated IO or port-mapped IO), the 8086 has a completely separate IO address space of 64 KB, addressed from 0000H to FFFFH. This space is accessed exclusively through the IN and OUT instructions. During these cycles, M/IO goes LOW, allowing the system to distinguish IO accesses from memory accesses and route them to the correct hardware.
IO Instructions in 8086
The 8086 provides two forms of IO instructions. In fixed port addressing, the port address is encoded as an 8-bit immediate value directly in the instruction. This allows access to ports 00H to FFH (256 ports). Example: IN AL, 40H reads a byte from port 40H. OUT 30H, AL sends the value in AL to port 30H.
In variable port addressing, the port address is loaded into register DX first, and then IN AL, DX or OUT DX, AL is used. This allows access to any port from 0000H to FFFFH (65536 ports). Variable port addressing is necessary when the port number is determined at runtime or when the port address exceeds 8 bits.
For 16-bit transfers, AX is used instead of AL: IN AX, DX reads a full 16-bit word from the port address in DX. This is useful when interfacing with 16-bit peripheral registers.
Mathematical Expression
In peripheral mapped IO, the IO address space is 16 bits wide: 2^16 = 65536 distinct IO port addresses (0000H to FFFFH). With fixed port addressing, only 8-bit immediate values are used, limiting access to 2^8 = 256 ports. The memory address space remains the full 2^20 = 1,048,576 bytes = 1 MB, completely separate from IO space.
In memory mapped IO, IO devices consume part of the 1 MB memory space. If an IO device uses 4 KB of address space, then only 1 MB minus 4 KB = 1044 KB remains available for actual memory. The more IO devices connected using memory mapping, the less memory space is available.
Practical Understanding
Memory mapped IO has a significant advantage: any instruction that can address memory can now be used to manipulate IO device registers. This means arithmetic and logical operations can be applied directly to device registers without first loading values into registers. This makes programming more flexible.
Peripheral mapped IO preserves the full 1 MB for memory, which is an important advantage in systems that need large programs or data storage. The use of IN/OUT instructions also makes programs easier to read because IO accesses are visually distinct from memory accesses. The 8086 uses peripheral mapped IO in most standard PC architectures.
Solved Example
An 8086 system uses peripheral mapped IO. An 8-bit input port is connected at IO address 50H. Write the instruction sequence to read the port and determine the effective address lines used for decoding.
Given:
IO port address = 50H = 0101 0000B
Port width = 8 bits (byte port)
IO addressing type = fixed port (address fits in 8 bits)
Why this formula applies:
For fixed port IO: IN AL, port uses 8-bit immediate port address.
M/IO = 0 during this bus cycle (IO access).
Only A15-A0 are driven on address bus; A19-A16 are don't cares.
Instruction:
IN AL, 50H
Address lines driven during this cycle:
A7-A0 = 0101 0000B (= 50H)
A15-A8 = 00000000B
A19-A16 = don't care (not used for IO decoding)
M/IO = 0 (identifies this as an IO cycle)
Decoding logic:
Port selected when A15-A0 = 0050H AND M/IO = 0
Decoder checks: A15 to A8 = 0 AND A7-A0 = 50H
Final Answer:
IN AL, 50H reads byte from IO port 50H.
Port decoder must check A7-A0 = 50H and M/IO = LOW.Exam Tip: A common GATE trap is assuming that memory mapped IO uses IN/OUT instructions. It does not — it uses MOV and other memory instructions. Only peripheral (isolated) IO uses IN and OUT. Also remember that IN/OUT can only use AL or AX as the data register, not other registers.
Mechanism Diagram
Key Differences Summary
- Memory mapped IO: device lives in memory address space (00000H-FFFFFH), uses MOV instructions, M/IO = 1.
- Peripheral mapped IO: device lives in IO address space (0000H-FFFFH), uses IN/OUT instructions, M/IO = 0.
- Fixed port IN/OUT uses 8-bit immediate port address: up to 256 ports directly accessible.
- Variable port IN/OUT uses DX register for 16-bit address: full 64 KB IO space accessible.
- Memory mapped IO allows all instruction types (arithmetic, logical) to operate on device registers directly.
- Peripheral mapped IO preserves full 1 MB memory space for actual memory chips.
Quick Revision
- 8086 has two address spaces: 1 MB memory space and 64 KB IO space. M/IO signal selects which one.
- Memory Mapped IO: device mapped into memory space. Uses standard memory instructions. M/IO = HIGH.
- Peripheral (Isolated) IO: separate IO address space. Uses IN/OUT instructions only. M/IO = LOW.
- Fixed port addressing: 8-bit port address in instruction (ports 00H-FFH). Variable: DX holds 16-bit address (0000H-FFFFH).
- IN and OUT instructions use only AL (byte) or AX (word) as the data register, never other registers.
- Advantage of memory mapped IO: flexible instruction set for device control. Advantage of isolated IO: full memory space preserved.
- Trap: IN/OUT cannot be used with memory mapped devices, and MOV cannot be used for IO in isolated IO mode.
IO Interfacing Quiz
Test your grasp of memory-mapped versus isolated IO schemes used in microprocessor systems.
Q1.Which of the following is a direct consequence of using memory-mapped IO in an 8086 system compared to isolated IO?
Related Articles
Keyboard Interfacing
Matrix keyboard scanning rows/cols.
7 min read
8237 DMA
Direct Memory Access controller operation.
8 min read
8251 USART
Universal Synchronous Asynchronous Receiver Transmitter.
11 min read
8253/54 Timer
Programmable Interval Timer, modes.
6 min read
Stepper Motor Interface
Driving coils sequence.
10 min read