LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

How do you read or extract a specific byte from a multi-byte register?

Use a sub-register name for the low bytes (%al, %ax) or %ah for bits 8–15; for higher bytes you must shift the value down first, then mask.

The named sub-registers only reach the bottom of the register, so extracting an arbitrary byte takes a shift.

Low bytes — direct:

mov %al, %cl    # lowest byte of %rax → %cl
mov %ax, %cx    # lowest 2 bytes
mov %ah, %cl    # bits 8–15 (the only "high" byte with a name)

Higher bytes — shift then mask:

mov  %rax, %rcx
shr  $16, %rcx     # bring byte 2 (bits 16–23) down to the bottom
movzbl %cl, %ecx   # keep just that byte, zero the rest
mov %rax, %rcx
shr $24, %rcx      # byte 3
and $0xFF, %rcx    # mask to a single byte

Tip: the new registers %r8%r15 don't have legacy byte names, so you use suffixes instead: %r8b (byte), %r8w (word), %r8d (dword).

Go deeper:

  • doc x86-64 (Wikipedia) — the 16 GP registers and the r8-r15 set lacking legacy byte names.

From Quiz: REVE1 / The Processor Interface | Updated: Jul 10, 2026