Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 00 -> AND, 01 -> OR, 10 -> NOR, 11 -> XOR
- module logicunit(out, A, B, control);
- output out;
- input A, B;
- input [1:0] control;
- wire l, m, n, p;
- and a1(l, A, B);
- or o1(m, A, B);
- nor n1(n, A, B);
- xor x1(p, A, B);
- mux4 mx1(out, l, m, n, p, control);
- endmodule // logicunit
- module logicunit_test;
- // exhaustively test your logic unit implementation by adapting mux4_tb.v
- // cycle through all combinations of A, B, C, D every 16 time units
- reg A = 0;
- always #1 A = !A;
- reg B = 0;
- always #2 B = !B;
- reg [1:0] control = 0;
- initial begin
- $dumpfile("logicunit.vcd");
- $dumpvars(0, logicunit_test);
- // control is initially 0
- # 16 control = 1; // wait 16 time units (why 16?) and then set it to 1
- # 16 control = 2; // wait 16 time units and then set it to 2
- # 16 control = 3; // wait 16 time units and then set it to 3
- # 16 $finish; // wait 16 time units and then end the simulation
- end
- wire out;
- logicunit l1(out, A, B, control);
- // you really should be using gtkwave instead
- /*
- initial begin
- $display("A B C D s o");
- $monitor("%d %d %d %d %d %d (at time %t)", A, B, C, D, control, out, $time);
- end
- */
- endmodule // logicunit_test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement