0% found this document useful (0 votes)
53 views17 pages

Integer Arithmetic: Chapter 10, Section 10.3

The document discusses integer arithmetic operations performed by the arithmetic logic unit (ALU) such as addition, subtraction, and overflow handling. It explains how binary addition and subtraction are performed, including carry-in, carry-out, and how to detect overflow for both unsigned and two's complement number representations. Practice problems are provided to help understand overflow conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views17 pages

Integer Arithmetic: Chapter 10, Section 10.3

The document discusses integer arithmetic operations performed by the arithmetic logic unit (ALU) such as addition, subtraction, and overflow handling. It explains how binary addition and subtraction are performed, including carry-in, carry-out, and how to detect overflow for both unsigned and two's complement number representations. Practice problems are provided to help understand overflow conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

14.

Integer Arithmetic

Chapter 10, section 10.3

Spring 2016 CS430 - Computer Architecture 1


Arithmetic Logic Unit

• The ALU performs


arithmetic and logical
operations on data

• All other elements …


control unit, registers,
memory, I/O mainly bring
data to ALU for
processing and then take
the results back

Spring 2016 CS430 - Computer Architecture 2


ADDITION

Spring 2016 CS430 - Computer Architecture 3


Binary Addition

 In general, we know the following is true:

0 + 0 = 0 0
0 + 1 = 0 1
1 + 0 = 0 1
1 + 1 = 1 0

Spring 2016 CS430 - Computer Architecture 4


Integer Addition

 Perform the following addition and interpret the


result in:
a. Unsigned numbers
b. Two's complement notation

1100
+ 0001
----

Spring 2016 CS430 - Computer Architecture 5


Carry-in & Carry-out

 Consider the following:


00001111
+01010101
--------

1. What is the carry-in and carry-out of bit 3 (bit


numbering starts at bit 0)
2. The carry-out of the MSB during an addition is the
value of the external carry in the flags register for an
addition
3. What is the external carry for the above example?

Spring 2016 CS430 - Computer Architecture 6


SUBTRACTION

Spring 2016 CS430 - Computer Architecture 7


Binary Subtraction

 In general, we know the following is true:

0 - 0 = 0
0 - 1 = borrow!
1 - 0 = 1
1 - 1 = 0
10 - 1 = 1

Spring 2016 CS430 - Computer Architecture 8


Subtraction of Unsigned Numbers

 Perform the following subtraction:


00110011 (Minuend)
-00001111 (Subtrahend)
--------
1. Before performing the subtraction, identify the two
numbers being subtracted. Assume the numbers are
represented as unsigned numbers.
2. Perform the subtraction.
3. Interpret the result. Is it what you would expect it to
be?

Spring 2016 CS430 - Computer Architecture 9


Subtraction

• Subtraction is
performed by taking
the two's
complement of the
subtrahend and
adding this value to
the minuend.

Spring 2016 CS430 - Computer Architecture 10


Subtraction of 2’s Complement
Numbers
 Perform the following subtraction:
00110011 (Minuend)
-00001111 (Subtrahend)
--------
1. Before performing the subtraction, identify the two
numbers being subtracted. Assume the numbers are
represented in 2’s complement.
2. Perform the subtraction.
3. Interpret the result. Is it what you would expect it to
be?

Spring 2016 CS430 - Computer Architecture 11


OVERFLOW

Spring 2016 CS430 - Computer Architecture 12


Arithmetic Overflow

 Remember that the range of values that can be


represented using 8-bits for:
 Unsigned numbers is 0 to 255
 Two's complement is -128 to 127.

 The microprocessor will perform the addition or


subtraction of two numbers, but the question is how
do we know if the result is correct?
 The answer lies with two flags: (a) the external carry
flag and (b) the overflow flag.
 First we will define overflow as a condition such that
an arithmetic operation produces a result outside the
range of the number system being used.

Spring 2016 CS430 - Computer Architecture 13


Overflow Detection

• Unsigned Numbers:
– When there is a carry out of the MSB (external carry)

• 2’s Complement:
– If two numbers are added, and they are both positive or
both negative, then overflow occurs if and only if the
result has the opposite sign

– There will never be an overflow when adding two


numbers of opposite signs

– The carry out of the MSB does not necessarily indicate


an overflow

Spring 2016 CS430 - Computer Architecture 14


Arithmetic Overflow

 Perform the operations below and interpret the


result in:
1. Unsigned numbers
2. Two's complement notation
11111111 01111111
+00000001 +00000001
-------- --------
 Were there any examples of overflow? Identify
each case and briefly explain why.

Spring 2016 CS430 - Computer Architecture 15


Geometric Depiction of 2’s
Complement Numbers

Spring 2016 CS430 - Computer Architecture 16


Practice

• Let's perform the following operations and determine where


any overflows occurred for both unsigned and 2’s complement
representations.

1001 1100
+0101 +0100
----- -----

0011 1100
-0100 -1111
----- -----

1000 1000
+0001 -0001
----- -----

Spring 2016 CS430 - Computer Architecture 17

You might also like