IT lexicon › Hardware › Unaligned access

Unaligned access

Hardware På svenska → Updated: 2026-11-04

Reading a 32-bit word from an address that isn't a multiple of four — something some CPUs tolerate with a sigh and others refuse outright.

x86 has always allowed it, at a cost when the word straddles a cache line. Cortex-M3 and M4 handle ordinary loads and stores but raise a UsageFault on multi-word instructions. Cortex-M0 takes no chances and goes straight to HardFault. Older ARM cores were the worst of all: they silently rotated the bytes and handed back a wrong value without complaint.

The bug nearly always arrives the same way: a received byte buffer gets cast to uint32_t*, or a packed struct is read field by field. It works on the developer's PC and crashes on the target board. The portable fix is memcpy into a local variable, which the compiler turns into the right instructions anyway.

← Back to the lexicon