Opcode Instruction Clocks Description E2 cb LOOP rel8 11+m DEC count; jump short if count <> 0 E1 cb LOOPE rel8 11+m DEC count; jump short if count <> 0 and ZF=1 E1 cb LOOPZ rel8 11+m DEC count; jump short if count <> 0 and ZF=1 E0 cb LOOPNE rel8 11+m DEC count; jump short if count <> 0 and ZF=0 E0 cb LOOPNZ rel8 11+m DEC count; jump short if count <> 0 and ZF=0
IF AddressSize = 16 THEN CountReg is CX ELSE CountReg is ECX; FI; CountReg := CountReg - 1; IF instruction <> LOOP THEN IF (instruction = LOOPE) OR (instruction = LOOPZ) THEN BranchCond := (ZF = 1) AND (CountReg <> 0); FI; IF (instruction = LOOPNE) OR (instruction = LOOPNZ) THEN BranchCond := (ZF = 0) AND (CountReg <> 0); FI; FI; IF BranchCond THEN IF OperandSize = 16 THEN IP := IP + SignExtend(rel8); ELSE (* OperandSize = 32 *) EIP := EIP + SignExtend(rel8); FI; FI;
The LOOP instructions provide iteration control and combine loop index management with conditional branching. Use the LOOP instruction by loading an unsigned iteration count into the count register, then code the LOOP at the end of a series of instructions to be iterated. The destination of LOOP is a label that points to the beginning of the iteration.
up:
Chapter 17 -- 80386 Instruction Set
prev: LODS/LODSB/LODSW/LODSD Load String Operand
next: LSL Load Segment Limit