Instructions
x86-64AND / OR / NOT
Bitwise logical instructions used for masking, flag testing, and bit manipulation; AND and OR set flags while NOT does not.
AND, OR, and NOT implement the three fundamental bitwise operations.
AND and OR update ZF, SF, PF and always clear CF and OF; NOT does
not modify any flags at all.
Syntax
and rax, 0xFF ; keep only low 8 bits of rax (mask)
and rax, rbx ; rax &= rbx
or rax, 0x1 ; set LSB of rax
or rax, rbx ; rax |= rbx
not rax ; rax = ~rax (one's complement / bitwise NOT)Common patterns
| Pattern | Meaning |
|---|---|
and rax, ~0xF | Align down to 16-byte boundary |
and rsp, ~0xF | 16-byte-align the stack before a call |
and eax, 0xFF | Zero-extend byte to 32 bits (cheaper: movzx eax, al) |
or eax, eax | Set ZF/SF for null check (same as test eax,eax) |
or al, 0x20 | Set bit 5 — convert uppercase ASCII to lowercase |
not rax; add rax, 1 | Two's complement negation (neg rax is equivalent) |
Reverse-engineering notes
and rsp, -16(orand rsp, 0xFFFFFFFFFFFFFFF0) in a prologue aligns the stack to 16 bytes for SSE/AVX calls — do not confuse it with a bounds check.- Bit-field extraction is usually
shr rax, N; and rax, mask— the shift positions the field at bit 0 and theandisolates it. andfollowed immediately byje/jneis functionally equivalent totestbut stores the result — the compiler may prefer it if the masked value is also needed later.notwithout a followingaddis rare; when present it usually implements a one's-complement checksum or a bitwise complement in crypto code.