forked from NJU-ProjectN/i386-manual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LOOP.htm
94 lines (77 loc) · 2.69 KB
/
LOOP.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>80386 Programmer's Reference Manual -- Opcode LOOP</TITLE>
</HEAD>
<BODY STYLE="width:80ch">
<B>up:</B> <A HREF="c17.htm">
Chapter 17 -- 80386 Instruction Set</A><BR>
<B>prev:</B><A HREF="LODS.htm"> LODS/LODSB/LODSW/LODSD Load String Operand</A><BR>
<B>next:</B><A HREF="LSL.htm"> LSL Load Segment Limit</A>
<P>
<HR>
<P>
<H1>LOOP/LOOPcond -- Loop Control with CX Counter</H1>
<PRE>
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
</PRE>
<H2>Operation</H2>
<PRE>
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;
</PRE>
<H2>Description</H2>
LOOP decrements the count register without changing any of the flags.
Conditions are then checked for the form of LOOP being used. If the
conditions are met, a short jump is made to the label given by the operand
to LOOP. If the address-size attribute is 16 bits, the CX register is used
as the count register; otherwise the ECX register is used. The operand
of LOOP must be in the range from 128 (decimal) bytes before the
instruction to 127 bytes ahead of the instruction.
<P>
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.
<H2>Flags Affected</H2>
None
<H2>Protected Mode Exceptions</H2>
#GP(0) if the offset jumped to is beyond the limits of the current code
segment
<H2>Real Address Mode Exceptions</H2>
None
<H2>Virtual 8086 Mode Exceptions</H2>
None
<P>
<HR>
<P>
<B>up:</B> <A HREF="c17.htm">
Chapter 17 -- 80386 Instruction Set</A><BR>
<B>prev:</B><A HREF="LODS.htm"> LODS/LODSB/LODSW/LODSD Load String Operand</A><BR>
<B>next:</B><A HREF="LSL.htm"> LSL Load Segment Limit</A>
</BODY>