
Instruction Set
4-148
LOOPE
LOOPZ
Loop If Equal
Loop If Zero
LOOPE
What It Does
LOOPE and LOOPZ repeatedly execute a sequence of instructions in which two
components are compared; an unsigned number in CX tells the microcontroller the
maximum number of times to execute the sequence. Once the microcontroller compares
two components and finds they are not equal, the loop is no longer executed.
S yntax
Desc ription
At the bottom of a loop, LOOPE subtracts 1 from CX, and then performs a short jump to
the label at the top of the loop if the following conditions are met: CX is not 0, and the two
components that were just compared are equal. The label must be in the range from 128
bytes before LOOPE to 127 bytes after LOOPE. The microcontroller performs the following
sequence of operations:
1. Executes the instructions between label and LOOPE label.
2. Subtracts 1 from the unsigned number in CX.
3. Performs a short jump to the label if CX is not 0 and the Zero Flag (ZF) is 1.
When CX is 0 or ZF is 0, the microcontroller begins executing the instruction following
LOOPE. LOOPZ is a synonym for LOOPE.
Operation It Performs
Form
Opcode
Description
Clocks
Am186 Am188
LOOPE rel8
E1 cb
Decrement count; jump short if CX
≠
0 and ZF=1
16,6
16,6
LOOPZ rel8
E1 cb
Decrement count; jump short if CX
≠
0 and ZF=1
16,6
16,6
LOOPE label
LOOPZ label
To repeat a loop until CX is 0 or two
components compared inside the
loop are not equal, use LOOPE or its
synonym, LOOPZ. Both forms
perform the same operation.
/* decrement counter */
CX = CX - 1;
if ((CX != 0) && (ZF == 1))
/* equal */
{
/* extend sign of label */
if (label < 0)
displacement = 0xFF00 | label;
else
displacement = 0x00FF & label;
/* loop */
IP = IP + displacement;
}