
Instruction Set
4-150
LOOPNE Loop If Not Equal
LOOPNE
LOOPNZ Loop If Not Zero
What It Does
LOOPNE and LOOPNZ 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 equal, the loop is no longer executed.
Syntax
Description
At the bottom of a loop, LOOPNE 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 not equal. The label must be in the range from
128 bytes before LOOPNE to 127 bytes after LOOPNE. The microcontroller performs the
following sequence of operations:
1. Executes the instructions between
label and LOOPNE 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 0.
When CX is 0 or ZF is 1, the microcontroller begins executing the instruction following
LOOPNE. LOOPNZ is a synonym for LOOPNE.
Operation It Performs
Form
Opcode
Description
Clocks
Am186 Am188
LOOPNE
rel8
E0
cb
Decrement count; jump short if CX
≠
0 and ZF=0
16,6
16,6
LOOPNZ
rel8
E0
cb
Decrement count; jump short if CX
≠
0 and ZF=0
16,6
16,6
To repeat a loop until CX is 0 or two
components compared inside the loop
are equal, use LOOPNE or its syn-
onym, LOOPNZ. Both forms perform
the same operation.
LOOPNE
label
LOOPNZ
label
/* decrement counter */
CX = CX - 1;
if ((CX != 0) && (ZF == 0))
/* not equal */
{
/* extend sign of label */
if (
label < 0)
displacement = 0xFF00 |
label;
else
displacement = 0x00FF &
label;
/* loop */
IP = IP + displacement;
}
Summary of Contents for Am186 Series
Page 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Page 10: ...Table of Contents x...
Page 18: ...Programming 1 8...
Page 40: ...Instruction Set Listing 3 14...