0

Quick question, why is the SF being set if the number is positive?

mov al,124
    add al,5     ;CF=0,SF=1,ZF=0,OF=1 
                 ;Carry flag - not set (no carry out of the most significant (leftmost) bit) 
                 ;Sign flag - set (???)
                 ;Zero flag - not set (destination not zero), 
                 ;overflow flag - set (value is not in the range of signed values for a byte)
    call dumpRegs
Jester
  • 56,577
  • 4
  • 81
  • 125
FlipFlopSquid
  • 99
  • 1
  • 4
  • 11
  • 3
    You need to read about 2's complement arithmetic. Plenty of material all over the place. Long story short, the sign bit is the most significant bit, and `124+5=129` has the MSB set. Alternatively, obviously the sign bit only makes sense in signed arithmetic, and in that case the result is actually `-127` so it's negative. – Jester Feb 28 '15 at 00:08
  • 1
    @Jester You should make that an answer. –  Feb 28 '15 at 00:12
  • Trust me I have read tons and I'm very aware. I'm not using a signed data type though?? – FlipFlopSquid Feb 28 '15 at 00:13
  • No this is not a duplicate, I viewed that post before this and read it in its entirety. – FlipFlopSquid Feb 28 '15 at 00:14
  • 1
    the resulting number is not positive. you overflowed and wrapped around! – thang Feb 28 '15 at 00:17
  • 4
    There is no signed and unsigned integer datatype in x86 asm. I think [this is the best illustration](http://stackoverflow.com/questions/23990071/sign-carry-and-overflow-flag-assembly) I will mark as duplicate if you agree. – Jester Feb 28 '15 at 00:20
  • @FlipFlopSquid Yes it is a duplicate, you just still don't understand it. As Jester suggest you should read about 2's complement. – m0skit0 Feb 28 '15 at 00:26
  • This is a duplicate of the one @Jester posted with the clock – FlipFlopSquid Feb 28 '15 at 00:30

0 Answers0