What is endianness in ARM?
Short answer: Endianness determines the byte order of multi-byte values in memory. AArch64 supports little-endian data and implementation-dependent big-endian support; Linux commonly uses little-endian.
REV W0, W1 // reverse byte order
1. Example: Store 0x12345678 at address 0x1000.
| Address | Little endian | Big endian |
|---|---|---|
| 0x1000 | 78 | 12 |
| 0x1001 | 56 | 34 |
| 0x1002 | 34 | 56 |
| 0x1003 | 12 | 78 |
2. C example
uint32_t x = 1;
bool little = *(unsigned char *)&x == 1;
3. Drivers: Protocols and device registers may define their own byte order. Use conversions such as cpu_to_le32 or be32_to_cpu where appropriate.
Interview takeaway: Endianness changes byte layout in memory, not the numerical meaning of an integer held in a register.
Byte order at a protocol boundary
Suppose an I2C device returns bytes 0x12 and 0x34 for a 16-bit big-endian register value.
uint16_t decode_be16(const uint8_t b[2])
{
return (uint16_t)(((uint16_t)b[0] << 8) | b[1]);
}
The result is 0x1234 regardless of the host CPU's byte order. Directly casting b to a uint16_t pointer can cause alignment, aliasing and endian problems. Explicit decoding or suitable OS helpers handles the protocol representation.
REV reverses all bytes of the selected register width; REV16 swaps bytes within each 16-bit group; RBIT reverses individual bits rather than bytes. These operations are distinct from the bit transmission order of a serial protocol.
A device's MMIO registers can specify their own endianness; Linux provides appropriate endian-specific accessors. Do not assume every peripheral uses the CPU's native byte order. A64 instruction encodings themselves use the architecture's fixed little-endian instruction representation, independently of supported data endianness.