I/O-Mapped vs Memory-Mapped I/O
Two Ways to Talk to Peripherals
Open interactive version (quiz + challenge)Real-world analogy
Imagine your house has two types of doors. Memory-mapped I/O is like having peripheral devices (TV, fridge, washing machine) inside rooms along the same hallway as your bedrooms — same address system, same keys. I/O-mapped (isolated) I/O is like having a separate service entrance with its own numbering — the postman uses one door, the delivery guy uses another, and they never confuse each other.
What is it?
I/O-mapped (isolated) I/O uses separate IN/OUT instructions and a dedicated 64KB address space to access peripherals, signaled by M/IO=0. Memory-mapped I/O places device registers in the normal memory address space and uses standard MOV/ADD/CMP instructions, signaled by M/IO=1. The 8086 supports both methods, and most real systems use a combination of both.
Real-world relevance
Your PC still uses both methods today. When your OS reads the keyboard controller, it uses IN/OUT instructions (I/O-mapped). When your GPU driver writes pixels, it writes to memory-mapped video RAM. The PCI Express bus on modern computers is entirely memory-mapped — every PCIe device gets a range of physical addresses.
Key points
- Two Approaches to Device Communication — The CPU must read from and write to peripheral devices (keyboard, display, timer). There are two fundamental approaches: (1) treat devices as memory locations (memory-mapped), or (2) give devices their own separate address space (I/O-mapped / isolated I/O). The 8086 supports BOTH methods — it has a separate M/IO pin to distinguish them.
- I/O-Mapped (Isolated) I/O — IN and OUT — In isolated I/O, peripheral devices have their own address space (0000h-FFFFh for 8086, 64KB). Access uses special instructions: IN reads a port, OUT writes a port. The CPU asserts M/IO=0 to signal an I/O operation. This keeps the memory address space completely separate from I/O — devices cannot accidentally shadow RAM or ROM.
- Memory-Mapped I/O — MOV to Device — In memory-mapped I/O, device registers are assigned addresses within the normal memory space. You read/write them with ordinary MOV, ADD, or any memory instruction — no special I/O instructions needed. The CPU asserts M/IO=1 (same as a normal memory access). The downside: these addresses are 'stolen' from memory space, reducing available RAM/ROM capacity.
- The M/IO Signal — The 8086 M/IO pin tells external hardware whether the current bus cycle is a memory access (M/IO=1) or an I/O access (M/IO=0). Address decoders use this signal along with address lines to generate the correct chip select. For memory chips, CS requires M/IO=1. For I/O devices, CS requires M/IO=0. This one pin is what makes the two separate address spaces possible.
- Address Space Comparison — With I/O-mapped I/O, the 8086 has two separate spaces: 1MB for memory and 64KB for I/O. With memory-mapped I/O, there is only one 1MB space shared by both memory and devices. I/O-mapped preserves the full memory space but requires special instructions. Memory-mapped sacrifices some memory addresses but allows richer instruction use on device registers.
- Pros and Cons Summary — I/O-mapped: clear separation, smaller address (simpler decoding), faster for simple reads — but limited to IN/OUT/AL/AX only. Memory-mapped: use any instruction (MOV, ADD, AND, CMP), no special instructions needed — but uses up memory addresses and address decoding is more complex. Most real systems use BOTH: I/O-mapped for simple control ports, memory-mapped for large buffers (like video RAM).
- IBM PC Example: Both Methods in Action — The original IBM PC used both methods simultaneously. Simple devices like the keyboard controller (port 60h), timer (port 40h), and interrupt controller (port 20h) used I/O-mapped I/O with IN/OUT. The video display buffer (B8000h) and ROM BIOS (F0000h) used memory-mapped addresses. This hybrid approach gave the best of both worlds.
- Interfacing a Device to Both Spaces — When designing a system, you choose which I/O method to use for each device. For the 8255 PPI, you typically use I/O-mapped (ports 80h-83h). For video memory, memory-mapped (segment B800h). The address decoding circuitry must include M/IO in the chip select logic to prevent a memory access from accidentally activating an I/O device or vice versa.
Code example
; =============================================
; I/O-Mapped vs Memory-Mapped I/O Comparison
; =============================================
;
; === I/O-Mapped (Isolated) I/O ===
; Access a device at I/O port 60h:
;
IN AL, 60h ; read byte from port 60h
; M/IO = 0 (I/O cycle)
; address bus = 0060h
OR AL, 80h ; process in register
OUT 60h, AL ; write back to port 60h
;
; === Memory-Mapped I/O ===
; Access a device at memory address B8000h:
;
MOV AX, 0B800h
MOV ES, AX ; point ES to device
MOV AL, ES:[0] ; read from device
; M/IO = 1 (memory cycle)
; address bus = B8000h
OR ES:[0], 80h ; modify device register DIRECTLY
; (can't do this with I/O-mapped!)
;
; Key difference: I/O-mapped uses IN/OUT only
; Memory-mapped can use ANY memory instructionLine-by-line walkthrough
- 1. Title comment for the I/O comparison
- 2. Separator line
- 3. Blank line
- 4. Section header: I/O-Mapped (Isolated) I/O
- 5. Comment: accessing a device at I/O port 60h
- 6. Blank line
- 7. IN AL, 60h — special instruction reads one byte from port 60h into AL
- 8. Comment: M/IO pin goes LOW (0) telling hardware this is an I/O cycle
- 9. Comment: only the lower 16 address bits carry the port address
- 10. OR AL, 80h — manipulate the data in a register (set bit 7)
- 11. OUT 60h, AL — write the modified byte back to port 60h
- 12. Blank line
- 13. Section header: Memory-Mapped I/O
- 14. Comment: accessing a device at memory address B8000h
- 15. Blank line
- 16. Load segment value 0B800h into AX
- 17. Move AX into ES segment register (ES now points to B8000h)
- 18. Read a byte from ES:[0] which is physical address B8000h — the device register
- 19. Comment: M/IO pin goes HIGH (1) because this is a normal memory cycle
- 20. Comment: the full 20-bit address appears on the bus
- 21. OR ES:[0], 80h — directly modify the device register in place using OR instruction
- 22. Comment: this direct-modify trick is impossible with I/O-mapped I/O
- 23. Blank line
- 24. Summary: I/O-mapped is limited to IN/OUT instructions
- 25. Memory-mapped can leverage the entire instruction set on device registers
Spot the bug
; Read from I/O port 300h
;
IN AL, 300h ; read byte from port 300h
;
; Write to memory-mapped device at C0000h
;
MOV AX, 0C000h
MOV DS, AX
OUT [0], AL ; write to deviceNeed a hint?
Check the rules for IN instruction addressing and what instruction is used for memory-mapped I/O.
Show answer
Two bugs: (1) IN AL, 300h is invalid — direct port addressing only supports 8-bit addresses (0-FFh). For port 300h, use: MOV DX, 300h then IN AL, DX. (2) OUT [0], AL is wrong — OUT is for I/O ports only. For memory-mapped I/O, use MOV [0], AL (or MOV DS:[0], AL).
Explain like I'm 5
Imagine you live in a building with 100 apartments (that is your memory). I/O-mapped I/O is like having a separate little mailroom in the lobby with 10 mailboxes for sending packages to shops outside — you use a special 'send package' form (IN/OUT). Memory-mapped I/O is like giving one of the 100 apartments to a shop — now the shop has a door just like any apartment, and you visit it the same way you visit a neighbor (MOV). But now you only have 99 apartments left for people!
Fun fact
The Motorola 68000 processor (used in original Macintosh and Sega Genesis) had NO separate I/O space at all — everything was memory-mapped. Intel's x86 kept the separate I/O space for backward compatibility with the 8080, and it persists in x86-64 processors to this day, over 45 years later.
Hands-on challenge
Design address decoding for a system with: (1) 8KB RAM at 00000h-01FFFh (memory-mapped), (2) 8KB ROM at FE000h-FFFFFh (memory-mapped), and (3) an 8255 PPI at I/O ports 80h-83h (I/O-mapped). Show how M/IO is used in each chip select equation. Write sample code to read from all three.
More resources
- I/O Mapped vs Memory Mapped I/O (Neso Academy)
- Memory Mapped I/O and Isolated I/O (GeeksforGeeks)
- 8086 I/O Interfacing (Education 4u)
- x86 IN/OUT Instructions Reference (x86 Reference)