HOMEWORK If didn't assign 4-31 --4-35, assign it now NOTE: I want to say more about CLA but don't want to break-up shifter/multiplier accross two lectures There are other fast adders (e.g. carry save) Shifter Just a string of D-flops; output of one is input of next Input to first is the serial input Output of last is the serial output But want more. Left and right shifting (with serial input/output) Parallel load Parallel Output Don't shift every cycle Parallel output is just wires. Shifter has 4 modes (left, right, nop, load) so 4-1 mux inside 2 control lines must come in Handout (also on web) shows diagram (Fig AA in my notes) Our shifters are slow for big shifts; barrel shifters are better HOMEWORK: A 4-bit shift register initially contains 1101. It is shifted six times to the right with the serial input being 101101. What is the contents of the register after each shift. HOMEWORK: Same register, same init condition. For the first 6 cycles the opcodes are left, left, right, nop, left, right and the serial input is 101101. The next cycle the register is loaded (in parallel) with 1011. The final 6 cycles are the same as the first 6. What is the contents of the register after each cycle? Multipliers Recall how to do multiplication. Multiplicand times multiplier gives product Multiply multiplicand by each digit of multiplier Put the result in the right column Then add the partial products just produced We will do it the same way ... ... BUT differently We have binary so each "digit" of the multiplier is 1 or zero. Hence "multiplying" by the digit means either Getting the multiplicand Getting zero Use an "if appropriate bit of multiplier is 1" stmt To get "appropriate bit" Use LOB Shift right (so next bit is LOB) Putting in the right column is done by shifting the multiplicand left one bit each time (even if the multiplier bit is zero) Instead of adding partial products at end, keep a running sum Don't add zero if multiplier bit is zero just skip step This results in the following algorithm product <- 0 for i = 0 to 31 if LOB of multiplier = 1 product = product + multiplicand shift multiplicand left 1 bit shift multiplier right 1 bit Do on board 4-bit addition (8-bit registers) 1100 x 1101 The circuit diagram is figure 4.20 (handout) What about the control? Always give the ALU the ADD operation Always send a 1 to the multiplicand to shift left Always send a 1 to the multiplier to shift right Pretty boring so far but Send a 1 to write line in product if and only if LOB multiplier is a 1 I.e. send LOB to write line I.e. it really is pretty boring This works! ... ... but is wasteful of resourses and hence is slower hotter bigger all these are bad Product register must be 64 bits since the product is 64 bits Why is multiplicand register 64 bits? So that we can shift it left I.e. for our convenience Why is ALU 64-bits? Because the product is 64 bits But we are only adding a 32-bit quantity to the product at any one step. Hmmm. Maybe we can just pull out the correct bits from the product. Would be tricky to pull out bits in the middle because which bits to pull changes each step POOF!! Solving both problems at once DON'T shift the multiplicand left Hence register is 32-bits and not a shifter Instead shift the product right! Add the HO 32-bits of prod reg to Multiplicand and place result back into HO 32-bits Only do this if the current multiplier bit is one. Do NOT need the carry-out from the adder; why? Because the HOB of the product BEFORE the add is zero This results in the following algorithm product <- 0 for i = 0 to 31 if LOB of multiplier = 1 product[32-63] = product[32-63] + multiplicand shift product right 1 bit shift multiplier right 1 bit The circuit diagram is figure 4.21 (handout) What about control Just as boring as before Send ADD, 1, 1 to ALU, multiplier, Product (shift right) Send LOB to Product (write) Redo same example on board A final trick ("gate bumming", like code bumming of 60s) There is sort of a waste of registers. Not for the multiplicand since we always need all 32 bits But once we use a multiplier bit, we can toss it And the product is half unused at beginning and only slowly ... POOF!! "Timeshare" the LO half of the "product register" In the beginning LO half contains the multiplier Each step we shift right and more goes to product less to multiplier The algorithm changes to product <- multiplier for i = 0 to 31 if LOB of product = 1 product[32-63] = product[32-63] + multiplicand shift product-multiplier-register right 1 bit Redo same example on board The above was for unsigned 32-bit multiplication For signed multiplication Save the signs of the multiplier and multiplicand Convert multiplier and multiplicand to non-neg numbers Use above algorithm Don't need the 32nd iteration since multiplier HOB of multiplier is zero (sign bit) Compliment product if original signs were different There are faster multipliers. Skip Division Skip Floating Point HOMEWORK Read 4.11 "Historical Perspective" Start Reading Chapter 5