誌面に掲載できなかった一部のリストを掲載します.

● 筆算法による 2 ビット× 2 ビット= 4 ビットの乗算器のテストベンチ(本誌 リスト3のテストベンチ)

module mul_test();

logic[1:0] a;
logic[1:0] b;
logic[3:0] r;

mul dut(a, b, r);

initial begin
a = 0; b = 0; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 1; b = 0; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 2; b = 0; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 3; b = 0; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);

a = 0; b = 1; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 1; b = 1; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 2; b = 1; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 3; b = 1; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);

a = 0; b = 2; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 1; b = 2; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 2; b = 2; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 3; b = 2; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);

a = 0; b = 3; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 1; b = 3; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 2; b = 3; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
a = 3; b = 3; #10;
assert (r == a * b) else $error("mul: (a: %d, b: %d, r_expected: %d, r_actual: %d)", a, b, a * b, r);
end

endmodule

コメントを残す