Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit...

59
Multiplication and Division CMSC 301 Prof. Szajda

Transcript of Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit...

Page 1: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication and Division

CMSC 301Prof. Szajda

Page 2: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Administrative

•  Read Ch. 3.1-3.4, C.11•  Program #1 due 10/24•  HW #5 assigned

w Due Monday, 10/21, at 5pm

Page 3: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Review

•  What is slow in a ripple carry adder?•  What makes a carry lookahead adder

faster than a ripple carry adder?

Page 4: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication

Page 5: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication in Decimal

How would this look in decimal? 0101x 0110

Multiplicand (MC)

Multiplier (MP)

Product (P)

Page 6: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication in Decimal

How would this look in decimal? 0101x 0110

0000

Multiplicand (MC)

Multiplier (MP)

Product (P)

Page 7: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication in Decimal

0101x 0110

How would this look in decimal?

00000101

Multiplicand (MC)

Multiplier (MP)

Product (P)

Page 8: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication in Decimal

0101x 0110

How would this look in decimal?

00000101

0101

Multiplicand (MC)

Multiplier (MP)

Product (P)

Page 9: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication in Decimal

0101x 0110

00000101

01010000

Multiplicand (MC)

Multiplier (MP)

Product (P)

Page 10: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplication in Decimal

0101x 0110

0011110

00000101

01010000

Multiplicand (MC)

Multiplier (MP)

Product (P)

Page 11: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observations

•  Two 4-bit operands produces an answer up to 8 bits

•  What is the only number that gets added to produce the product?

•  What happens each iteration?

Page 12: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observations

•  Two 4-bit operands produces an answer up to 8 bits

•  What is the only number that gets added to produce the product? Multiplicand

•  What happens each iteration?

Page 13: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observations

•  Two 4-bit operands produces an answer up to 8 bits

•  What is the only number that gets added to produce the product? Multiplicand

•  What happens each iteration?w Shift multiplicand one to the leftw Shift our attention of multiplier bit one

left

Page 14: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

MIPS Multiplication

•  2 32-bit inputs create a 64-bit output•  MIPS places those in regs named HI

and LO•  code for $s0 = $s1 * $s2mult $s1, $s2 # implicit dests HI & LO mflo $s0 # $s0 <- LO

Page 15: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Multiplier Hardware

Page 16: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Multiplication Algorithm

Start

Done

No: < 32 iterations

Yes: 32 iterations

32nd iteration?

Test multiplier bit 0 MP[0] == 0?

MP[0] == 0 MP[0] != 0

P = P + MC

MC << 1

MP >> 1

Page 17: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0000 0101 0000 0000 1

Shift left MC Shift right MP

3 Shift left __

Shift right __

2 Shift left __

Shift right __

4 Shift left __

Shift right __

Page 18: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0000 0101 0000 0000 1 0 -> no op 0110

Shift left MC 0000 1010 Shift right MP 0011

3 Shift left __

Shift right __

2 Shift left __

Shift right __

4 Shift left __

Shift right __

Page 19: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0000 0101 0000 0000 1 0 -> no op 0110

Shift left MC 0000 1010 Shift right MP 0011

3 Shift left __

Shift right __

2 1 -> Pr = Pr + MC 0000 1010 Shift left MC 0001 0100 Shift right MP 0001

4 Shift left __

Shift right __

Page 20: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0000 0101 0000 0000 1 0 -> no op 0110

Shift left MC 0000 1010 Shift right MP 0011

3 1 -> Pr = Pr + MC 0001 1110 Shift left MC 0010 1000 Shift right MP 0000

2 1 -> Pr = Pr + MC 0000 1010 Shift left MC 0001 0100 Shift right MP 0001

4 Shift left __

Shift right __

Page 21: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0000 0101 0000 0000 1 0 -> no op 0110

Shift left MC 0000 1010 Shift right MP 0011

3 1 -> Pr = Pr + MC 0001 1110 Shift left MC 0010 1000 Shift right MP 0000

2 1 -> Pr = Pr + MC 0000 1010 Shift left MC 0001 0100 Shift right MP 0001

4 0 -> no op 0001 1110 Shift left MC 0101 0000 Shift right MP 0000

