Direction flag explained

The direction flag is a flag that controls the left-to-right or right-to-left direction of string processing,[1] stored in the FLAGS register on all x86-compatible CPUs.[2] It is bit number 10.

This flag is used to determine the direction ('forward' or 'backward') in which several bytes of data will be copied from one place in the memory, to another. The direction is important mainly when the original data position in memory and the target data position overlap.

x86-instructionMeaningFlag Notes
Direction of string processingMode title
CLDclear direction flag 0lowest-to-highest addressauto-incrementing
STDset direction flag 1highest-to-lowest addressauto-decrementing

Notes and References

  1. http://www.logix.cz/michal/doc/i386/chp03-08.htm 3.8.1 Carry and Direction Flag Control Instructions
  2. https://docs.microsoft.com/en-us/cpp/c-runtime-library/direction-flag Direction Flag