X86 direction flag

I can’t understand how the direction flag in works x86. The text in my lectures says that it increases either the decrements of the source or destination register , but this does not make sense with his name. Can someone explain what he is doing?

+6
source share
2 answers

This flag is used in string operations and indicates whether strings start at a low address and go to higher addresses or vice versa.

For string instructions, it ECXhas a number of iterations, DS:ESIhas a source address, and ES:EDIa destination (therefore, s in ESIand d in EDI).

After each iteration, it ECXdecreases by one, and ESIit EDIeither increases or decreases by the size of the element (1 for operations with bytes, 2 for operations with text, etc.) in accordance with EFLAGS.DF.

If EFLAGS.DF 0, ESIand EDIincrease, otherwise they decrease.

+7
source

Take rep movsbfor example instructions that depend on the direction flag.

rep movsb, esi, edi ecx. . ( ) esi edi , , . rep movsb, , .

, . , , , . , , , .

+4
source

All Articles