Professional Documents
Culture Documents
Computer Arithmetic
Chapter 10
Computer Arithmetic
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)
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)
= - 25 1
= - 20
= + 25
= - 26 - 25 1
= - 25 24- 1 = - 49
= - 20
= + 24 = 16
= - 26 = - 64 - 49
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
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
A B
n-1
AC
Multiplication of
floating-point numbers
1.
2.
3.
4.
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.
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