module tbenew; // testbench for the 5-bit by 4-bit unsigned multiplier // exhaustive checking of all 512 (2^5 * 2^4) possible cases reg [4:0] x; // 5-bit inputs reg [3:0] y; // 4-bit inputs wire [8:0] p; // 9-bit output of the multiplier circuit reg [8:0] check; // 9-bit product value used to check correctess 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 5-bit by 4-bit multiplier mult5by4 mult_instance(x, y, p); // exhaustive checking of all 512 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 < 32; i = i + 1) begin x = i; for (j = 0; j < 16; j = j + 1) begin y = j; check = x * y; // compute and check the product #10 if (p == 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)", x, y, p, check); end end // print the final counter values $display("num_correct = %d, num_wrong = %d", num_correct, num_wrong); end endmodule