File size: 1,132 Bytes
035592e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
`timescale 1ns / 1ps

module testbench;

  reg [7:0] A;          // Input A (8 bits)
  reg [7:0] B;          // Input B (8 bits)
  wire [15:0] product;  // Product result (16 bits)
  integer i;            // Loop variable
  integer error = 0;    // Error count for failed tests

  multi_8bit uut (
    .A(A),
    .B(B),
    .product(product)
  );

  // Test cases
  initial begin

    for (i = 0; i < 100; i = i + 1) begin
      // Generate random 8-bit inputs
      A = $random;
      B = $random;

      // Wait for the operation to complete
      #10;

    //   $display("A = %d, B = %d, Expected Product = %d", A, B, A * B);

      // Check the result of the multiplication
      if (product !== A * B) begin
        error = error + 1;
        $display("Test failed: A = %d, B = %d, Expected Product = %d, Got = %d", A, B, A * B, product);
      end
    end

    // Final test result summary
    if (error == 0) begin
      $display("=========== Your Design Passed ===========");
    end
    else begin
      $display("=========== Test completed with %d /100 failures ===========", error);
    end

    $finish;
  end

endmodule