'How does subtracting 0x1 - 0x80000000 cause an overflow?

  MOV   R0, #0x80000000 
  MOV   R1, #0x1 
  SUBS  R2, R1, R0

Upon Running this code, Flag N and Z are set. Now, I know N flag is set if the operation results in a negative result and Z flag is set when there is an overflow.

The thing I don't understand is that how does 0x1 - 0x80000000 causes overflow. Any help is appreciated!



Solution 1:[1]

Consider extending the two numbers to 36 bits. 1 is still 1, of course. 80000000 becomes f80000000. 1 - f80000000 = 080000001, a positive number. Since 080000001 doesn't fit in 32 bits as a positive number, there is overflow.

Solution 2:[2]

    1
 1000 
+1110
======

10001
 1000 
+1110
======
 0111

carry in and carry out of msbit are not the same...signed overflow.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 old_timer