Number bases and operands
| Number bases | |
| Operand sizes | |
| Bit masks |
Number bases
NASM writes hex with a 0x prefix, binary with 0b, and plain decimal by default. Character constants are single quotes and hold the ASCII value:
mov al, 0xFF ; 255
mov bl, 0b1010 ; 10
mov cl, 'A' ; 65
mov dl, 100 ; decimal 100
Operand sizes
When both operands are memory or a constant is involved, the size must be unambiguous. NASM resolves it from a register when it can, and from a size keyword otherwise:
mov byte [flag], 1
mov word [count], 1000
mov qword [big], 1000000
Bit masks
Hex is the natural base for masks, because one hex digit is exactly four bits. A mask of 0xF keeps the low nibble, and 0xFF00 keeps bits 8 through 15:
and eax, 0xFF ; keep only the low byte
shr eax, 8 ; shift right one byte
Next: Defining strings and data
Article author: Arthur Isaev