Skip to content
Tactiverge

Computer architecture

Memory-mapped I/O

Also called: MMIO · peripheral registers · GPIO register · register map

Definition

With memory-mapped I/O, peripheral control and data registers appear at fixed memory addresses, so the processor talks to hardware with ordinary load and store instructions.

Picture it

Writing a 1 to bit 5 at a GPIO output address turns on pin 5. Datasheets publish the register map. Because hardware can change these values on its own, code must read them freshly each time, which is another reason for volatile.

The maths

register address = peripheral base + offset
set bit k: reg = reg | (1 << k)
SI units used in this entry
QuantityUnitSymbol
informationbitbit

Worked example

A GPIO port's output register is at base 0x4000_0000 + offset 0x14. Firmware sets bit 5 in a register currently holding 0x01. What address is written and what value?

  1. Address = 0x40000014
  2. 1 << 5 = 0x20
  3. 0x01 | 0x20 = 0x21 = 33

AnswerWrite 0x21 (decimal 33) to 0x40000014.

✓ The number in this answer is recomputed from scratch by an automated test.

Common misconceptions

  • Misconception: Writing a whole register to set one bit can accidentally clear the others; read, modify, write.
  • Misconception: Peripheral registers are not normal RAM; reading some of them clears flags.