TEST (x86 instruction) (original) (raw)
From Wikipedia, the free encyclopedia
X86 instruction
In the x86 assembly language, the **TEST**
instruction performs a bitwise AND on two operands. The flags [SF](/wiki/Sign%5Fflag "Sign flag")
, [ZF](/wiki/Zero%5Fflag "Zero flag")
, [PF](/wiki/Parity%5Fflag "Parity flag")
are modified while the numerical result of the AND is discarded. The OF
and CF
flags are set to 0
, while AF
flag is undefined. There are 9 different opcodes for the TEST instruction depending on the type and size of the operands. It can test 8-bit, 16-bit, 32-bit, or 64-bit values. It can also test registers and memory against registers and immediate values.[1]
TEST opcode variations
[edit]
The TEST operation clears the flags CF
and OF
to zero. The [SF](/wiki/Sign%5Fflag "Sign flag")
is set to the most significant bit of the result of the AND. If the result is 0
, the ZF
is set to 1
, otherwise set to 0
. The parity flag is set to the bitwise XNOR of the least significant byte of the result, 1
if the number of ones in that byte is even, 0
otherwise. The value of AF
is undefined.
; Conditional Jump test cl,cl ; set ZF to 1 if cl == 0 jz 0x8004f430 ; jump if ZF == 1
; Conditional Jump with NOT test cl, cl ; set ZF to 1 if cl == 0 jnz 0x8004f430 ; jump if ZF == 0
; or test eax, eax ; set SF to 1 if eax < 0 (negative) js error ; jump if SF == 1
; regular application test al, 0F;setZFif"alAND0F ; set ZF if "al AND 0F;setZFif"alAND0f = 0" (here: address-align test for 16b) jnz @destination ; jump if eax IS NOT "MODULO 16=0"
- ^ "Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2B: Instruction Set Reference, N-Z" (PDF). Retrieved 2019-12-21.