//====================================================================== // File name: mult16s.c // File type: GNU C++ language source code file. // // Description: // This file defines a function called mult16s() that performs // multiplication of 16-bit two's complement numbers (represented // in sign-extended form in 32-bit registers). The file // also contains an auxilliary output routine for debugging // purposes, and a main() routine that exercises mult16s() by // performing some multiplications and printing the results. // // Author: Michael P. Frank // Created: March 21, 2006 //====================================================================== #include //---------------------------------------------------------------------- // Function name: mult16s() // Description: // Algorithm to carry out multiplication of signed 16-bit numbers // (encoded in sign-extended form in 32-bit ints) using shift and // add/subtract operations. // Arguments: // int mand - 16-bit signed multiplicand, sign-extended to 32 bits // int mer - 16-bit signed multiplier, sign-extended to 32 bits //---------------------------------------------------------------------- int mult16s(int mand, int mer){ unsigned i; // loop index variable int prod = 0; // initialize product to 0 for (i=0; i<15; i++) // at each positive position, if (mer&(1<