Beruflich Dokumente
Kultur Dokumente
4.1
SB=Sign(B)
operand 2
SC=Sign(C)
result
XOR SA,SB 0 1 1 0
4.2
Multiplication: In general, if the multiplicand has n bits and the multiplier has m bits, the product will have (n+m) bits. Note whats going on: we go through each bit in the multiplier and performing a sequence of left-shifts and additions. This is an indication that to implement multiplication in hardware, one needs a shift-register and an adder. What about the signs of the operands and the sign of the result?
4.3
Start
Multiplier0 = 1
1. Test Multiplier0
Multiplier0 = 0
1a. Add multiplicand to product and place the result in Product register
How many registers are needed to implement this in hardware? In general, how many repetitions are needed by this algorithm?
4.4
32nd repetition?
4.5
Start
Multiplier0 = 1
1. Test Multiplier0
Multiplier0 = 0
1a. Add multiplicand to the left half of the product and place the result in the left half of the Product register
32nd repetition?
4.6
32-bit ALU
Product 64 bits
Control test
4.7
Operations on 2s Complement
Division: Trivial when multiplier is a power of 2 (use a shift-register to do right shifts). Otherwise, we have to define an algorithm, but first, lets think a bit. Quotient: How many times does the divisor fit into the dividend? Remainder: After a multiple of the divisor has been subtracted from the dividend, whats left?
4.8
Start
Division:
1001 1000 1001010 -1000 1010 -1000 10
1. Subtract the Divisor register from the Remainder register and place the result in the Remainder register
> Remainder 0
Test Remainder
Remainder < 0
2a. Shift the Quotient register to the left, setting the new rightmost bit to 1
2b. Restore the original value by adding the Divisor register to the Remainder register and place the sum in the Remainder register. Also shift the Quotient register to the left, setting the new least significant bit to 0
33rd repetition?
Yes: 33 repetitions
4.9
Done
no R=R+D Q<<1(0)
4.10
10
Iteration
Initialize R=R-D
Step
Quotient
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0001 0001 0011 0011
Divisor
0010 0000 0010 0000 0010 0000 0001 0000 0001 0000 0001 0000 0000 1000 0000 1000 0000 1000 0000 0100 0000 0100 0000 0100 0000 0010 0000 0010 0000 0010 0000 0001
Remainder
0000 0111 1110 0111 0000 0111 0000 0111 1111 0111 0000 0111 0000 0111 1111 1111 0000 0111 0000 0111 0000 0011 0000 0011 0000 0011 0000 0001 0000 0001 0000 0001
4.11
R0=1: +D,Q<<1,Q0=0 D>>1 R=R-D R0=1: +D,Q<<1,Q0=0 D>>1 R=R-D R0=1: +D,Q<<1,Q0=0 D>>1 R=R-D R0=0: Q<<1,Q0=1 D>>1 R=R-D R0=0: Q<<1,Q0=1 D>>1
7 2
n=4
11
64-bit ALU
Remainder 64 bits
Write
Control test
4.12
12
7 = (3 2) + (1) 2
7 = (4 2) + ( +1) 2
Sign( Dividend ) Sign( Divisor ) Sign(Remainder ) = Sign( Dividend ) Quotient = Quotient 4.13
13
Interlude
Question: Given a positive n-bit number A, how can one compute the twos complement representation of (-A) with the hardware that you know? subtraction 0 -A A
4.14
14
Binvert
Operation CarryIn
0 1 Result
0 1
Less
a.
CarryOut
c = a b = a + b +1
To make c = a + b
Binvert Operation CarryIn a 0 1 Result b 0 1 Less 3 Set Overflow detection b. 2
Bnegate=0
To make c = a b
OP=10 CarryIn=1 Binvert=1 Bnegate=1
4.15
Overflow
15
Binvert
CarryIn
Operation
a0 b0
Result0
a1 b1 0
Result1
a2 b2 0
Result2
Set
4.16
16
Bnegate
Operation
a0 b0
a1 b1 0
Zero
a2 b2 0
a31 b31 0
CarryOut
4.17
17