ARM: Efficient C for ARM: Unaligned Data Access

by David Thomas on

Unaligned Data Access

  • ARM favours 32-bit aligned addresses.
  • Unaligned values have to be pulled from memory a byte at a time and reformed.

Examples

A load from a guaranteed alignment:

LDR Rd,[Ra]

A load from an unspecified alignment:

LDRB Rd,[Ra,#0]
LDRB Rt,[Ra,#1]
ORR  Rd,Rd,Rt,LSL #8
LDRB Rt,[Ra,#2]
ORR  Rd,Rd,Rt,LSL #16
LDRB Rt,[Ra,#3]
ORR  Rd,Rd,Rt,LSL #24

Each byte must be individually fetched and merged into the result.

Navigate