
40
Chapter 3: General-Purpose Programming
AMD 64-Bit Technology
24593—Rev. 3.09—September 2003
resulted in a carry (for addition) or a borrow (for subtraction)
out of bit 3. Otherwise, hardware clears the flag to 0.
The main application of this flag is to support decimal
arithmetic operations. Most commonly, this flag is used
internally by correction commands for decimal addition (AAA)
and subtraction (AAS).
Zero Flag (ZF).
Bit 6. Hardware sets the zero flag to 1 if the last
arithmetic operation resulted in a value of zero. Otherwise (for
a non-zero result), hardware clears the flag to 0. The compare
and test instructions also affect the zero flag.
The zero flag is typically used to test whether the result of an
arithmetic or logical operation is zero, or to test whether two
operands are equal.
Sign Flag (SF).
Bit 7. Hardware sets the sign flag to 1 if the last
arithmetic operation resulted in a negative value. Otherwise
(for a positive-valued result), hardware clears the flag to 0.
Thus, in such operations, the value of the sign flag is set equal
to the value of the most-significant bit of the result. Depending
on the size of operands, the most-significant bit is bit 7 (for
bytes), bit 15 (for words), bit 31 (for doublewords), or bit 63 (for
quadwords).
Direction Flag (DF).
Bit 10. The direction flag determines the order
in which strings are processed. Software can set the direction
flag to 1 to specify decrementing the data pointer for the next
string instruction (LODSx, STOSx, MOVSx, SCASx, CMPSx,
OUTSx, or INSx). Clearing the direction flag to 0 specifies
incrementing the data pointer. The pointers are stored in the
rSI or rDI register. Software can set or clear the flag with the
STD and CLD instructions, respectively.
Overflow Flag (OF).
Bit 11. Hardware sets the overflow flag to 1 to
indicate that the most-significant (sign) bit of the result of the
last signed integer operation differed from the signs of both
source operands. Otherwise, hardware clears the flag to 0. A set
overflow flag means that the magnitude of the positive or
negative result is too big (overflow) or too small (underflow) to
fit its defined data type.
The OF flag is undefined after the DIV instruction and after a
shift of more than one bit. Logical instructions clear the
overflow flag.