test
Logical compare
Sets the flags from a bitwise AND of the two operands, without storing the result.
8086 and later
Used in
- The flags registerx86-64 assembly
- Loopsx86-64 assembly
- Arithmetic, logic and bitsx86-64 assembly
- Arrays, strings and the string instructionsx86-64 assembly
- syscall and the Linux x86-64 ABIx86-64 assembly
- Interrupts, exceptions and signalsx86-64 assembly
- Length of a stringx86-64 assembly
- Even or odd, count the set bits, multiply by shiftingx86-64 assembly
- Print an unsigned number in bases 2 through 36x86-64 assembly
CFPFAFZFSFDFOF 0●?●●–0
- ● set from the result
- 0 always 0
- ? undefined afterwards
- – not changed
Forms
Operands
r/m- A general-purpose register or memory location matching the operation’s size, for example
raxorqword [rbp-8]. The byte registersah,bh,chanddhcannot be used with a REX prefix, including when the memory address usesr8–r15. reg- A general-purpose register matching the operation’s size, for example
al,ax,eaxorrax. The byte registersah,bh,chanddhcannot be used with a REX prefix, which is required byspl,bpl,sil,dilandr8–r15. imm- An immediate value encoded in the instruction, written as a number, character or label. Its encoded width and any sign extension depend on the instruction; arithmetic immediates may be sign-extended, while shift counts are used without sign extension.
acc- The accumulator matching the operation’s size:
al,ax,eaxorrax. A shorter encoding may be available.
ZF reports whether all tested bits were zero; CF and OF are cleared.
For a 64-bit operand, an immediate uses a 32-bit field sign-extended to 64 bits. For example, test rax, -1 tests all 64 bits. There is no full 64-bit immediate or sign-extended 8-bit immediate encoding for test; load a different 64-bit mask into a register if needed.
global _start
section .text
_start:
mov rax, 12
mov rbx, 5
mov rcx, 3
mov rsi, 9
test rax, rbx
mov rax, 60 ; syscall 60: exit
xor rdi, rdi
syscall