module tbexy4z; // testbench for the XY + 4*Z circuit // exhaustive checking of all 32*16*64(=32768) possible cases reg [4:0] x; // 5-bit inputs reg [3:0] y; // 4-bit inputs reg [5:0] z; // 6-bit inputs wire [9:0] s; // 10-bit output of the XY + 4*Z circuit reg [9:0] check; // 10-bit XY + 4*Z value used to check correctess integer i, j, k; // 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 XY + 4*Z circuit xyz xyz_instance(x, y, z, s); // exhaustive checking of all 32*16*64(=32768) 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; for (k = 0; k < 64; k = k + 1) begin z = k; check = (x * y) + (4 * z); // compute and check XY + 4*Z #10 if (s == check) num_correct = num_correct + 1; else num_wrong = num_wrong + 1; // following commented out but are useful for debugging // $display($time, " (%d * %d) + (4 * %d) = %d (%d)", // x, y, z, s, check); end end end // print the final counter values $display("num_correct = %d, num_wrong = %d", num_correct, num_wrong); end endmodule