// Listing 2.1 module eq1 // I/O ports ( input wire i0, i1, output wire eq ); // signal declaration wire p0, p1; // body // sum of two product terms assign eq = p0 | p1; // product terms assign p0 = ~i0 & ~i1; assign p1 = i0 & i1; endmodule// Listing 2.2 module eq2 ( input wire[1:0] a, b, output wire aeqb ); // internal signal declaration wire e0, e1; // body // instantiate two 1-bit comparators eq1 eq_bit0_unit (.i0(a[0]), .i1(b[0]), .eq(e0)); eq1 eq_bit1_unit (.eq(e1), .i0(a[1]), .i1(b[1])); // a and b are equal if individual bits are equal assign aeqb = e0 & e1; endmodule// Listing 2.3 // The `timescale directive specifies that // the simulation time unit is 1 ns and // the simulation timestep is 10 ps `timescale 1 ns/10 ps module eq2_testbench; // signal declaration reg [1:0] test_in0, test_in1; wire test_out; // instantiate the circuit under test eq2 uut (.a(test_in0), .b(test_in1), .aeqb(test_out)); // test vector generator initial begin $dumpvars; //for iverilog/vvp // test vector 1 test_in0 = 2'b00; test_in1 = 2'b00; # 200; // test vector 2 test_in0 = 2'b01; test_in1 = 2'b00; # 200; // test vector 3 test_in0 = 2'b01; test_in1 = 2'b11; # 200; // test vector 4 test_in0 = 2'b10; test_in1 = 2'b10; # 200; // test vector 5 test_in0 = 2'b10; test_in1 = 2'b00; # 200; // test vector 6 test_in0 = 2'b11; test_in1 = 2'b11; # 200; // test vector 7 test_in0 = 2'b11; test_in1 = 2'b01; # 200; // stop simulation //$stop; end endmodule