User's Manual

BASIC INSTRUCTION SET
4.
Adjust the memory pointers
in
DS:SI and ES:DI
by
incrementing SI and DI if DF
is
0 or
by
decrementing
SI
and DI if
DF
is
l.
5.
Decrement CX (this step does not affect the flags).
6.
For SCAS (Scan String) and CMPS(Compare String), check
ZF
for a match with the repeat
condition and stop repeating if the
ZF
fails
to
match.
The Load
String and Store String instructions allow a program
to
perform arithmetic or logical opera-
tions
on
string characters (using AX for word strings and AL for byte strings). Repeated operations
that include instructions other than string primitives must use the loop instructions rather than a repeat
prefix.
3.7.2.1 STRING MOVEMENT INSTRUCTIONS
REP
(Repeat While
CX
Not Zero) specifies a repeated operation of a string primitive. The REP prefix
causes the hardware
to
automatically repeat the associated string primitive until CX=O. This form of
iteration allows the
CPU
to
process strings much faster than would be possible with a regular software
loop.
When the
REP prefix accompanies a MOVS instruction, it operates
as
a memory-to-memory block
transfer.
To
set up for this operation, the program must initialize CX and the register pairs DS:SI and
ES:DI. CX specifies the number of bytes or
words
in the block.
If
DF=O, the program must point DS:SI
to
the first element of the source string and point ES:DI to
the destination address for the first element.
If
DF=
1,
the program must point these
two
register pairs
_
to
the last element of the source string and
to
the destination address
forthe
last element, respectively.
Example:
REP MOVSW. The processor checks the value in CX for zero.
If
this value
is
not zero,
the processor
moves
a word from the location pointed
to
by
DS:SI
to
the location pointed
to
by ES:DI and increments SI and DI
by
two
(if DF=O). Next, the processor decrements
CX by one and returns
to
the beginning of the repeat cycle
to
check CX again. After CX
decrements
to
zero, the processor executes the instruction that
follows.
MOVS
(Move String)
moves
the string character pointed
to
by
the combination of DS and
SI
to
the
location pointed
to
by
the combination of ES and DI. This
is
the only memory-to-memory transfer
supported
by
the instruction set of the base architecture. MOVSB operates
on
byte elements. The
destination segment register cannot
be
overridden
by
a segment override prefix while the source segment
register can be overridden.
Example:
MOVSW. Moves the contents of the memory byte pointed
to
by
DS:SI to the location
pointed to by
ES:DI.
3.7.2.2
OTHER STRING OPERATIONS
CMPS
(Compare Strings) subtracts the destination string element (ES:DI) from the source string
element
(DS:SI) and updates the flags AF, SF, PF, CF and OF.
If
the string elements are equal,
ZF=
1;
otherwise, ZF=O.
If
DF=O, the processor increments the memory pointers (SI and DI) for
the
two
strings. The segment register used for the source address can
be
changed with a segment
override prefix, while the destination segment register cannot
be
overridden.
Example:
CMPSB. Compares the source and destination string elements with each other and returns
the result of the comparison
to
ZF.
3-23