Page 22: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observation of 1st Algorithm

•  Half of the MC is 0’s at any given time•  We really only care about 4 bits of the

MC •  Can we shift something else and keep

MC the same?

Page 23: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observation of 1st Algorithm

•  Half of the MC is 0’s at any given time•  We really only care about 4 bits of the

MC •  Can we shift something else and keep

MC the same? Product

Page 24: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

2nd Algorithm

•  Always add MC to the top bits of the product

•  Shift the Product to the right

Page 25: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

2nd Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0101 0000 0000 1 0 -> no op 0110

Shift right MP 0011

3 1 -> Pr = Pr + MC

Shift right MP 0000

2 1 -> Pr = Pr + MC

Shift right MP 0001

4 0 -> no op Shift Right P Shift right MP 0000

Shift Right P

Shift Right P

Shift Right P

Page 26: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

2nd Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0101 0000 0000 1 0 -> no op 0110

Shift right MP 0011

3 1 -> Pr = Pr + MC

Shift right MP 0000

2 1 -> Pr = Pr + MC

Shift right MP 0001

4 0 -> no op Shift Right P Shift right MP 0000

Shift Right P 0000 0000

Shift Right P

Shift Right P

Page 27: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

2nd Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0101 0000 0000 1 0 -> no op 0110

Shift right MP 0011

3 1 -> Pr = Pr + MC

Shift right MP 0000

2 1 -> Pr = Pr + MC 0101 0000

Shift right MP 0001

4 0 -> no op Shift Right P Shift right MP 0000

Shift Right P 0000 0000

Shift Right P 0010 1000

Shift Right P

Page 28: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

2nd Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0101 0000 0000 1 0 -> no op 0110

Shift right MP 0011

3 1 -> Pr = Pr + MC 0111 1000

Shift right MP 0000

2 1 -> Pr = Pr + MC 0101 0000

Shift right MP 0001

4 0 -> no op Shift Right P Shift right MP 0000

Shift Right P 0000 0000

Shift Right P 0010 1000

Shift Right P 0011 1100

Page 29: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

2nd Multiplication Algorithm

Iteration Step Multiplier Multiplicand Product 0 Initialize values 0110 0101 0000 0000 1 0 -> no op 0110

Shift right MP 0011

3 1 -> Pr = Pr + MC 0111 1000

Shift right MP 0000

2 1 -> Pr = Pr + MC 0101 0000

Shift right MP 0001

4 0 -> no op 0011 1100 Shift Right P 0001 1110 Shift right MP 0000

Shift Right P 0000 0000

Shift Right P 0010 1000

Shift Right P 0011 1100

Page 30: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Savings

•  We have a 4-bit adder, not 8-bit adder•  Save 4 bits of storage in Multiplicand

Page 31: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observations about 2nd Algorithm

•  The # of bits we care about in the Multiplier is equal to the # of 0’s in Product

Page 32: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observations about 2nd Algorithm

•  The # of bits we care about in the Multiplier is equal to the # of 0’s in Product

•  SolutionStore the Multiplier in the lower

portion of the Product

Page 33: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Multiplication Algorithm

Iteration Step Multiplicand Product / MP 0 Initialize values 0101 0000 0110 1 0 -> no op

3 1 -> Pr = Pr + MC

2 1 -> Pr = Pr + MC

4 0 -> no op Shift Right P

Shift Right P

Shift Right P

Shift Right P

Page 34: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Multiplication Algorithm

Iteration Step Multiplicand Product / MP 0 Initialize values 0101 0000 0110 1 0 -> no op

3 1 -> Pr = Pr + MC

2 1 -> Pr = Pr + MC

4 0 -> no op Shift Right P

Shift Right P 0000 0011

Shift Right P

Shift Right P

Page 35: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Multiplication Algorithm

Iteration Step Multiplicand Product / MP 0 Initialize values 0101 0000 0110 1 0 -> no op

3 1 -> Pr = Pr + MC

2 1 -> Pr = Pr + MC 0101 0011

4 0 -> no op Shift Right P

Shift Right P 0000 0011

Shift Right P 0010 1001

Shift Right P

Page 36: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Multiplication Algorithm

