LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What is the and $0xf, %reg pattern used for?

It masks off everything but the low 4 bits, giving a value 0-15 — equivalent to value % 16 or extracting a single hex digit.

Bitwise AND of 0x47 with mask 0x0f keeps the low four bits, giving 0x7, which equals 71 modulo 16

* AND with $0xf clears all but the low 4 bits — an isolate-low-nibble mask equivalent to value % 16. *

movzbl (%rax), %edx
and    $0xf, %edx

This reads a byte (like a character) and masks it to get a value 0-15.

Common uses:

  • Lookup table index: Extract low bits of a character as an array index
  • Modulo by power of 2: and $(N-1), %reg = %reg % N (when N is power of 2)
  • Bit field extraction: Isolate specific bits

Common masks:

Mask Bits kept Equivalent
$0x1 Lowest bit % 2 (odd/even check)
$0xf Low 4 bits % 16
$0xff Low byte % 256
$0x7 Low 3 bits % 8

Go deeper:

From Quiz: REVE1 / Assembly Patterns & GDB | Updated: Jul 14, 2026