73 lines
3.1 KiB
HTML
73 lines
3.1 KiB
HTML
<html><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
|
<html>
|
|
|
|
<head>
|
|
<title>80386 Programmer's Reference Manual -- Opcode LOOP</title>
|
|
</head>
|
|
|
|
<body>
|
|
<b>up:</b> <a href="C17.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C17.HTM">Chapter 17 -- 80386 Instruction Set</a><br>
|
|
<b>prev:</b><a href="LODS.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/LODS.HTM"> LODS/LODSB/LODSW/LODSD Load String Operand</a><br>
|
|
<b>next:</b><a href="LSL.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/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" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C17.HTM">Chapter 17 -- 80386 Instruction Set</a><br>
|
|
<b>prev:</b><a href="LODS.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/LODS.HTM"> LODS/LODSB/LODSW/LODSD Load String Operand</a><br>
|
|
<b>next:</b><a href="LSL.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/LSL.HTM"> LSL Load Segment Limit</a>
|
|
</body>
|
|
|