diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7393e46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +*.o diff --git a/hw1.t.v b/hw1.t.v new file mode 100644 index 0000000..d381643 --- /dev/null +++ b/hw1.t.v @@ -0,0 +1,40 @@ +`include "hw1.v" + +module demorgan_test (); + + // Instantiate device/module under test + reg A, B; // Primary test inputs + wire nA, nB, + nAandnB, n_AorB, + nAornB, n_AandB; // Test outputs + + demorgan dut(A, B, nA, nB, + nAandnB, n_AorB, + nAornB, n_AandB); // Module to be tested + + // Run sequence of test stimuli + initial begin + // ~A~B vs ~(A+B) + $display("A B | ~A ~B | ~A~B | ~(A+B)"); // Prints header for truth table + A=0;B=0; #1 // Set A and B, wait for update (#1) + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB); + A=0;B=1; #1 // Set A and B, wait for new update + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB); + A=1;B=0; #1 + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB); + A=1;B=1; #1 + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB); + + $display(""); + // ~A + ~B vs ~(AB) + $display("A B | ~A ~B | ~A+~B | ~(AB)"); + A=0;B=0; #1 + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAornB, n_AandB); + A=0;B=1; #1 + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAornB, n_AandB); + A=1;B=0; #1 + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAornB, n_AandB); + A=1;B=1; #1 + $display("%b %b | %b %b | %b | %b ", A,B, nA, nB, nAornB, n_AandB); + end +endmodule // End demorgan_test diff --git a/hw1.v b/hw1.v new file mode 100644 index 0000000..e7f6c6f --- /dev/null +++ b/hw1.v @@ -0,0 +1,37 @@ +module demorgan +( + input A, // Single bit inputs + input B, + output nA, // Output intermediate complemented inputs + output nB, + output nAandnB, // Single bit output, (~A)*(~B) + output n_AorB, + output nAornB, + output n_AandB +); + + wire nA; + wire nB; + wire AandB; + wire AorB; + not Ainv(nA, A); // Top inverter is named Ainv, takes signal A as input and produces signal nA + not Binv(nB, B); + + // ~A * ~B + and nAandnBgate(nAandnB, nA, nB); + + // ~(A*B) + and AandBgate(AandB, A, B); + not AandBInv(n_AandB, AandB); + + // ~A + ~B + or nAornBgate(nAornB, nA, nB); + + // ~(A+B) + or AorBgate(AorB, A, B); + not AorBInv(n_AorB, AorB); + + + + +endmodule diff --git a/results.txt b/results.txt new file mode 100644 index 0000000..9ce0b94 --- /dev/null +++ b/results.txt @@ -0,0 +1,12 @@ +A B | ~A ~B | ~A~B | ~(A+B) +0 0 | 1 1 | 1 | 1 +0 1 | 1 0 | 0 | 0 +1 0 | 0 1 | 0 | 0 +1 1 | 0 0 | 0 | 0 + +A B | ~A ~B | ~A+~B | ~(AB) +0 0 | 1 1 | 1 | 1 +0 1 | 1 0 | 1 | 1 +1 0 | 0 1 | 1 | 1 +1 1 | 0 0 | 0 | 0 +