Extract a packed color byte
Before you start this master track
Binary and hexadecimal numbers, memory addresses, register widths, and signed arithmetic.
Master is the entry-background tier for this track. These three introductory x86-64 exercises cover registers, masks, shifts, and flags; completing them does not establish mastery of Assembly.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Predict the result.
After the final instruction, what hexadecimal value is in EBX?
mov eax, 0xABCDand eax, 0xFFmov ebx, eaxnopx86-64 instruction snippets in Intel/NASM syntax, not complete OS programs. Step from the first instruction through the last in a debugger, then inspect the named registers. eax, ebx, and ecx are 32-bit registers; cl is the low byte of ecx. No console output or system calls are used.
Review the lesson
Registers hold bit patterns. mov copies a value into its destination, which appears first in Intel syntax. AND keeps a bit only when both input bits are one. A mask of 0xFF therefore keeps the lowest eight bits and clears the rest, extracting one byte from a packed value.