Iteration Step Multiplicand Product / MP 0 Initialize values 0101 0000 0110 1 0 -> no op

3 1 -> Pr = Pr + MC 0111 1001

2 1 -> Pr = Pr + MC 0101 0011

4 0 -> no op Shift Right P

Shift Right P 0000 0011

Shift Right P 0010 1001

Shift Right P 0011 1100

Page 37: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Multiplication Algorithm

Iteration Step Multiplicand Product / MP 0 Initialize values 0101 0000 0110 1 0 -> no op

3 1 -> Pr = Pr + MC 0111 1001

2 1 -> Pr = Pr + MC 0101 0011

4 0 -> no op Shift Right P 0001 1110

Shift Right P 0000 0011

Shift Right P 0010 1001

Shift Right P 0011 1100

Page 38: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Savings

•  Only one shift per iteration•  Save 4 bits of storage from Multiplier

•  Limitation: 4 * -1?

Page 39: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Division

Page 40: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Division in Decimal

0111

How would this look in decimal?

Dividend 0010

Quotient

Divisor

Page 41: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Division in Decimal

0111

How would this look in decimal?

Dividend 0010

Quotient 11

-0010

0011-0010 1 Remainder

Divisor

Page 42: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Divisor Hardware

Initially dividend

Initially divisor in left half

Page 43: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmStart

Done

Test Remainder

33rd repetition?

Divisor >> 1

Quotient << 1 Rightmost bit = 1

Rem = Divisor + Rem Quotient << 1

Rightmost bit = 0

Rem = Rem - Divisor

Rem >= 0 Rem < 0

Yes: 33 repetitions

No: < 33 repetitions

Page 44: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmIteration Step Quotient Divisor Remainder

0 Initialize values 0000 0010 0000 0000 0111 1 Rem = Rem - Div

Div>>1

3 Rem = Rem - Div

Div>>1

2 Rem = Rem - Div

Div>>1

4 Rem = Rem - Div

Div>>1 5 Rem = Rem - Div

Div>>1

Page 45: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmIteration Step Quotient Divisor Remainder

0 Initialize values 0000 0010 0000 0000 0111 1 Rem = Rem - Div

Rem<0=>+Div, Q<<1, Q0=0 Div>>1

3 Rem = Rem - Div

Div>>1

2 Rem = Rem - Div

Div>>1

4 Rem = Rem - Div

Div>>1

1110 0111 0000 0111

0001 0000 0000

5 Rem = Rem - Div

Div>>1

Page 46: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmIteration Step Quotient Divisor Remainder

0 Initialize values 0000 0010 0000 0000 0111 1 Rem = Rem - Div

Rem<0=>+Div, Q<<1, Q0=0 Div>>1

3 Rem = Rem - Div

Div>>1

2 Rem = Rem - Div 1111 0111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

4 Rem = Rem - Div

Div>>1

1110 0111 0000 0111

0001 0000 0000

0000 0000 1000

0000 0111

5 Rem = Rem - Div

Div>>1

Page 47: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmIteration Step Quotient Divisor Remainder

0 Initialize values 0000 0010 0000 0000 0111 1 Rem = Rem - Div

Rem<0=>+Div, Q<<1, Q0=0 Div>>1

3 Rem = Rem - Div 1111 1111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

2 Rem = Rem - Div 1111 0111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

4 Rem = Rem - Div

Div>>1

1110 0111 0000 0111

0001 0000 0000

0000

0000

0000 1000

0000 0100

0000 0111

0000 0111

5 Rem = Rem - Div

Div>>1

Page 48: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmIteration Step Quotient Divisor Remainder

0 Initialize values 0000 0010 0000 0000 0111 1 Rem = Rem - Div

Rem<0=>+Div, Q<<1, Q0=0 Div>>1

3 Rem = Rem - Div 1111 1111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

2 Rem = Rem - Div 1111 0111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

4 Rem = Rem - Div 0000 0011 Rem>=0=> Q<<1, Q0=1

Div>>1

1110 0111 0000 0111

0001 0000 0000

0000

0000

0001

0000 1000

0000 0100

0000 0010

0000 0111

0000 0111

5 Rem = Rem - Div

Div>>1

Page 49: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

