CSCI206 - Computer Organization & Programming Integer Multiplication zyBook: 10.3
2’s Complement Multiplication For powers of 2, multiply is trivial (shift left). else use elementary algorithm:
Algorithm In general, multiplying a M bit number times a N bit number results in M + N bits multiplicand multiplier product = 0 for i in range(0, N): if multiplier[i] == 1: product += multiplicand << i product
Signed Multiplication This algorithm works for unsigned numbers. For signed numbers, multiply the absolute values and then add the proper sign to the result.
Signed Multiplication Resulting sign is + x + = + + x - = - - x + = - - x - = + In general: xor of input sign bits to get resulting sign bit
The Multiplier 1011 multiplicand x 1110 multiplier ----------------------------- Setup multiplicand in lower half of multiplicand register (2n bits) multiplier in multiplier register (n bits) product register is zero (2n bits)
The Multiplier
0010 x 0011 = ???? Example 1
0010 x 0011 = 0110
Product is the MIPS hi/lo registers Optimized Multiplier Product is the MIPS hi/lo registers Multiplier is initialized in the left half of the product register. Now we shift product register right. The multiplicand is 32-bits and not shifted because the result is written to the correct position in the product register after 32 right shifts.