### V22.0436 - Prof. Grishman

### Lecture 15 - Multipliers

(text, section 4.6: pages 198 to 204 only)

#### Multipliers

task: multiplying two 32-bit positive numbers to produce a 64-bit product

(note: bits are numbered with low-order bit = bit 0)

##### Basic (elementary school) algorithm adapted for binary arithmetic:

product:=0
repeat for i:= 0 to 31
if bit i of multiplier=1
then product:=product + multiplicand
shift multiplicand left 1 bit

- requires 32-bit multiplier register, 64-bit multiplicand register,
64-bit product register, 64-bit adder
- we can eliminate circuitry to find bit i of multiplier:

product:=0
repeat for i:= 0 to 31
if bit 0 of multiplier=1
then product:=product + multiplicand
shift multiplicand left 1 bit
shift multiplier right 1 bit

##### Saving bits

- instead of shifting multiplicand left, shift product right
- add multiplicand to high 32 bits of product register
- needs only 32-bit adder

product:=0
repeat for i:= 0 to 31
if bit 0 of multiplier=1
then product[bits 32-63]:=product[bits 32-63] + multiplicand
shift product right 1 bit
shift multiplier right 1 bit

- can save even more by combining product and multiplier in one 64-bit
register