The TEST instruction

Logical comparison (AND with flag setting).

The TEST instruction format

InstructionDescription
TEST AL, imm8AL AND imm8.
TEST AX, imm16AX AND imm16.
TEST reg/mem8, imm8reg/mem8 AND imm8.
TEST reg/mem16, imm16reg/mem16 AND imm16.
TEST reg/mem8, reg8reg/mem8 AND reg8.
TEST reg/mem16, reg16reg/mem16 AND reg16.

Computes the bitwise logical AND of the first operand and the second operand and sets the SF, ZF and PF status flags according to the result. The result is then discarded. The OF and CF flags are set to 0. The state of the AF flag is undefined.

Usage example

In this example we test the value of the ax register with different values and see how they affect the flags.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

code segment public        ; Start of the code segment
    assume cs:code

    main proc              ; Start of the main procedure
        mov     ax, 0      ; Copy the value 0 into the ax register
        test    ax, ax     ; Test the value of the ax register

        mov     ax, -1     ; Copy the value -1 into the ax register
        test    ax, ax     ; Test the value of the ax register

        mov     ax, 6      ; Copy the value 6 into the ax register
        test    ax, ax     ; Test the value of the ax register

        mov     ax, 4C00h  ; Copy the process termination function number into ah and the value into al
        int     21h        ; Call the interrupt
    main endp              ; End of the main procedure

code ends                  ; End of the code segment
end main                   ; End of file. The main procedure is the entry point

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

CF
0
PF
Yes
AF
?
ZF
Yes
SF
Yes
TF
No
IF
No
DF
No
OF
0