Memory-Mapped I/O

A processor doesn't have special "turn on LED" or "read button" instructions. Instead, it treats peripherals as if they were just memory cells at specific addresses. This elegant trick is called memory-mapped I/O.

The address space is divided into regions: some addresses point to ROM, some to RAM, and a special range is reserved for peripherals. When the processor reads from address 255, it might actually be reading the state of a switch panel. When it writes to address 254, it might be lighting up an LED array.

The address decoder is what makes this work. It watches the address bus. If the address falls in the I/O range, instead of activating a memory chip, it activates the peripheral interface. The peripheral sees the read or write signal and responds just like memory would — placing data on the bus or capturing data from it.

Practical example. In a system with 8 LEDs mapped to address 254, the assembly code STA 254 writes the accumulator value to that address. The address decoder recognizes 254 as an I/O address, routes the write signal to the LED controller, and the 8 bits of the accumulator light up the corresponding LEDs. From the programmer's perspective, it's just a store instruction. Under the hood, it's talking to hardware.