CS0447 Project 3
Due March 23 (at mid-night)
The purpose of this assignment is to model and simulate hardware multiplication
units and compare the performance of two hardware multiplication algorithms.
See the web for the procedure you need to follow to submit this project.
PROJECT:
Write a C++ program to simulate both the third multiplication algorithm and
the Booth algorithm given in the textbook. You may assume that the operands
are positive integers (although the Booth algorithm allows negative operands).
Your program should read the two operand, simulate the multiplication, keep
track of the time it takes to perform the multiplication, then write the
results along with the time (simulated) consumed by the multiplication hardware.
To compute the simulated time, assume that a shift takes one cycle and an
add/subtract takes 6 cycles.
As usual, you need to check the validity of the input and print adequate
error messages.
EXAMPLES:
> enter multiplicand: 6
> this is 000000000110 in binary
> enter multiplier: 463
> this is 000111001111 in binary
> The product is : 2778
> which is 000000000000101011011010 in binary
> Algorithm 3 took 54 cycles and Booth algorithm took 36 cycles
>
> do you want to stop: N
> enter multiplicand: 371
> this is 000101110011 in binary
> enter multiplier: 85
> this is 000001010101 in binary
> The product is : 31535
> which is 000000000111101100101111 in binary
> Algorithm 3 took 36 cycles and Booth algorithm took 60 cycles
>
> do you want to stop: Y
BONUS POINTS (+10%):
You may statistically compare the performance of the two hardware units by
running the algorithms many times (say 1000 times) using randomly generated
operands and computing the average time needed for each unit. Of course, you
can do this by making 1000 run from your terminal, or you can put a wrapper
around your program that will loop 1000 time. To generate random numbers
between 0 and 4095 (which is the range of 12-bit integers), use the
random number generating facility in C++.
*****************************************************************************
A PROGRAM TEMPLATE
------------------
/* Your program should constructed in a way similar to the following object
oriented structure */
#include
enum bit{F,T} ;
int int_to_bin(int, int , bit []); /* converts an integer to a binary word */
int bin_to_int(int, bit []) ; /* converts a binary word to an integer */
/* one of the arguments is the size of the binary word -- the return value
in int_to_bin indicates whether or not the size is too small */
class register_12 { /* may add other members if you need to */
public : register_12() ;
void left_shift();
void right_shift();
void write(bit binary_word[]); /* write a word to the register */
bit get_rmb(); /* get the right most bit */
private : bit store[12] ;
};
class register_24 {} ;
class alu_12
{ public : alu_12();
int add() ; /* returns bit-13 of the result */
int sub() ; /* returns bit-13 of the result */
private: bit operand1[12] ;
bit operand2[12] ;
bit result[13] ;
void get_first_operand() ;
void get_second_operand() ;
void write_result() ;
};
class mult_unit_3 { /* a unit to implement the 3rd algorithm in the book */
public:
mult_unit_3() ; ;
void load_multiplicand(bit b_word[12]) ;
void load_multiplier(bit b_word[12]) ;
int start_control(); ;
void get_result(bit b_word[24]) ;
private:
register_12 multiplicand ; /* a 12-bit register */
register_24 product ; /* a 24_bit register */
alu_12 adder ; /* a 12-bit adder */
}
class mult_unit_booth {} ; /* a unit designed to execute Booth multiplication */
int main(void)
{ int x, y, z_3, z_b ;
int time_3, time_b ;
bit multiplicand[12];
bit multiplier[12];
bit product[24];
mult_unit_3 M3;
mult_unit-booth MB;
loop until you had enough
{
read multiplicand as an integer into x ;
int_to_bin(12, x, multiplicand) ;
read multiplier as an integer into y ;
int_to_bin(12, y, multiplier) ;
M3.load_multiplicand(multiplicand) ; /* do multiplication using M3 */
M3.load_multiplier(multiplier) ;
time_3 = M3.start_control() ;
M3.get_result(product) ;
z_3 = bin_to_int(24,product)
MB.load_multiplicand(multiplicand) ; /* do multiplication using MB */
MB.load_multiplier(multiplier) ;
time_b = MB.start_control() ;
MB.get_result(product) ;
z_b = bin_to_int(24,product)
print z_3, z_b, time_3 and time_b ;
}
}
int alu_12::add() {
get_first_operand() ; /* copy into operand1[12] the data from the appropriate */
/* register -- namely mult_unit_3.multiplicand */
/* NOTE: if you do not know how to give get_first_operand()
access to mult_unit_3.multiplicand.store, you can make
the latter a public class member (rather than private) */
get_second_operand() ;
implement the binary addition operand1 + operand2 ;
write_result() ; /* copy the result into the appropriate positions of */
/* mult_unit_3.product */
}
int mult_unit_3::start_control {
/* controls multiplication and returns the number of cycles it took to
complete the multiplication assuming shift takes one cycle and add/sub
takes 6 cycles */
}