Documente Academic
Documente Profesional
Documente Cultură
Hardware/Software Interface
Topics covered:
Arithmetic
Multiplication of signed-operands
1
Booth’s algorithm
0110000000000000
0000011000000000
0000000011110000
+0000000000000110
0110011011110110
2
Booth’s algorithm (contd..)
Suppose Q is a block-1 integer: Q = 0000000001111000 = 120
And:
Q = 0000000001111000
128 = 0000000010000000
8 = 0000000000001000
3
Booth’s algorithm (contd..)
Q = 2k+1 - 2j
4
Booth’s algorithm (contd..)
Since:
Q = 215 – 21
X.Q = X.(215 – 21)
5
Booth’s algorithm (contd..)
Suppose: Q = 0110011011110110
Thus,
Q.X = X.(215 - 213 + 211 - 29 +27 - 24 + 23 - 21 )
6
Booth’s algorithm (contd..)
7
Booth’s algorithm (contd..) – Example #1
01001100 Multiplicand X
01110111 Multiplier Q
00000000 00000000 Double-length PP register
Step 0 bit pair 10
action: SUB 1011010000000000
Shift Right 1101101000000000
Step 1 bit pair 11
action: --- 1101101000000000
Shift Right 1110110100000000
Step 2 bit pair 11
action: --- 1110110100000000
Shift Right 1111011010000000
Step 3 bit pair 01
action: ADD 0100001010000000
Shift Right 0010000101000000
Step 4 bit pair 10
action: SUB 1101010101000000
Shift Right 1110101010100000
Step 5 bit pair 11
action: --- 1110101010100000
Shift Right 1111010101010000
Step 6 bit pair 11
action: --- 1111010101010000
Shift Right 1111101010101000
Step 7 bit pair 01
action: ADD 0100011010101000
Shift Right 0010001101010100 = Product: 9044
8
Booth’s algorithm (contd..) – Example #2
9
Booth’s algorithm (contd..) – Example #3
10
Booth’s algorithm and signed integers
And:
V(Q) = -2n-1 + qn-2 2n-2 + qn-3 2n-3 + ......... + q2 22 + q1 21 + q0 20
0 - X = -X = -1.X
11
Booth’s algorithm and signed integers (contd..)
Booth’s technique is correct for an arbitrary –ve 2’s complement number
Q is a 2’s complement number:
Q = 1 qn-2 qn-3 qn-4............ q1 q0
V(Q) = -2n-1 + qn-2 2n-2 + qn-3 2n-3 + ......... + q2 22 + q1 21 + q0 20
If we read Q from MSB (left hand side), Q will have certain number of 1s
followed by a 0. If the first 0 appears in the mth bit of Q.
V(Q) = -2n-1 + qn-2 2n-2 + qn-3 2n-3 + ......... + q2 22 + q1 21 + q0 20
= ( -2n-1 + 2n-2 + 2n-3 + ......... 2m+1 ) + (qm-1 2m-1 + ......... + q2 22 + q1 21 + q0 20 )
= -2m+1 + (qm-1 2m-1 + ......... + q2 22 + q1 21 + q0 20 )
Where ( -2n-1 + 2n-2 + 2n-3 + ......... 2m+1 ) = -2m+1
21 10101
13 274 1101 10001001
26 01101
14 10000
13 1101
1 1110
Try dividing 13 into 2. 1101
Try dividing 13 into 26.
1
Try dividing 1101 into 1, 10, 100, 1000
and 10001.
13
Restoring division
How do we know when the divisor has gone into part of the dividend
correctly?
10101
1101 10001001
01101 Subtract 1101 from 1, result is negative
Subtract 1101 from 10, result is negative.
10000 Subtract 1101 from 100, result is negative
1101 Subtract 1101 from 1000, result is negative.
Subtract 1101 from 10001, result is positive.
1110
1101
1
14
Restoring division
15
Restoring division (contd..)
Set Register A to 0.
Shift left
Load dividend in Q.
an an - 1 a0 q
n- 1
q
0
Load divisor into M.
A Dividend Q Repeat n times:
Quotient - Shift A and Q left one bit.
setting
-Subtract M from A.
-Place the result in A.
n +1-bit -If sign of A is 1, set q0 to
adder Add/Subtract 0 and add M back to A.
Control
sequencer Else set q0 to 1.
0 mn - 1 m0
End of the process:
Divisor M - Quotient will be in Q.
- Remainder will be in A.
Sign bit (result of sub)
16
Restoring division (contd..)
Initially0 0 0
0 0 1 0 0 0
0 0 0
1 1
Shift 0 0 0
0 1 0 0 0
Subtract 1 1 1
0 1 First cycle
Set q0 1 1 1
1 0
Restore 1 1
10 0 0 0 0 1 0 0 0 0
Shift 0 0 0 1 0 0 0 0
11 1000
11 Subtract 1 1 1 0 1
Set q0 1 1 1 1 1 Second cycle
1
10
Restore 1 1
0 0 0 1 0 0 0 0 0
Shift 0 0 1 0 0 0 0 0
Subtract 1 1 1 0 1
Set q0 0 0 0 0 1 Third cycle
Shift 0 0 0 1 0 0 0 0 1
Subtract 1 1 1 0 1 0 0 1
Set q0 1 1 1 1 1
Fourth cycle
Restore 1 1
0 0 0 1 0 0 0 1 0
Remainder Quotient
17
Non-restoring division
18
Non-restoring division (contd..)
Initially0 0 0 0 0 1 0 0 0
0 0 0 1 1
Shift 0 0 0 0 1 0 0 0 First cycle
Subtract 1 1 1 0 1
Set q0 1 1 1 1 0 0 0 0 0
Shift 1 1 1 0 0 0 0 0
Add 0 0 0 1 1 Second cycle
10 Set q0 1 1 1 1 1 0 0 0 0
11 1000
11 Shift 1 1 1 1 0 0 0 0
1
10 Add 0 0 0 1 1 Third cycle
Set q0 0 0 0 0 1 0 0 0 1
Shift 0 0 0 1 0 0 0 1
Subtract 1 1 1 0 1 Fourth cycle
Set q0 1 1 1 1 1 0 0 1 0
Quotient
1 1 1 1 1
Add 0 0 0 1 1 Restore
0 0 0 1 0 remainder
Remainder
19