// tb_lut4.sv: configure lut4 for y = (a AND b) OR (c XOR d) and check // all 16 input combinations against the Boolean expression. `timescale 1ns/1ps module tb_lut4; logic a, b, c, d, y; int unsigned errors = 0; // Truth table read from the lesson, row 15 first: 1000 1111 1111 1000 = 16'h8FF8 lut4 #(.INIT(16'h8FF8)) dut (.a(a), .b(b), .c(c), .d(d), .y(y)); initial begin for (int i = 0; i < 16; i++) begin {d, c, b, a} = i[3:0]; #1; if (y !== ((a & b) | (c ^ d))) begin $display("FAIL dcba=%b%b%b%b y=%b", d, c, b, a, y); errors++; end end if (errors == 0) $display("PASS: INIT=16'h8FF8 implements (a & b) | (c ^ d)"); else $display("FAILED with %0d errors", errors); $finish; end endmodule