You are on page 1of 40

10.

Computer Arithmetic

Chapter 10

Computer Arithmetic

Four types of data for add, subtract,


multiply, divide
1. Fixed-point binary data
in signed-magnitude representation
2. Fixed-point binary data
in signed-2s complement representation
3. Floating-point binary data
4. Binary-Coded Decimal(BCD) data

1
Add
(+3) + (+2)
(+6) + (3)
(3) + (+2)
(3) + (6)
(+3) (+2)
(+3) (6)
(3) (+2)
(3) (6)

Subtract

1
Flowchart for add and subtract
operations
(signed magnitude representation)

A-B
A + B + 1
= A - B + 2n
( B + B + 1 = 2n)
If A B
If A < B

2n(E = 1)
E=0

A<B

EA A B

A
2

(+3) + (2)
(+3) + (+6)
(+3) (2)
(3) (6)

10-3 Multiplication Algorithms


23
19
------

10111 Multiplicand
x 10011 Multiplier
----------10111
10111
00000
00000
10111
-------------------

437

110110101

1
AQ B x Q for multiplication

10111
x 10011
-----------

1 0 1 1 1

10111
10111
00000
00000
10111
-------------------

110110101

0 0 0 0 0
1 0 1 1 1
0 1 0 1 1

1 0 0 1 1
1 1 0 0 1

1
Booth Multiplication Algorithm
Multiplication with
binary integers
in signed-2s complement representation
Ex) (-9) x (-13) = + 117

1
(-9) x (-13) = + 117
BR = 10111(-9)
BR + 1 = 01001
QR = 10011(-13)

(-9) x (-13) = + 117


BR = 10111(-9)
BR + 1 = 01001
QR = 10011(-13)
QnQn+1 1001 10
10 - : -1
11
01
+ : +4
00
10
- : -16
-13

Proof of the Booth Algorithm


111111111 = -1
10 = -1
111011111
10
01
10
111001111
10
01
10

= - 25 1
= - 20
= + 25
= - 26 - 25 1
= - 25 24- 1 = - 49
= - 20
= + 24 = 16
= - 26 = - 64 - 49

Proof of the Booth Algorithm


If the number is 1, it adds 1, which is the same as the Booth algorithm.
If there is a 0 in the position 2k then it adds 2k .
Also, the Booth algorithm adds 2k 2k+1, which is 2k.
k
543210
111..1111111101111..111111 = - 000..0000000010000..000001
k+m-1
If there is m 0s from the position 2k then it adds 2l
l=k
k+m-1 k
543210
111111100.0011111111111 = - 000000011.1100000000001
Also, the Booth algorithm adds 2k 2k+m, which is
k+m-1 k
543210
k+m-1
k+m-1
000000011.1100000000000
- 2l because ( 2l + 2k ) = -2k+m + 000000000.0100000000000
l=k
l=k
.
000000100.0000000000000

b3

b2 b1 b0
a2 a1 a0
--------------------------------------------a0b3 a0b2 a0b1 a0b0
a1b3 a1b2 a1b1 a1b0
a2b3 a2b2 a2b1 a2b0

1
Q AQ / B for division
AQ B x Q for multiplication

Subtraction
Addition

multiplication
division

1
Flowchart for divide operation
(signed magnitude representation)
Q AQ / B
AQ AB Overflow ,
EA A + B:
A
Q
1 0 1 0
0 1 1 0
B
0 0 1 1
A<B shl EAQ
E=1 EA > B
1

n-1

(EA 2n-1) + (2n-1 B) = EA B

Addition and Subtraction


of floating-point operands
1.
2.
3.
4.

Check for zeros


Align the mantissas
Add or subtract the mantissas
Normalize the result

10001

1 0 0 1

0 0 0 1 0 1 1
1 0 1 0 1

1 0 1 1

1
A x 2 a A x 2a B x 2 b
AC
BR

Figure 10-15
Addition and subtraction of
floating-point numbers
Align mantissas :
A< B

A B

Mantissa addition and subtraction :


Fig. 10-2 signed magnitude

A B

Check for zeros: A


Normalization: A1 = 1 shift
1

n-1

AC

Multiplication of
floating-point numbers
1.
2.
3.
4.

Check for zeros


Add the exponents
multiply the mantissas
Normalize the product

1
A x 2a
B x 2b x Q x 2 q

Figure 10-16
Flowchart for multiplication of
floating-point numbers
: - max1 ~ + max2
0 ~ + max2 + bias
Ex) 5 bit : - 16 ~ + 15 0 ~ + 31
a = a + bias(16 in this example)
b = b + bias
a + b = a + b + 2 x bias
0.1 x 0.1 = 0.01

Division of
floating-point numbers
1.
2.
3.
4.
5.

Check for zeros


Initialize registers and evaluate the sign
Align the dividend
Subtract the exponents
Divide the mantissas

Q x 2q
A x 2a / B x 2b

Figure 10-17
Flowchart for division of
floating-point numbers
Overflow check
If E = 1 then A B
A

1 0 1 0 0 1 1 0
B

1 0 0 1
shr A a a+1
Fig. 10-13
divide magnitude of mantissa
overflow .
a - b = a + bias (b + bias)
a a + bias

1
Table 10-4
Derivation of
BCD Adder
: 0
: 9+9+1=19
0
1
0
9
+ 0
+ 9
-------- ----------0
19
C = k + Z8Z4 + Z8Z2

C = k + Z8Z4 + Z8Z2

1
BCD 9s complementer
M B8 B4 B 2 B1
0 0 0 0 0
0 0 0 0 1
0 0 0 1 0
.
.
0 1 0 0 0
0 1 0 0 1
1 0 0 0 0
1 0 0 0 1
1 0 0 1 0
.
.
1 1 0 0 0
1 1 0 0 1

x8 x4 x2 x1
0 0 0 0
0 0 0 1
0 0 1 0

X1 = B1 M + B1 M
X2 = B2
X4 = B4 M + (B4 B2 + B4 B2 ) M
X8 = B8 M + B8 B4 B2 M

1
1
1
1
0

0
0
0
0
1

0
0
0
0
1

0
1
1
0
1

0 0 0 1
0 0 0 0

X1 = B2 M + B1 M
X2 = B2
X4 = B4 M + (B4 B2 + B4 B2 ) M
X8 = B8 M + B8 B4 B2 M

1
8 6

7 2

9 4

Figure 10-21
Registers for decimal arithmetic multiplication and
division
Ae : to accommodate an overflow
while adding the multiplicand
to the partial product during multiplication
Be : to form the 9s complement of the devisor
when subtracted from the partial remainder
during the division operation

1
AQ B x Q by adding A A + B and decrementing QL
Q AQ / B by subtracting A A - B and incrementing QL

4 0 5

1
AQ B x Q
by adding A A + B and decrementing QL

3 2 1 8

+
0 0 0 0

3 2 1 8

4 0 5

76

1
Q AQ / B
by subtracting A A - B and incrementing QL

2 8 3 4

3 2 1 8

4 0 5

01

0 3 8 4
0

8 4 4

5 1

You might also like