You are on page 1of 2

Discussion unit 3

In your implementation of the ALU there is no need to detect or handle overflow. However, it's
a good mental exercise to think about when/how an overflow might occur. When adding
numbers with different signs, overflow cannot occur because the sum must be no larger than one
of the numbers.

What happens when the signs of the numbers are the same?

If 2 Two's Complement numbers are added, and they both have the same sign (both
positive or both negative), then overflow occurs if and only if the result has the
opposite sign. Overflow never occurs when adding operands with different signs.

i.e. Adding two positive numbers must give a positive result


Adding two negative numbers must give a negative result

Overflow occurs if

 (+A) + (+B) = −C
 (−A) + (−B) = +C

Example: Using 4-bit Two's Complement numbers (−8 ≤ x ≤ +7)


(−7) 1001
+(−6) 1010
------------
(−13) 1 0011 = 3 : Overflow (largest −ve number is −8)

What happens in the case of subtraction?

If 2 Two's Complement numbers are subtracted, and their signs are different, then
overflow occurs if and only if the result has the same sign as the subtrahend.

Overflow occurs if

 (+A) − (−B) = −C
 (−A) − (+B) = +C

Example: Using 4-bit Two's Complement numbers (−8 ≤ x ≤ +7)


Subtract −6 from +7
(+7) 0111 0111
−(−6) 1010 -> Negate -> +0110
---------- -----
13 1101 = −8 + 5 = −3 : Overflow

How do we detect when an overflow does occur?

Representation of overflow with signed numbers.

Alternative approach: Overflow can be identified and detected using a different mechanism, but, of
course, keeping intact the fundamental requirements as mentioned above in conclusions (1) and (2).
This means that overflow may occur if the two numbers being added are of the same sign. Numbers
having different sign when added will not give rise to any overflow, because the result after addition
will produce a result which will be always smaller than the larger of the two original numbers. To
explain and exhibit the overflow, consider the following examples of 8-bit addition, as shown in
Figure 7.3, with 8-bit signed integers in 2's complement form in which the most significant bit in
each binary number is the sign bit. (ebrary)

Reference
https://www.doc.ic.ac.uk/~eedwards/compsys/arithmetic/index.html
https://ebrary.net/206259/computer_science/addition_subtraction_signed_numbers

You might also like