DYSTOPIANPIXEL

Little-endian byte order

See why a sixteen-bit value is stored with its low byte first.

Next Asset Lab concept artwork showing sprite patterns, palette colours and animation frames
Next Asset Lab concept artwork · Begin with Odin Dev.2k and the foundations of Z80 assembly.
TUTORIAL 1 / PART 12

Little-endian byte order

Why does $6000 appear as 00 60?

The instruction LD HL,$6000 assembled as:

21 00 60

The opcode is $21. The following two bytes represent the 16-bit value $6000, but they appear as $00 followed by $60.

The Z80 stores 16-bit immediate values in little-endian order: the low byte comes first, followed by the high byte.

$6000
high byte = $60
low byte  = $00

stored in instruction = 00 60

This often feels backwards at first. It becomes familiar with practice, and it matters later when working with pointers, files, data structures and operating-system calls.