Opcode | Encoding | 16-bit | 32-bit | 64-bit | Description |
---|---|---|---|---|---|
20 /r AND r/m8, r8 | mr | Valid | Valid | Valid | Logical AND r8 into r/m8. |
REX 20 /r AND r/m8*, r8* | mr | N/E | N/E | Valid | Logical AND r8 into r/m8. This uses the alterate gpr8 encoding. |
21 /r AND r/m16, r16 | mr | Valid | Valid | Valid | Logical AND r16 into r/m16. |
21 /r AND r/m32, r32 | mr | Valid | Valid | Valid | Logical AND r32 into r/m32. |
REX.W 21 /r AND r/m64, r64 | mr | N/E | N/E | Valid | Logical AND r64 into r/m64. |
22 /r AND r8, r/m8 | rm | Valid | Valid | Valid | Logical AND r/m8 into r8. |
REX 22 /r AND r8*, r/m8* | rm | N/E | N/E | Valid | Logical AND r/m8 into r8. This uses the alterate gpr8 encoding. |
23 /r AND r16, r/m16 | rm | Valid | Valid | Valid | Logical AND r/m16 into r16. |
23 /r AND r32, r/m32 | rm | Valid | Valid | Valid | Logical AND r/m32 into r32. |
REX.W 23 /r AND r64, r/m64 | rm | N/E | N/E | Valid | Logical AND r/m64 into r64. |
24 ib AND AL, imm8 | ai | Valid | Valid | Valid | Logical AND imm8 into AL . |
25 iw AND AX, imm16 | ai | Valid | Valid | Valid | Logical AND imm16 into AX . |
25 id AND EAX, imm32 | ai | Valid | Valid | Valid | Logical AND imm32 into EAX . |
REX.W 25 id AND RAX, imm32 | ai | N/E | N/E | Valid | Logical AND imm32 (sign extended to 64 bits) into RAX . |
80 /4 ib AND r/m8, imm8 | mi | Valid | Valid | Valid | Logical AND imm8 into r/m8. |
REX 80 /4 ib AND r/m8*, imm8* | mi | Valid | Valid | Valid | Logical AND imm8 into r/m8. This uses the alterate gpr8 encoding. |
81 /4 iw AND r/m16, imm16 | mi | Valid | Valid | Valid | Logical AND imm16 into r/m16. |
81 /4 id AND r/m32, imm32 | mi | Valid | Valid | Valid | Logical AND imm32 into r/m32. |
REX.W 81 /4 id AND r/m64, imm32 | mi | N/E | N/E | Valid | Logical AND imm32 (sign extended to 64 bits) into r/m64. |
82 /4 ib AND r/m8, imm8 | mi | Valid | Valid | Invalid | Logical AND imm8 (sign extended to 8 bits) into r/m8. Undocumented. |
83 /4 ib AND r/m16, imm8 | mi | Valid | Valid | Valid | Logical AND imm8 (sign extended to 16 bits) into r/m16. |
83 /4 ib AND r/m32, imm8 | mi | Valid | Valid | Valid | Logical AND imm8 (sign extended to 32 bits) into r/m32. |
REX.W 83 /4 ib AND r/m64, imm8 | mi | N/E | N/E | Valid | Logical AND imm8 (sign extended to 64 bits) into r/m64. |
Encoding
Encoding | Operand 1 | Operand 2 |
---|---|---|
mr | ModRM.r/m[rw] | ModRM.reg[rw] |
rm | ModRM.reg[rw] | ModRM.r/m[rw] |
ai | AL/AX/EAX/RAX | imm8/16/32 |
mi | ModRM.r/m[rw] | imm8/16/32 |
Description
The AND
instruction performs a logical AND with source operand and the destination operand. The result is stored in the destination operand.
This instruction can be used with the LOCK
prefix to allow atomic exectution.
Operation
// `src` is sign extended to the width of `dest`
public void AND(ref U8 dest, U8 src)
{
dest &= SRC;
}
public void AND(ref U16 dest, U16 src)
{
dest &= SRC;
}
public void AND(ref U32 dest, U32 src)
{
dest &= SRC;
}
public void AND(ref U64 dest, U64 src)
{
dest &= SRC;
}
Flags Affected
CF
(carry flag)- Cleared.
PF
(parity flag)- Set according to the result.
AF
(auxiliary flag)- Undefined.
ZF
(zero flag)- Set according to the result.
SF
(sign flag)- Set according to the result.
OF
(overflow flag)- Cleared.
Intrinsics
uint8_t _addcarry_u8(uint8_t c_in, uint8_t src1, uint8_t src2, uint8_t *sum_out)
uint8_t _addcarry_u16(uint8_t c_in, uint16_t src1, uint16_t src2, uint16_t *sum_out)
uint8_t _addcarry_u32(uint8_t c_in, uint32_t src1, uint32_t src2, uint32_t *sum_out)
uint8_t _addcarry_u64(uint8_t c_in, uint64_t src1, uint64_t src2, uint64_t *sum_out)
Exceptions
Exception | Mode | Cause of Exception | |||
---|---|---|---|---|---|
Real Mode | Virtual 8086 | Protected and Compatibility | Long Mode | ||
#UD | X | X | X | X | If the LOCK prefix is used, but the destination is not a memory operand. |
#SS(0) | X | X | X | X | If a memory operand using the SS segment has an effective address that is outside the SS segment's limit. |
X | If a memory operand using the SS segment is in non-canonical form. | ||||
#GP(0) | X | X | X | X | If a memory operand (using a segment other than SS ) has an effective address that is outside the segment's limit. |
X | X | If the destination is located in a non-writable segment. | |||
X | X | If a memory operand uses a segment containing a NULL selector. | |||
X | If a memory operand (using a segment other than SS ) is in non-canonical form. | ||||
#PF(fc) | X | X | X | If a page fault occurs. | |
#AC(0) | X | X | X | If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made. |