LOOP location Loop LOOPE/LOOPZ location Loop While Equal/Zero LOOPNE/LOOPNZ location Loop While Not Equal/Zero
Logic ; loop ; loope ; loopne eCX ← eCX - 1 eCX ← eCX - 1 eCX ← eCX - 1 if eCX <> 0 if eCX <> 0 AND ZF=1 if eCX <> 0 AND ZF=0 JMP location JMP location JMP location endif endif endif
The LOOP instructions are conditional jumps that use the count value in eCX (LOOPE/LOOPNE also use the zero flag) to determine whether a code loop should be continued or terminated.
All LOOPs automatically decrement eCX and terminate when eCX = 0. The operand, a short code label, must be in the range -128 to +127 bytes from the next instruction.
If the address-size attribute is 16 bits, the CX register is used as the count register; otherwise, ECX is used (80386+).
Example: sub ax,ax jcxz skip ; Don't execute 65,535 times again: add ax,[bx] stosw inc bx inc bx loop again mov [looped],1 skip:
Note Some assemblers support the following LOOP extensions that force the use of CX (loopw forms) or ECX (loopd forms) regardless of the code segment's size attribute (80386+):