When are the carry flags set by x86 negation (NEG) / subtraction (SUB)?

assembly, carryflag, eflags, x86

Solution

You could view `NEG a` as equivalent to `SUB 0, a`. If `a` is non-zero, then this will set the carry flag (as this will always result in an unsigned overflow).

Problem

What is meant by "Applying the NEG instruction to a nonzero operand always sets the Carry flag." Why does substracting 2 from 1 set the carry flag? ``` 00000001 (1) + 11111110 (-2) [in 2-complement form] --------------------- CF:1 11111111 (-1) [ why is the carry flag set here???] ```

Original source

Related problems