Direction Flag in x86
assembly, eflags, microprocessors, x86
Solution
This flag is used in string operations, and specifies if strings begin at a low address and proceed to higher addresses or vice versa.
For string instructions, `ECX` has the number of iterations, `DS:ESI` has the source address and `ES:EDI` has the destination (hence the s in `ESI` and the d in `EDI`).
After each iteration, `ECX` is decremented by one, and `ESI` and `EDI` are either incremented or decremented by the element size (1 for byte operations, 2 for word operations etc) according to `EFLAGS.DF`.
If `EFLAGS.DF` is `0`, `ESI` and `EDI` are incremented, otherwise they're decremented.
Problem
I am unable to understand how does the direction flag work in `x86`. The text in my lectures say that it increments or decrements the source or destination register but that does not make sense with its name. Can someone explain what it does?