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
	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
	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