
Instruction Set
4-159
MOV S
MOV S
This example copies one string of 16-bit integers stored in memory to another string located
in the same segment. Because the Direction Flag (DF) is cleared to 0 using CLD, the
microcontroller copies the words, one by one, from first to last.
T ips
Before using MOVS, always be sure to: set up SI with the offset of the source string and
DI with the offset of the destination string, set up CX with the length of the strings, and use
CLD (forward) or STD (backward) to establish the direction for string processing.
To copy one string to another, use the REP prefix to execute MOVS repeatedly.
To fill a string with a pattern, use MOV to: copy each component of the pattern to the first
several components in the string, load SI with the offset of the string, load DI with the offset
of the first component in the string that is not part of the pattern, load CX with the length of
the string less the number of components in the pattern, and then use the REP prefix to
execute MOVS repeatedly.
The string instructions always advance SI and/or DI, regardless of the use of the REP prefix.
Be sure to set or clear DF before any string instruction.
Related Instruc tions
If you want to
Process string components from lower to higher addresses
Copy a component from a port in I/O memory to a string in main memory
Copy a component from a string in memory to a register
Copy a component from a string in main memory to a port in I/O memory
Process string components from higher to lower addresses
Copy a component from a register to a string in memory
See
CLD
INS
LODS
OUTS
STD
STOS
; defined in SEG_Z segment
SOURCE
DEST
DW
DW
350,-4821,-276,449,10578
5 DUP ()
; copy one string to another in the same segment
; direct assembler that DS and ES point to
; the same segment of memory
ASSUME
DS:SEG_Z, ES:SEG_Z
; set up DS and ES with same segment address
MOV
AX,SEG_Z
MOV
DS,AX
MOV
ES,AX
; load segment into DS and ES
; DS points to SEG_Z
; ES points to SEG_Z
; set up registers and flags
LEA
SI,SOURCE
LEA
DI,DEST
MOV
CX,5
CLD
; load source offset (segment = DS)
; load dest. offset (segment = ES)
; set up counter
; process string low to high
; copy source string to destination string
MOVSW
REP