Logical AND

Encoding

EncodingOperand 1Operand 2
mrModRM.r/m[rw]ModRM.reg[rw]
rmModRM.reg[rw]ModRM.r/m[rw]
aiAL/AX/EAX/RAXimm8/16/32
miModRM.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

Exceptions

Real-Address Mode

#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.

Virtual-8086 Mode

#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.

Protected Mode

#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If the destination is located in a non-writable segment.
  • If a memory operand uses a segment containing a NULL selector.
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.

Compatibility Mode

#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If the destination is located in a non-writable segment.
  • If a memory operand uses a segment containing a NULL selector.
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.

Long Mode

#UD
  • If the LOCK prefix is used, but the destination is not a memory operand.
#SS(0)
  • If a memory operand using the SS segment is in non-canonical form.
  • If a memory operand using the SS segment has an effective address that is outside the SS segment's limit.
#GP(0)
  • If a memory operand (using a segment other than SS) is in non-canonical form.
  • If the destination is located in a non-writable segment.
  • If a memory operand uses a segment containing a NULL selector.
  • If a memory operand (using a segment other than SS) has an effective address that is outside the segment's limit.
#PF(fc)
  • If a page fault occurs.
#AC(0)
  • If alignment checking is enabled while the current privilege level is 3 and an unaligned memory access is made.