Recall: 1010 0101 ---- 1010 0000 1010 0000 ------- 0110010 Repeat n times: Step 1: Test multiplier-0 Step 2: if 1, add multiplicand to product Step 3: shift multiplier right 1 bit Step 4: shift multiplicand left 1 bit Initilize: product = 00000000 multiplier = 0101 multiplicand = 00001010 ======================== Iter 1: product = 00000000 +00001010 --------- 00001010 multiplier = 0010 multiplicand = 00010100 Iter 2: product = 00001010 multiplier = 0001 multiplicand = 00101000 Iter 3: product = 00001010 +00101000 --------- 00110010 multiplier = 0000 multiplicand = 01010000 Iter 4: product = 00110010 multiplier = 0000 multiplicand = 10100000 ====== Implementation 2 1111 1111 ---- 00000000 00001111 -------- 00001111 + 00011110 -------- 00101101 + 00111100 -------- 01101001 + 01111000 -------- 11100001 Repeat n times: Step 1: Test multiplier-0 Step 2: if 1, add multiplicand to left half of product and place the result in the left half of the product register Step 3: shift multiplier right 1 bit Step 4: shift product register right 1 bit Initilize: product = 00000000 multiplier = 1111 multiplicand = 1111 ====================== *** 0s that are just filling up space; they are not part of the final answer. [At the end of iteration i, there are n-i filler 0s at the right. So, at the end of iteration n, there are 0 filler 0s at the right.] Iter1: product = 00000000 +1111 ----- product = 11110000 **** multiplier = 0111 product = 01111000 *** Iter2: product = 01111000 + 1111 ------ product = 101101000 multiplier = 0011 product = 10110100 ** ** if there is a carry, it needs to be shifted in, rather than a 0 Iter3: product = 10110100 + 1111 ------ product = 110100100 multiplier = 0001 product = 11010010 * Iter4: product = 11010010 + 1111 ------ product = 111000010 multiplier = 0000 product = 11100001 Return to the picture of the hardware...go over again what we saved. Version 3: Initialize: product = {n{0},n-bit multiplier} multiplicand = multiplicand (n bits) Repeat n times: Step 1: Test product[0] Step 2: if 1, add multiplicand to left half of product and place the result in the left half of the product register Step 3: shift product register right 1 bit Initilize: product = 00001111 multiplicand = 1111 ====================== ***The starred ones are now the multiplier Iter1: product = 00001111 +1111 ----- product = 11111111 **** product = 01111111 *** Iter2: product = 01111111 + 1111 ------ product = 101101111 *** product = 10110111 ** ** if there is a carry, it needs to be shifted in, rather than a 0 Iter3: product = 10110111 + 1111 ------ product = 110100111 ** product = 11010011 * Iter4: product = 11010011 + 1111 ------ product = 111000011 * multiplier = 0000 product = 11100001 ==================================== Integer Division of Unsigned Numbers quotient ------------ divisor | dividend -------- remainder Example for reference: 11 ---------- 0010 | 00000111 0010 ----- 00011 0010 ----- 1 7 / 2 is 3 with 1 remainder of 1 Algorithm: Size of dividend is 2 * size of divisor Size of quotient == size of divisor Initialization: quotient register = 0 remainder register = dividend divisor register = divisor in left half Repeat for 33 iterations (size divisor + 1): step 1: remainderReg = remainderReg - divisorReg step 2: If Remainder >= 0: shift quotientReg left 1 bit, placing 1 in bit 0 Else: remainderReg = remainderReg + divisorReg shift quotientReg left 1 bit, placing 0 in bit 0 step 3: shift divisorReg right 1 bit Our example: Although the hardware needs to, I won't bother subtracting and then adding. I'll just indicate "no change". Initilize: remainderReg = 00000111 divisorReg = 00100000 quotientReg = 0000 n + 1 iterations. We are using a 4-bit datapath in these examples, so there are 5 iterations. Iter 1: 00000111 - 0010000 < 0: remainderReg = 0000 0111 no change divisorReg = 0001 0000 quotientReg = 0000 Iter 2: 0000 0111 - 0001 0000 < 0: remainderReg = 0000 0111 no change divisorReg = 0000 1000 quotientReg = 0000 Iter 3: 00000111 - 00001000 < 0: remainderReg = 0000 0111 no change divisorReg = 0000 0100 quotientReg = 0000 Iter 4: 0000 0111 - 0000 0100 >= 0: remainderReg = 0000 0111 - 0000 0100 0000 0011 divisorReg = 0000 0010 quotientReg = 0001 Iter 5: 0000 0011 - 0000 0010 >= 0: remainderReg = 0000 0011 - 0000 0010 0000 0001 divisorReg = 0000 0001 quotientReg = 0011