-1

I found out if I add two numbers in assembly and their sum is 0, CF is set equal to one. In other cases not. I don't understand why. Any ideas please? Example:

        __asm {
        mov eax, 0
        mov ebx, 5
        mov edx, -5
        add ebx, edx
        adc eax, 0
    }

result 1

old_timer
  • 69,149
  • 8
  • 89
  • 168
Jozko
  • 85
  • 1
  • 11
  • 1
    https://stackoverflow.com/questions/19301498/carry-flag-auxiliary-flag-and-overflow-flag-in-assembly and https://stackoverflow.com/questions/791991/about-assembly-cfcarry-and-ofoverflow-flag. Long story short, if you are considering your values signed the carry flag doesn't really mean much. – Matteo Italia May 01 '18 at 18:15

1 Answers1

2

I think it answers itself, just a twos complement thing...The carry flag does more than just tell you if you have an unsigned overflow.

 00000101
+11111011
===========

111111110       
 00000101
+11111011
===========
 00000000

subtraction works out the same 5 - 5:

111111111       
 00000101
+11111010
===========
 00000000

you can see in both cases there is no signed overflow

UNSIGNED math though this is 0xFB + 0x05 = 0x100 which is an unsigned overflow, thus the flag.

old_timer
  • 69,149
  • 8
  • 89
  • 168
  • I accidentally used 8 bits there just wanted to be at least 4 or more. 800 bits or 8 or 80 or 32, it all works out the same as you can see... – old_timer May 01 '18 at 18:15