User's Manual

BASIC INSTRUCTION SET
LOOPE (Loop While Equal) and LOOPZ (Loop While Zero) are physically the same instruction.
These instructions auto-decrement the
ex
register before testing
ex
and
ZF
for
the branch conditions.
If
ex
is
non-zero and
ZF=
1,
the program branches
to
the target label specified
in
the instruction.
If
LOOPE or LOOPZ finds that
ex=o
or ZF=O, control transfers
to
the instruction immediately
succeeding the
LOOPE or LOOPZ instruction.
Example:
LOOPE START_LOOP (or LOOPZ START_LOOP). Each time the program encounters
this instruction, it decrements
ex
and tests
ex
and ZF.
If
the value
in
ex
is
non-zero and
the value of
ZF
is
1,
the program branches
to
the instruction labeled START_LOOP.
If
ex=o
or
ZF=O,
the program continues with the instruction that
follows
the LOOPE (or
LOOPZ) instruction.
LOOPNE (Loop While
Not
Equal) and LOOPNZ (Loop While Not Zero) are physically the same
instruction. These instructions auto-decrement the
ex
register before testing
ex
and ZF
for
the branch
conditions.
If
ex
is
non-zero and ZF=O, the program branches
to
the target label specified
in
the
instruction.
If
LOOPNE
or
LOOPNZ finds that
ex=o
or
ZF=
1,
control transfers
to
the instruction
immediately succeeding the
LOOPNE or LOOPNZ instruction.
Example:
LOOPNE
START_LOOP
(or
LOOPNZ
START_LOOP). Each time the program
encounters this instruction, it decrements
ex
and tests
ex
and ZF.
If
the value of
ex
is
non-zero and the value of
ZF
is
0,
the program branches
to
the instruction labeled
START_LOOP.
If
ex=o
or
ZF=
1,
the program continues with the instruction that
follows
the LOOPNE (or LOOPNZ) instruction.
3.6.2.3
EXECUTING A LOOP
OR
REPEAT ZERO TIMES
JCXZ
(Jump
if
CX
Zero) branches
to
the label specified
in
the,
instruction if it finds a value of zero
in
ex.
Sometimes, it
is
desirable
to
design a
loop
that executes zero times if the count variable
in
ex
is
initialized
to
zero. Because the LOOP instructions (and repeat prefixes) decrement
ex
before they
test it, a
loop
will
execute 65,536 times if the program enters the
loop
with a zero value
in
ex.
A
programmer may conveniently overcome this problem
with
JeXZ,
which enables the program
to
branch
around the code within the
loop
if
ex
is
zero when
JeXZ
executes.
Example:
JeXZ
TARGETLABEL. Causes the program
to
branch
to
the instruction labeled
TARGETLABEL if
ex=o
when the instruction executes.
3.6.3
Software-Generated Interrupts
The
INT
n and INTO instructions allow the programmer
to
specify a transfer
to
an
interrupt service
routine from within a program. Interrupts
0-31
are reserved
by
Intel.
3.6.3.1
SOFTWARE INTERRUPT INSTRUCTION
INT
n (Software Interrupt) activates the interrupt service routine that corresponds
to
the number
coded within the instruction. Interrupt type 3
is
reserved for internal software-generated interrupts.
However, the
INT
instruction may specify any interrupt type
to
allow
multiple types of internal inter-
rupts
or
to
test the operation of a service routine. The interrupt service routine terminates with an
IRET instruction that returns control
to
the instruction that
follows
INT.
Example:
INT
3.
Transfers control
to
the interrupt service routine specified
by
a type 3 interrupt.
3-21