Home / Learn Embedded C / Memory-Mapped I/O Explained

Memory-Mapped I/O Explained

How peripheral registers appear as regular memory addresses that ordinary load/store instructions can access.

Quick summaryHow peripheral registers appear as regular memory addresses that ordinary load/store instructions can access.

How to think about this

A simplified address space layout0x00000000Flash (program code)0x20000000RAM (variables, stack, heap)0x40000000Peripheral registers (GPIO, timers, UART, ...)
A simplified address space layout

In plain terms

Memory-mapped I/O means peripheral control and status registers are assigned regular memory addresses, so the same load/store (read/write) instructions a CPU uses for RAM also read and write hardware registers — no special I/O instructions needed.

Why we use it

This is why, throughout this course, "reading a register" and "writing a register" have used exactly the same C syntax as reading/writing any other variable — the whole mechanism this course has been teaching rests on this single architectural idea.

Under the hood

A fixed range of the chip's overall address space is reserved for each peripheral's registers; accessing an address in that range does not touch RAM at all, but instead directly reads/writes that peripheral's hardware state.

Real-world use

  • All register-level peripheral access
  • Chip architecture understanding
  • Low-level driver development

Try it

A plain variable standing in for a memory-mapped register (see JSCPP_NOTES.md: integer-to-pointer casts are not supported here)C: edit and run

In real C this would be `*(volatile unsigned int*)0x40020014 |= (1 << 5);` — the bit operation itself is identical either way.

Try it: reading a status register vs an ordinary variable

Two "addresses" behaving identically under load/storeC: edit and run

Both lines use plain C assignment and bitwise operators; nothing in the syntax reveals that one is backed by RAM and the other by a hardware register.

Quick quiz

1. What does "memory-mapped" mean for a peripheral's registers?