0

Hello so I have a question about the flag register in x86. How do I know when the CF/OF is 1 or 0.

AX: FFE4 decimal: -28
DX: 0002 decimal:   2
                  -56 = -28 x 2
DX:FFFF
AX:FFC8
OF/CF: 0 
Binary 11111111111111111111111111001000

Do I look at the most signficant bit? If so would the OF/CF would be 1?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Check the `(E)FLAGS` register with `JC label`/`JNC label`/`JO label`/`JNO label`. The former two jump on CARRY set/not set and the latter two on OVERFLOW set/not set. But the (E)FLAGS have to be the result of an arithmetic instruction and not just a load=MOV which doesn't set the (E)FLAGS). – zx485 Apr 13 '20 at 17:27
  • https://en.wikipedia.org/wiki/FLAGS_register - CF is the lowest bit in EFLAGS. You can read it programmatically with `setc al`, or just use a debugger that can decode FLAGS for you. – Peter Cordes Apr 13 '20 at 18:00
  • 1
    From the SDM: “The CF and OF flags are set when the signed integer value of the intermediate product differs from the sign extended operand-size-truncated product, otherwise the CF and OF flags are cleared.” – prl Apr 13 '20 at 18:08
  • Also from the SDM: “For the one operand form of the instruction, the CF and OF flags are set when significant bits are carried into the upper half of the result and cleared when the result fits exactly in the lower half of the result. For the two- and three-operand forms of the instruction, the CF and OF flags are set when the result must be truncated to fit in the destination operand size and cleared when the result fits exactly in the destination operand size.” – prl Apr 13 '20 at 18:09

0 Answers0