The context
I read in a textbook that...
An addition and subtraction cannot cause overflow. To quote,
"An overflow cannot occur after an addition if one number is positive and the other negative, since adding a positive number to a negative number produces a result who magnitude is smaller(...)".
However, by going through some problems it didn't seem to be the case and I want to confirm what I calculated isn't some mistake.
For example a context in which this applies, for a 4-bit adder-subtractor where M=1 (this means subtraction with B), A = 0101 (+5) and B = 1010 (+10).
By taking the 2s complement of B = 0110 (-10) and adding the numbers, the subtraction could be made.
e.g (5)+(-10)
0 1
+5 0101
-10 0110
-------------
result: 1011
results 2s: 0101 (-5)
C: 0 and V = 1.
A couple of questions already arise just by performing this problem.
- The overflow bit is set despite the fact there is no overflow (number is in range)
- Given that the range is -8 to 7, wouldn't a signed integer and unsigned integer also cause overflow e.g. (-1+9)
e.g
-1 1110
+9 1001
-------------
result: 1111
result 2s: 0001 (1)
C: 1 and V: 1
I noticed that when C = 0 there is no overflow and when C = 1 there is a overflow.
I read that the overflow relationship between two unsigned integer is the V overflow flag. On the other hand, the overflow relationship between two signed integer is related to the C carry flag. Could this be related?
Finally, notice that there is overflow between an unsigned and signed integer despite the statement I quoted contradicts that.
TL;DR
Is overflow between the addition of an unsigned integer and signed integer possible? If so, what would the relationship an unsigned integer and signed integer be for overflow (C or V flag)?