The STD and CLD instructions
Setting and clearing the direction flag DF.
The STD instruction format
| Instruction | Description |
|---|---|
| STD | Set the direction flag (DF = 1). |
The CLD instruction format
| Instruction | Description |
|---|---|
| CLD | Clear the direction flag (DF = 0). |
These instructions control the direction flag DF, which determines the direction in which string instructions (MOVS, CMPS, SCAS, LODS, STOS) process their operands. When DF=0, the addresses are incremented (processing goes from lower addresses to higher ones). When DF=1, the addresses are decremented (processing goes from higher addresses to lower ones).
Usage example
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the code segment cld ; DF = 0, the strings will be processed forward (from lower addresses to higher ones) std ; DF = 1, the strings will be processed backward (from higher addresses to lower ones) mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Processor status flags
CF
NoPF
NoAF
NoZF
NoSF
NoTF
NoIF
NoDF
YesOF
No