LOOPZ and LOOPE Instructions


The (loop if zero) and (loop if equal) instruction permit a loop to continue while the Zero flag is set and the unsigned value of 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 by 1 (without modifying the flags) and transfers control to “label” if != 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
 .data
  dummy  WORD  ? 
 .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
 .data
  dummy  WORD  ?
 .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
 .data
  dummy  WORD  ?
 .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

 

 

 

 

 

 






      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown