In the x86 assembly language, the <code>TEST</code> instruction performs a bitwise AND on two operands. The flags <code>SF</code>, <code>ZF</code>, <code>PF</code> are modified while the numerical result of the AND is discarded. The <code>OF</code> and <code>CF</code> flags are set to <code>0</code>, while <code>AF</code> 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.
The TEST operation clears the flags <code>CF</code> and <code>OF</code> to zero. The <code>SF</code> is set to the most significant bit of the result of the AND. If the result is <code>0</code>, the <code>ZF</code> is set to <code>1</code>, otherwise set to <code>0</code>. The parity flag is set to the bitwise XNOR of all eight least significant bits of the result, <code>1</code> if the number of ones in that byte is even, <code>0</code> otherwise. The value of <code>AF</code> is undefined.
Note that when TESTing a register against itself, there is no change to the register. The AND instruction could be substituted.