chapter3_2
chapter3_2
Multiplicand 1000ten
Multiplier x 1001ten
---------------
1000
0000
0000
1000
----------------
Product 1001000ten
In every step
• multiplicand is shifted
• next bit of multiplier is examined (also a shifting step)
• if this bit is 1, shifted multiplicand is added to the product
2
HW Algorithm 1
initially left half is zeros and right half is non zero,
shifted to the left 64 times (and hence needs a 128 bit register)
In every step
• multiplicand is shifted
• next bit of multiplier is examined (also a shifting step)
• if this bit is 1, shifted multiplicand is added to the product
3
the 64 bit register is actually 64+1 (to handle the case
HW Algorithm 2 of overflow as an extra space for the carry out bit)
5
MIPS Instructions
6
Fast Algorithm
1001ten Quotient
Divisor 1000ten | 1001010ten Dividend
-1000
10
101
1010
-1000
10ten Remainder
At every step,
• shift divisor right and compare it with current dividend
• if divisor is larger, shift 0 as the next bit of the quotient
• if divisor is smaller, subtract to get new dividend and shift 1
as the next bit of the quotient 8
Division
1001ten Quotient
Divisor 1000ten | 1001010ten Dividend
At every step,
• shift divisor right and compare it with current dividend
• if divisor is larger, shift 0 as the next bit of the quotient
• if divisor is smaller, subtract to get new dividend and shift 1
as the next bit of the quotient 9
Divide Example
• Divide 7ten (0000 0111two) by 2ten (0010two)
10
IMPORTANT PAGE
Divide Example
• Divide 7ten (0000 0111two) by 2ten (0010two)
Iter Step Quot Divisor Remainder
0 Initial values 0000 0010 0000 0000 0111
1 Rem = Rem – Div 0000 0010 0000 1110 0111
Rem < 0 +Div, shift 0 into Q 0000 0010 0000 0000 0111
Shift Div right 0000 0001 0000 0000 0111
2 Same steps as 1 0000 0001 0000 1111 0111
0000 0001 0000 0000 0111
0000 0000 1000 0000 0111
3 Same steps as 1 0000 0000 0100 0000 0111
4 Rem = Rem – Div 0000 0000 0100 0000 0011
Rem >= 0 shift 1 into Q 0001 0000 0100 0000 0011
Shift Div right 0001 0000 0010 0000 0011
5 Same steps as 4 0011 0000 0001 0000 0001
11
divisor is shifted left initially until its 64 bit. in each step we subtract it from remainder. if remainder becomes negative, we add it back
and add 0 in the end of the divisor, else we add 1 in the end of the divisor. after each step we shift the divisor by 1.
left side contains remainder (initially set equal to the 64 bit dividend)
right side contains the quotient (initially set to zeros) in the 64+1 bit register
last 32 bits compared, if smaller then subtract from last 33 bits, put just 1, or 01
accordingly in lsb of the register (because remainder has given up one bit)
13
Source: H&P textbook
Divisions Involving Negatives
14
Divisions involving Negatives
15