0

If %rax = 0x0000 0000 0000 0000
then subq $1, %rax generates CF=1?

My csapp lecture note says it does, but i don't understand why. I thought CF only occurs when there is carry out.

Could you explain why there is a CF?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Jinwoo Park
  • 99
  • 1
  • 10
  • 1
    SUB sets CF as a borrow output, with a `1` propagating to higher bits. So yes there is carry out. e.g. 0-1 = all bits set no matter how wide an integer you use. . [When are the carry flags set?](//stackoverflow.com/a/29329713) has more detail, still looking for another more similar question. – Peter Cordes Sep 23 '19 at 03:08
  • In general not specific to x86, the output of the adder (a subtract you invert the second operand and set the msbit carry in) is sometimes simply a carry out as is and some architectures invert it and consider it a borrow flag. So you have to know what a specific architecture does with it which of course is not always obvious you have to either look at the subtract with borrow instruction or more likely the conditional branch instructions and figure it out. – old_timer Sep 23 '19 at 17:41

0 Answers0