In: Computer Science
When adding two signed binary numbers , what does it mean when unsigned overflow has occured?
What is the result of subtracting 1000 from 0001? What, if any, overflows would occur?
Overflow Flag:
The overflow flag is a single bit status register that indicates the overflow when the arithmetic operation occurred.
Explanation:
When the sign of two additional operands is different then overflow never occurs.
A negative result out of positive operands (or vice versa) is an overflow.
The overflow flag is thus set when the most significant bit (here considered the sign bit) is changed by adding two numbers with the same sign.
The overflow flag is relevant when we are calculating the sum of two signed numbers but it is not relevant to the unsigned number addition.
The overflow flag is turned on in two cases as given below:
For example:
0101 + 0100 = 1001 #signed overflow flag is turned on
1001 + 1100 = 0101 #signed overflow flag is turned on
If the carry out of the MSB then carry flag is on but not the overflow flag.
What is the result of subtracting 1000 from 0001? What, if any, overflows would occur?
Let us suppose operands are the unsigned numbers.
To perform the subtraction by addition, we need to perform the 2's complement.
The 2's complement of the subtrahend is: 1000
Now perform the addition operation:
0001 + 1000 = 1001
There is no overflow. So the result is 1001 and it is in 2's complement form.
The final result is(-): 0111