In the
x86 assembly language
x86 assembly language is a family of Low-level programming language, low-level programming languages that are used to produce object code for the x86 class of processors. These languages provide backward compatibility with CPUs dating back to th ...
, the
TEST
instruction performs a
bitwise AND
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operat ...
on two
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
s. The
flag
A flag is a piece of textile, fabric (most often rectangular) with distinctive colours and design. It is used as a symbol, a signalling device, or for decoration. The term ''flag'' is also used to refer to the graphic design employed, and fla ...
s
SF
,
ZF
,
PF
are modified while the numerical result of the
AND
And or AND may refer to:
Logic, grammar and computing
* Conjunction, connecting two words, phrases, or clauses
* Logical conjunction in mathematical logic, notated as "∧", "⋅", "&", or simple juxtaposition
* Bitwise AND, a Boolean oper ...
is discarded. The
OF
and
CF
flags are set to
0
, while
AF
flag is undefined. There are 9 different
opcode
In computing, an opcode (abbreviated from operation code) is an enumerated value that specifies the operation to be performed. Opcodes are employed in hardware devices such as arithmetic logic units (ALUs), central processing units (CPUs), and ...
s for the TEST instruction depending on the type and size of the
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
s. 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.
TEST opcode variations
The TEST operation clears the flags
CF
and
OF
to zero. The
SF
is set to the
most significant bit
In computing, bit numbering is the convention used to identify the bit positions in a binary numeral system, binary number.
Bit significance and indexing
In computing, the least significant bit (LSb) is the bit position in a Binary numeral sy ...
of the result of the
AND
And or AND may refer to:
Logic, grammar and computing
* Conjunction, connecting two words, phrases, or clauses
* Logical conjunction in mathematical logic, notated as "∧", "⋅", "&", or simple juxtaposition
* Bitwise AND, a Boolean oper ...
. If the result is
0
, the
ZF
is set to
1
, otherwise set to
0
. The parity flag is set to the
bitwise
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operat ...
XNOR
The XNOR gate (sometimes ENOR, EXNOR, NXOR, XAND and pronounced as exclusive NOR) is a digital logic gate whose function is the logical complement of the exclusive OR ( XOR) gate. It is equivalent to the logical connective (\leftrightarrow) fr ...
of the
least significant byte
In computing, bit numbering is the convention used to identify the bit positions in a binary number.
Bit significance and indexing
In computing, the least significant bit (LSb) is the bit position in a binary integer representing the lowes ...
of the result,
1
if the number of ones in that byte is even,
0
otherwise. The value of
AF
is undefined.
Examples
; 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 ; set ZF if "al AND $0f = 0" (here: address-align test for 16b)
jnz @destination ; jump if eax IS NOT "MODULO 16=0"
References
X86 instructions
{{software-stub