module tb16; // testbench for the 8-bit by 8-bit Booth signed multiplier // exhaustive checking of all 256*256 possible cases reg [7:0] x, y; // 8-bit inputs integer xval, yval; // numerical values of inputs x and y wire [15:0] p; // 16-bit output of the multiplier circuit integer pval; // numerical value of the product integer check; // value used to check correctness integer i, j; // loop variables integer num_correct; // counter to keep track of the number correct integer num_wrong; // counter to keep track of the number wrong // instantiate the 8-bit by 8-bit radix-4 Booth-encoded signed multiplier booth16f mult_instance(x, y, p); // exhaustive simulation of all 256*256 = 65,536 possible cases initial begin // initialize the counter variables num_correct = 0; num_wrong = 0; // loop through all possible cases and record the results for (i = 0; i < 256; i = i + 1) begin x = i; xval = -x[7]*128 + x[6:0]; for (j = 0; j < 256; j = j + 1) begin y = j; yval = -y[7]*128 + y[6:0]; check = xval * yval; // compute and check the product #10 pval = -p[15]*32768 + p[14:0]; if (pval == check) num_correct = num_correct + 1; else num_wrong = num_wrong + 1; // following line is commented out, but is useful for debugging // $display($time, " %d * %d = %d (%d)", xval, yval, pval, check); end end // print the final counter values $display("num_correct = %d, num_wrong = %d", num_correct, num_wrong); end endmodule