TEST

Logical Compare

stableVMJITAOTinstruction

Encodings

OpcodeInstructionOp/En64-bitCompat/LegacyDescription
A8 ibTEST AL, imm8IValidValidAND imm8 with AL; set SF, ZF, PF according to result.
A9 iwTEST AX, imm16IValidValidAND imm16 with AX; set SF, ZF, PF according to result.
A9 idTEST EAX, imm32IValidValidAND imm32 with EAX; set SF, ZF, PF according to result.
REX.W + A9 idTEST RAX, imm32IValidNot encodableAND imm32 sign-extended to 64-bits with RAX; set SF, ZF, PF according to result.
F6 /0 ibTEST r/m8, imm8MIValidValidAND imm8 with r/m8; set SF, ZF, PF according to result.
F7 /0 iwTEST r/m16, imm16MIValidValidAND imm16 with r/m16; set SF, ZF, PF according to result.
F7 /0 idTEST r/m32, imm32MIValidValidAND imm32 with r/m32; set SF, ZF, PF according to result.
REX.W + F7 /0 idTEST r/m64, imm32MIValidNot encodableAND imm32 sign-extended to 64-bits with r/m64; set SF, ZF, PF according to result.
84 /rTEST r/m8, r8MRValidValidAND r8 with r/m8; set SF, ZF, PF according to result.
85 /rTEST r/m16, r16MRValidValidAND r16 with r/m16; set SF, ZF, PF according to result.
85 /rTEST r/m32, r32MRValidValidAND r32 with r/m32; set SF, ZF, PF according to result.
REX.W + 85 /rTEST r/m64, r64MRValidNot encodableAND r64 with r/m64; set SF, ZF, PF according to result.

Operand encoding

Each mode is a value of the Op/En column above. It says which field of the encoded instruction carries each operand, in the order they are written, and whether the instruction reads it, writes it or both.

I

  1. AL/AX/EAX/RAX
  2. imm8/16/32immediate after the instruction, as wide as the operand

MI

  1. modrm.rm lecturaModRM byte, r/m field (bits 2-0); with the SIB byte and the displacement when the mod field asks for them
  2. imm8/16/32immediate after the instruction, as wide as the operand

MR

  1. modrm.rm lecturaModRM byte, r/m field (bits 2-0); with the SIB byte and the displacement when the mod field asks for them
  2. modrm.reg lecturaModRM byte, reg field (bits 5-3)

Measured cost

Loading measurements from arch-data...

Flags named

Description

Computes the bit-wise logical AND of first operand (source 1 operand) and the second operand (source 2 operand) and sets the SF, ZF, and PF status flags according to the result. The result is then discarded.

In 64-bit mode, using a REX prefix in the form of REX.R permits access to additional registers (R8-R15). Using a REX prefix in the form of REX.W promotes operation to 64 bits. See the summary chart at the beginning of this section for encoding data and limits.

Operation

TEMP := SRC1 AND SRC2;
SF := MSB(TEMP);

IF TEMP = 0
    THEN ZF := 1;
    ELSE ZF := 0;

FI:

PF := BitwiseXNOR(TEMP[0:7]);
CF := 0;
OF := 0;


(* AF is undefined *)

Flags affected

The OF and CF flags are set to 0. The SF, ZF, and PF flags are set according to the result (see the "Operation" section above). The state of the AF flag is undefined.

Exceptions

Protected mode
#GP(0)If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit. If the DS, ES, FS, or GS register contains a NULL segment selector.
#SS(0)If a memory operand effective address is outside the SS segment limit. #PF(fault-code) If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#UDIf the LOCK prefix is used.
Real address mode
#GPIf a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SSIf a memory operand effective address is outside the SS segment limit.
#UDIf the LOCK prefix is used.
Virtual-8086 mode
#GP(0)If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SS(0)If a memory operand effective address is outside the SS segment limit. #PF(fault-code) If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made.
#UDIf the LOCK prefix is used.
Compatibility mode
Same exceptions as in protected mode.
64-bit mode
#SS(0)If a memory address referencing the SS segment is in a non-canonical form.
#GP(0)If the memory address is in a non-canonical form. #PF(fault-code) If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#UDIf the LOCK prefix is used.

Sources