Lecture 4
Computer Arithmetic
Part I: Integers
1
In this lecture:
Integer Representations
Integer Arithmetic
2
Chapter1 Review
1. What are the basic components of a computer?
2. List some computer performance improvement
techniques
3. What are the two basic stages (steps) of
instruction cycle?
4. List some common registers inside CPU
5. List at least two characteristics of a von Neumann
machine
3
Computer Arithmetic
ALU performs arithmetic and logic
operations
Arithmetic operations are performed on:
Integers
Floating point numbers
4
Integer representation
Unsigned number representation
Q. What is the range of unsigned integer
numbers that can be represented with 8 bits?
Signed number representation
Sign-magnitude
2s complement---> used in computers
5
Integer representation cntd
Q. Convert the following decimal representations
into 2s complement representations . Use 8 bits.
i) 20
ii) -20
Why use 2s complement representation?
Simpler arithmetic circuits
6
Integer Arithmetic
Addition (signed)
Q. Compute using 2s complement representation (use 4 bits)
i) 3+4
ii) -4+5
iii) 7+5
iv) (-4) +(-5)
Overflow will not occur if two numbers added have opposite signs.
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.
Subtraction (signed)
A B = A+(-B) (find the negative equivalent of B then add with A)
7
Adder/Subtractor Unit
Register B Register A
Complementer
SW
OF Adder SW: Selects between addition
and subtraction
Register C OF: Indicates whether an
overflow occurred
8
Integer Multiplication
Unsigned integers
e.g. 1011 Multiplicand
We can store the partial
products and then add them
1101 Multiplier to find the product
But large number of registers
00001011 are required as no. of bits
000 0000 0 Partial products
increases (e.g. 32 registers
00 1011 00 for 32 bits)
Better approach is to add the
01011 000 partial products as we go
10001111 Product
9
Integer Multiplicationcntd
Important observations
When the multiplier bit is 0, the partial product is 0.When the multiplier is 1, the
partial product is the multiplicand
Each successive partial product is shifted one position to the left relative to the
preceding partial product
The multiplication of two n-bit binary integers results in a product of up to 2n-
bits in length
We can use successive add and shift operations to find the
product
10
Method 1
Start
Product(P) -> 2n-bits
=1 Test LSB of =0 Multiplicand(M) ->
multiplier 2n-bits
Multiplier(Q) -> n-bits
Product = product +
multiplicand
Initially P=0 and upper
Shift multiplicand 1 bit to the left
n bits of M are 0
Shift multiplier 1 bit to the right
nth NO
repetition ?
YES
Done 11
Method 1cntd
e.g. 1011 X 1101
Multiplier (Q) Multiplicand (M) Product (P) Initial Values
1101 00001011 00000000
1101 00001011 00001011 P=P+M
1 1101 00010110 00001011 Shift M left
0110 00010110 00001011 Shift Q right
0110 00101100 00001011 Shift M left
2
0011 00101100 00001011 Shift Q right
0011 00101100 00110111 P=P+M
0011 01011000 00110111 Shift M left
3
0001 01011000 00110111 Shift Q right
12
Method 1cntd
0001 01011000 10001111 P=P+M
4 0011 10110000 10001111 Shift M left
0000 10110000 10001111 Shift Q right
13
Method 2
A -> n-bits
C -> 1-bit
Multiplicand (M) -> n-bits
Multiplier (Q) -> n-bits
P=A:Q
14
Method 2cntd
e.g. 1011 X 1101
15
Method 2cntd
16
Method 2cntd
Exercise
Compute using method 2
i) 1000 X 1010
ii) 110 X 111
Faster multiplication
Calculate partial products in parallel
Need more components
17
Next Class
Signed integer multiplication
Floating-point representation/arithmetic
18
More Readings
1. Computer Architecture and Organization,
William Stallings, 8th edition (chapter 9)
2. Computer Organization and Design, David A.
Patterson, 4th edition (section 3.3)
19