100 likes | 112 Vues
This document discusses the revised algorithm for integer multiplication in computer organization and programming. It covers the use of the 10.3.2's Complement Multiplication in zyBook and provides an optimized multiplier circuit example.
E N D
CSCI206 - Computer Organization & Programming Integer Multiplication Revised by Alexander Fuchsberger and Xiannong Meng in spring 2019 based on the notes by other instructors. 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 = 0; i < N; i ++) { if (multiplier[i] == 1) // shift m by i bits then add // m remains the same! product += multiplicand << i; product Demo mult.c
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)
0010 x 0011 = ???? Example 1
Optimized Multiplier Basic circuits 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. Product is the MIPS hi/lo registers Optimized one