1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML 2.0//EN">
4 <TITLE>80386 Programmer's Reference Manual -- Opcode LOOP
</TITLE>
7 <B>up:
</B> <A HREF=
"c17.htm">
8 Chapter
17 --
80386 Instruction Set
</A><BR>
9 <B>prev:
</B><A HREF=
"LODS.htm"> LODS/LODSB/LODSW/LODSD Load String Operand
</A><BR>
10 <B>next:
</B><A HREF=
"LSL.htm"> LSL Load Segment Limit
</A>
14 <H1>LOOP/LOOPcond -- Loop Control with CX Counter
</H1>
17 Opcode Instruction Clocks Description
19 E2 cb LOOP rel8
11+m DEC count; jump short if count <
> 0
20 E1 cb LOOPE rel8
11+m DEC count; jump short if count <
> 0 and ZF=
1
21 E1 cb LOOPZ rel8
11+m DEC count; jump short if count <
> 0 and ZF=
1
22 E0 cb LOOPNE rel8
11+m DEC count; jump short if count <
> 0 and ZF=
0
23 E0 cb LOOPNZ rel8
11+m DEC count; jump short if count <
> 0 and ZF=
0
29 IF AddressSize =
16 THEN CountReg is CX ELSE CountReg is ECX; FI;
30 CountReg := CountReg -
1;
31 IF instruction <
> LOOP
33 IF (instruction = LOOPE) OR (instruction = LOOPZ)
34 THEN BranchCond := (ZF =
1) AND (CountReg <
> 0);
36 IF (instruction = LOOPNE) OR (instruction = LOOPNZ)
37 THEN BranchCond := (ZF =
0) AND (CountReg <
> 0);
45 IP := IP + SignExtend(rel8);
46 ELSE (* OperandSize =
32 *)
47 EIP := EIP + SignExtend(rel8);
54 LOOP decrements the count register without changing any of the flags.
55 Conditions are then checked for the form of LOOP being used. If the
56 conditions are met, a short jump is made to the label given by the operand
57 to LOOP. If the address-size attribute is
16 bits, the CX register is used
58 as the count register; otherwise the ECX register is used. The operand
59 of LOOP must be in the range from
128 (decimal) bytes before the
60 instruction to
127 bytes ahead of the instruction.
62 The LOOP instructions provide iteration control and combine loop index
63 management with conditional branching. Use the LOOP instruction by
64 loading an unsigned iteration count into the count register, then code the
65 LOOP at the end of a series of instructions to be iterated. The
66 destination of LOOP is a label that points to the beginning of the
69 <H2>Flags Affected
</H2>
73 <H2>Protected Mode Exceptions
</H2>
75 #GP(
0) if the offset jumped to is beyond the limits of the current code
78 <H2>Real Address Mode Exceptions
</H2>
82 <H2>Virtual
8086 Mode Exceptions
</H2>
90 <B>up:
</B> <A HREF=
"c17.htm">
91 Chapter
17 --
80386 Instruction Set
</A><BR>
92 <B>prev:
</B><A HREF=
"LODS.htm"> LODS/LODSB/LODSW/LODSD Load String Operand
</A><BR>
93 <B>next:
</B><A HREF=
"LSL.htm"> LSL Load Segment Limit
</A>