1st Division AlgorithmIteration Step Quotient Divisor Remainder

0 Initialize values 0000 0010 0000 0000 0111 1 Rem = Rem - Div

Rem<0=>+Div, Q<<1, Q0=0 Div>>1

3 Rem = Rem - Div 1111 1111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

2 Rem = Rem - Div 1111 0111 Rem<0=>+Div, Q<<1, Q0=0

Div>>1

4 Rem = Rem - Div 0000 0011 Rem>=0=> Q<<1, Q0=1

Div>>1

1110 0111 0000 0111

0001 0000 0000

0000

0000

0001

0000 1000

0000 0100

0000 0010

0000 0111

0000 0111

5 Rem = Rem - Div 0000 0001 Rem>=0=> Q<<1, Q0=1

Div>>1 0011

0000 0001

Page 50: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observation of 1st Algorithm

•  Half of the Divisor is 0’s at any given time

•  We really only care about 4 bits of the Divisor

•  Can we shift something else and keep Divisor the same?

Page 51: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observation of 1st Algorithm

•  Half of the Divisor is 0’s at any given time

•  We really only care about 4 bits of the Divisor

•  Can we shift something else and keep Divisor the same?

•  Solution: w Shift the Remainder to the left

Page 52: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

Observation of 1st Algorithm

•  First step cannot produce 1 in Quotient bitw  If it did, too large for quotient register

•  Shift first, subtract secondw Removes one iterationw Remainder in left half of Remainder

register

Page 53: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

More Observations (of 2nd Algorithm)

•  The # of bits we care about in the Quotient is equal to the # of 0’s in Remainder

•  SolutionStore the Quotient in the lower

portion of the Remainder

Page 54: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Division AlgorithmStart

Done. (LH)Rem >> 1

Test Remainder

32nd repetition?

Left half Rem = (LH)Rem - Divisor

Rem << 1 Rightmost bit Rem = 1

(LH)Rem = Divisor + (LH)Rem Rem << 1

Rightmost bit Rem = 0

Rem << 1

Rem >= 0 Rem < 0

Yes: 32 repetitions

No: < 32 repetitions

Page 55: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Division Algorithm

Iteration Step Divisor Remainder 0 Initialize values 0010 0000 0111

1 Rem << 1

Rem = Rem - Div

3 Rem = Rem - Div

2 Rem = Rem - Div

4 Rem = Rem - Div

Left half of Rem >> 1

Page 56: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Division Algorithm

Iteration Step Divisor Remainder 0 Initialize values 0010 0000 0111

1 Rem << 1

Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

3 Rem = Rem - Div

2 Rem = Rem - Div

4 Rem = Rem - Div

Left half of Rem >> 1

0000 1110 1110 1110 0001 1100

Page 57: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Division Algorithm

Iteration Step Divisor Remainder 0 Initialize values 0010 0000 0111

1 Rem << 1

Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

3 Rem = Rem - Div

2 Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

4 Rem = Rem - Div

Left half of Rem >> 1

0000 1110 1110 1110 0001 1100 1111 1100 0011 1000

Page 58: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Division Algorithm

Iteration Step Divisor Remainder 0 Initialize values 0010 0000 0111

1 Rem << 1

Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

3 Rem = Rem - Div Rem>=0=> R<<1, R0=1

2 Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

4 Rem = Rem - Div

Left half of Rem >> 1

0000 1110 1110 1110 0001 1100 1111 1100 0011 1000 0001 1000 0011 0001

Page 59: Multiplication and DivisionShift multiplicand one to the left! Shift our attention of multiplier bit one left. MIPS Multiplication ... 1st Multiplication Algorithm ... 2nd Algorithm

3rd Division Algorithm

Iteration Step Divisor Remainder 0 Initialize values 0010 0000 0111

1 Rem << 1

Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

3 Rem = Rem - Div Rem>=0=> R<<1, R0=1

2 Rem = Rem - Div Rem<0=>+Div, R<<1, R0=0

4 Rem = Rem - Div Rem>=0=> R<<1, R0=1

Left half of Rem >> 1

0000 1110 1110 1110 0001 1100 1111 1100 0011 1000 0001 1000 0011 0001 0001 0001 0010 0011 0001 0011