4.5. Aligning data

It is sometimes necessary to access unaligned data in memory, for example, when porting legacy code from a CISC architecture where instructions are available to directly access unaligned data in memory.

Like other RISC architectures, ARM and Thumb processors are designed to efficiently access aligned data, that is, words which lie on addresses that are multiples of four, and halfwords which lie on addresses that are multiples of two. Such data is located on its natural size boundary.

Care needs to be taken when accessing unaligned data in memory, lest unexpected results are returned. For example, when a conventional pointer is used to read a word in C or C++ source code, the ARM compiler generates assembly language code that reads the word using an LDR instruction. This works as expected when the address is a multiple of four, for example if it lies on a word boundary. However, if the address is not a multiple of four, then the LDR returns a rotated result rather than performing a true unaligned word load. Generally this rotation is not what the programmer expects.

Copyright © 2002-2007 ARM Limited. All rights reserved.ARM DUI 0205H