
Instruction Set
4-30
CLD
CLD
This example copies one string of 16-bit integers in memory to another string 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 one of the string instructions (CMPS, INS, LODS, MOVS, OUTS, SCAS, or
STOS), always set up CX with the length of the string, and use CLD (forward) or STD
(backward) to establish the direction for string processing.
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
Compare a component in one string with a component in another string
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 one string in memory to another string in memory
Copy a component from a string in main memory to a port in I/O memory
Compare a string component located in memory to a register
Process string components from higher to lower addresses
Copy a component from a register to a string in memory
See
CMPS
INS
LODS
MOVS
OUTS
SCAS
STD
STOS
; defined in SEG_1 segment
SOURCE
DEST
DW
DW
350,-4821,-276,449,10578
5 DUP ()
; direct assembler that DS and ES point to
; the same segment of memory
ASSUME
DS:SEG_1, ES:SEG_1
; set up DS and ES with same segment address
MOV
AX,SEG_1
MOV
DS,AX
MOV
ES,AX
; copy data segment to AX
; copy AX to DS
; copy AX to ES
; 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