Endianness

Contents

Endianness#

x86-64 and ARM64 (in normal mode) are little-endian: the least-significant byte comes first in memory. mov qword [p], rax writes rax’s low byte at [p], the next at [p+1], and so on. Network protocols (TCP, IP, TLS) are big-endian; use bswap (x86-64) or rev (ARM64) to swap.

Byte-swap a 32-bit register.

mov     eax, 0x12345678
bswap   eax                    ; eax = 0x78563412

References#

  • Sizes for the operand widths a swap operates on.

  • Strings and arrays for the on-disk byte layout this rule shapes.