AND
By Vesper Vei
1 minute read
Table of Contents
AND (and)
Basic function
AND performs a bitwise logical AND operation:
x1 = x1 & x2Instruction format
and x1, x2x1 can be a register or memory
x2 is a register or an immediate value
but memory-to-memory is not allowed
Behavioral characteristics
- Commonly used for bit clearing
- ZF is set if the result is all zeros
- OF and CF are cleared
- It does not produce a carry concept, because it is a logical operation
Example
and eax, 0xFF; 保留低 8 位
and rax, rbxand [rbp-0x8], 0x1Common uses
- Masking operations —> IP&24 subnet mask
- Bit condition checking
- Alignment calculations (such as aligning an address to 4, 8, or 16 bytes)
For example, aligning to 16 bytes:
and rsp, -0x10