Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.

Similar presentations


Presentation on theme: "1 Lecture 5Multiplication and Division ECE 0142 Computer Organization."— Presentation transcript:

1 1 Lecture 5Multiplication and Division ECE 0142 Computer Organization

2 2 Multiplication  More complicated than addition –A straightforward implementation will involve shifts and adds  More complex operation can lead to –More area (on silicon) and/or –More time (multiple cycles or longer clock cycle time)  Let ’ s begin from a simple, straightforward method

3 3 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 01010010 00000000 01010010 00000000 01010010 00000000 010001011101010

4 4 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 000000000000000 (partial sum)

5 5 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 000000001010010 (partial sum)

6 6 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 00000000

7 7 000000001010010 (partial sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x

8 8 000000001010010 (partial sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 01010010

9 9 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 000000110011010 (partial sum)

10 10 000000110011010 (partial sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 01010010

11 11 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 000010000101010 (partial sum)

12 12 000010000101010 (partial sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 00000000

13 13 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 000010000101010 (partial sum)

14 14 000010000101010 (partial sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 01010010

15 15 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 000111001101010 (partial sum)

16 16 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 01010010 000111001101010 (partial sum)

17 17 Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 010001011101010 (partial sum)

18 18 010001011101010 (partial sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x 00000000

19 19 010001011101010 (full sum) Straightforward Algorithm 01010010 (multiplicand) 01101101 (multiplier)x

20 20 Implementation 1

21 21 Example ( Implementation 1 )  Let ’ s do 0010 x 0110 (2 x 6), unsigned Iterati on Implementation 1 StepMultiplierMultiplicandProduct 0 initial values 01100000 00100000 1 1: 0 -> no op 01100000 00100000 2: Multiplier shift right/ Multiplicand shift left 0110000 01000000 2 1: 1 -> product = product + multiplicand 0110000 0100 2: Multiplier shift right/ Multiplicand shift left 010000 10000000 0100 3 1: 1 -> product = product + multiplicand 010000 10000000 1100 2: Multiplier shift right/ Multiplicand shift left 00001 00000000 1100 4 1: 0 -> no op 00001 00000000 1100 2: Multiplier shift right/ Multiplicand shift left 0010 0000

22 22 Drawbacks  The ALU is twice as wide as necessary  The multiplicand register takes twice as many bits as needed  The product register won’t need 2n bits till the last step –Being filled  The multiplier register is being emptied during the process

23 23 Implementation 2 Multiplicand stationary - Multiplier right - PP right

24 24 Example ( Implementation 2 )  Let ’ s do 0010 x 0110 (2 x 6), unsigned Iteration Implementation 2 StepMultiplierMultiplicandProduct 0 initial values 011000100000 ×××× 1 1: 0 -> no op 011000100000 ×××× 2: Multiplier shift right/ Product shift right × 01100100000 0 ××× 2 1: 1 -> product = product + multiplicand × 01100100010 0 ××× 2: Multiplier shift right/ Product shift right ×× 0100100001 00 ×× 3 1: 1 -> product = product + multiplicand ×× 0100100011 00 ×× 2: Multiplier shift right/ Product shift right ×x× 000100001 100 × 4 1: 0 -> no op ××× 000100001 100 × 2: Multiplier shift right/ Product shift right ×××× 00100000 1100

25 25 Implementation 3 Multiplier on right half of PP reg Multiplicand stationary - Multiplier right - PP right

26 26 Example ( Implementation 3 )  Let ’ s do 0010 x 0110 (2 x 6), unsigned Iteration Implementation 3 StepMultiplierMultiplicandProduct|Multiplier 0 initial values 011000100000 0110 1 1: 0 -> no op 011000100000 0110 2: Multiplier shift right/ Product shift right × 01100100000 0011 2 1: 1 -> product = product + multiplicand × 01100100010 0011 2: Multiplier shift right/ Product shift right ×× 0100100001 3 1: 1 -> product = product + multiplicand ×× 0100100011 0001 2: Multiplier shift right/ Product shift right ×× 0000100001 1000 4 1: 0 -> no op ××× 000100001 1000 2: Multiplier shift right/ Product shift right ×××× 00100000 1100

27 27 Example (signed)  Note: –Sign extension of partial product subtract –If most significant bit of multiplier is 1, then subtract → + + → + → → → + → → → → + → → →

28 28 Booth ’ s Encoding  Three symbols to represent numbers: 1, 0, -1  -1 in 8 bits –11111111 (two ’ s complement) –0000000-1 (Booth ’ s encoding)  14 in 8 bits –00001110 (two ’ s complement) –000100-10 (Booth ’ s encoding)  Bit transitions show Booth ’ s encoding –0 to 0: 0 –0 to 1: -1 –1 to 1: 0 –1 to 0: 1  Partial results are obtained by –Adding multiplicand –Adding 0 –Subtracting multiplicand

29 29 Booth ’ s Algorithm Example  Let ’ s do 0010 x 1101 (2 x -3) Iteration Implementation 3 StepMultiplicandProduct 0 initial values 00100000 1101 0 1 10 -> product = product – multiplicand 00101110 1101 0 shift right 1111 0110 1 2 01 -> product = product + multiplicand 00100001 0110 1 shift right 0000 1011 0 3 10 -> product = product – multiplicand 00101110 1011 0 shift right 1111 0101 1 4 11 -> no op 00101111 0101 1 shift right 1111 1010 1

30 30 Why it works? b × (a 31 a 30 ….a 0 ) = a 0 × b × 2 0 + a 1 × b × 2 1 + … a 31 × b × 2 31 = ( 0 – a 0 ) × b × 2 0 + ( a 0 – a 1 ) × b × 2 1 + … (a 30 – a 31 ) × b × 2 31 + a 31 × b × 2 32  Booth's algorithm performs an addition when it encounters the first digit of a block of ones (0 1) and a subtraction when it encounters the end of the block (1 0). When the ones in a multiplier are grouped into long blocks, Booth's algorithm performs fewer additions and subtractions than the normal multiplication algorithm. ?

31 31 Why it works?  Works for positive multiplier coz a 31 is 0  What happens for negative multipliers? a 31 is 1 –Remember that we are using 2’s complement binary b × (a 31 a 30 ….a 0 ) = b × (- a 31 × 2 31 +a 30 × 2 30 +….a 0 ×2 0 ) Same derivation applies

32 32 Division

33 33 Integer Division  Dividend = Quotient × Divisor + Remainder  How to do it using paper and pencil? Q ?R ? 1001 10001001010 -1000 10 101 1010 -1000 10 001000000111 11 -0010 00011 -0010 0001 7÷2 = 3 … 1

34 34 Implementation 1 64-bit wide 32-bit shift register

35 35 IterationStepQuotientDivisorRemainder 0 Initial values 00000010 00000000 0111 1 1: Rem=Rem-Div 00000010 00001110 0111 2b: Rem +Div, sll Q, Q 0 =0 00000010 00000000 0111 3: Shift Div right 00000001 00000000 0111 2 1: Rem=Rem-Div 00000001 00001111 0111 2b: Rem +Div, sll Q, Q 0 =0 00000001 00000000 0111 3: Shift Div right 00000000 10000000 0111 3 1: Rem=Rem-Div 00000000 10001111 2b: Rem +Div, sll Q, Q 0 =0 00000000 10000000 0111 3: Shift Div right 00000000 01000000 0111 4 1: Rem=Rem-Div 00000000 01000000 0011 2a: Rem≥0=> sll Q, Q 0 =1 00010000 01000000 0011 3: Shift Div right 00010000 00100000 0011 5 1: Rem=Rem-Div 00010000 00100000 0001 2a: Rem≥0=> sll Q, Q 0 =1 00110000 00100000 0001 3: Shift Div right 00110000 0001

36 36 Implementation 2 1. Place dividend in lower half 2. Do the division 3. Get remainder here 4. Get quotient here


Download ppt "1 Lecture 5Multiplication and Division ECE 0142 Computer Organization."

Similar presentations


Ads by Google