-2
STC
MOV AL, 5
SBB AL, 3 ; AL = 5 - 3 = 2, but I am getting 1 .. why?
RET 
4
  • 3
    Read carefully the description of the SBB instruction, paying particular attention to how the carry flag is used. Oct 4 at 14:24
  • Have you tried both with the carry flag set to 0 and with it set to 1?
    – OmarL
    Oct 4 at 14:32
  • 5
    I’m voting to close this question because it shows distinct lack of background research.
    – introspec
    Oct 4 at 14:53
  • I'm voting to reopen the question because asking people why something is broken is research.
    – JeremyP
    Oct 9 at 8:53
4

It's quite simple really. sbb is "subtract with borrow". It uses the CPU carry flag as the borrow flag. stc sets the carry flag, which means that sbb thinks there is a borrow and, instead of subtracting three from five, it subtracts four from five.

In this respect, the 8086 is the opposite of some other processors, notably the 6502 where c=0 means there is a borrow, and c=1 means there isn't a borrow.

1
  • Thank you for your answer, and the great explanation
    – B.T.
    Oct 9 at 2:35
1

Contrary to the 6502 which inverts the carry as borrow, 8086 does not.

Not the answer you're looking for? Browse other questions tagged or ask your own question.