16 bit Assembly
Home Site Map Instruction Index
The LOOP instruction is used to repeat a task until the CX register reaches 0.
The CX register is decremented each time the LOOP instruction is actioned.
This command has 2 parts, Instruction, then either a Register, Immediate value, or a memory address.
There are several similar LOOP alternatives that also use the CX register.
The operand is an 8 bit near jump address (forward 0 to 79h) or (backwards FF to 80h).
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 |