Home  Site Map  Instruction Index 

LOOP  -  Loop Instruction


The LOOP instruction is used to repeat a task until the CX register counts down to zero. The CX register is decremented each time the LOOP instruction is encountered.

There are several similar LOOP alternatives that also use the CX register.

  • LOOP decrements until CX = 0
    Op Code is E2<./li>
  • LOOPE and LOOPZ, decrement until CX = 0, and the Zero flag has been set.
    Op Code is E1.
  • LOOPNE and LOOPNZ, decrement until CX = 0, and the Zero flag has NOT been set.
    Op Code E0.

This command has 2 parts, Instruction, then either a Register, Immediate value, or a memory address.

This example reads 16 single bytes before exiting the LOOP.


Assembly
Sample
Description   16 bit Machine
  Code
MOV CX, 0x0010;  Assign 10h (16) to the Counter CX   B9 10 00
MOV SI, DataString;  Assign SI to point at a memory
;  location to be read.
  BE 26 01
LODSB;  Load one byte into AL   AC
LOOP 0xFD;  LOOP back to LODSB to read
;  each byte until CX = 0
  E2 FD