test

Logical compare

Sets the flags from a bitwise AND of the two operands, without storing the result.

8086 and later

Intel's reference: TEST

CFPFAFZFSFDFOF 0●?●●–0
  • ● depends on the result
  • 0 always 0
  • ? undefined (do not rely on it)
  • – not changed

Forms

Operands

r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8].
reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax.
imm
An immediate value: a constant written in the instruction as a number, a character or a label, for example 10, 0x1f, 'a' or msg. Open a row to see the size it has in each form, such as imm8 or imm32.
acc
The accumulator: al, ax, eax or rax, whichever matches the operation’s size. The form accepts no other register in this position.

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