TEST Instruction


The TEST instruction performs an implied AND operation between each pair of matching bits in two operands and sets the flags accordingly. The only difference between TEST and AND is that TEST does not modify the destination operand.

TEST — Test for Bit Pattern

Usage: TEST dest, src

Flag O D I S Z A P C
Result *     * * ? * 0

Performs a logical AND of the two operands updating the flags register without saving the result.
Clocks
Operands 286 386 486 Size Bytes
reg, reg 2 1 1 2
reg, mem 6 5 1 2-4
mem, reg 6 5 2 2-4
reg, immed 3 2 1 3-4
mem, immed 6 5 2 3-6
accum, immed 3 2 1 2-3

The LAHF instruction copies bits 0-7 of the flags register into AH.
        AH := S Z ? A ? P ? C
 Sign & Carry Test   Odd Number Test   > 15 Test 
 INCLUDE Irvine32.inc
 .code
 main PROC
     mov   bh, 80h
     neg   bh
     lahf 
     test  ah, 10000001b
     jnz   L1
     call  WaitMsg
 L1: exit
 main ENDP
 END main
 .code
     mov   al, 0
     mov   bl, 1
     count = 5
     mov   ecx, count
 L1: add   al, bl
     xchg  al, bl
     loop  L1
     test  bl, 00000001b
     jnz   L2
     call  WaitMsg
 L2: exit
 .code
     count = 5
     mov   al, 0
     mov   ecx, count
 L1: add   al, cl
     loop  L1
     test  al, 11110000b
     jnz   L2
     call  WaitMsg
 L2: exit
 Output  Output  Output