Slide 11.9: TEST instruction
Slide 12.2: LOOPNZ and LOOPNE instructions
Home

LOOPZ and LOOPE Instructions


The LOOPZ (loop if zero) and LOOPE (loop if equal) instruction permit a loop to continue while the Zero flag is set and the unsigned value of ECX is greater than zero. The following code is the execution logic of them:
        ECX = ECX - 1
        if (ECX > 0 and ZF = 1)
           jump to destination
The loop destination must be within –128 to +127 bytes of the current location counter.

LOOPZ/LOOPE — LOOP If Equal (Zero)

Usage: LOOPZ label or LOOPE label

Flag O D I S Z A P C
Result                

Decrements ECX by 1 (without modifying the flags) and transfers control to “label” if ECX != 0 and the Zero Flag is set.
Clocks
Operands 286 386 486 Size Bytes
label: jump 8+m 11+m 9 2
no jump 4 ? 6 2

 LOOP   LOOPZ   LOOPE 
 INCLUDE Irvine32.inc
 .code
 main PROC
     count = 6
     mov   eax, 0
     mov   ecx, count
 L1: add   al, cl
     test  al, 0F0h
     loop  L1
     call  WriteInt
     exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .code
 main PROC
     count = 6
     mov    eax, 0
     mov    ecx, count
 L1: add    al, cl
     test   al, 0F0h
     loopz  L1
     call   WriteInt
     exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .code
 main PROC
     count = 6
     mov    eax, 0
     mov    ecx, count
 L1: add    al, cl
     test   al, 0F0h
     loope  L1
     call   WriteInt
     exit
 main ENDP
 END main
 Output  Output  Output