diff --git a/hw1.t.v b/hw1.t.v new file mode 100644 index 0000000..1727ade --- /dev/null +++ b/hw1.t.v @@ -0,0 +1,30 @@ +`include "hw1.v" + +module demorgan_test (); + +// Instantiate device/module under test +reg A, B; //test inputs +wire nA, nB, nAandnB, AnandB, nAornB, AnorB; //test outputs + +demorgan dut(A, B, nA, nB, nAandnB, AnandB, nAornB, AnorB); + +// Run tests + +initial begin + $display("\n"); + $display("| A B | ~A ~V || ~A~B | ~(A+B) || ~A+~B | ~(AB) |"); + A=0;B=0; #1 + $display("| %b %b | %b %b || %b | %b || %b | %b |", + A,B, nA, nB, nAandnB, AnorB, nAornB, AnandB); + A=0;B=1; #1 + $display("| %b %b | %b %b || %b | %b || %b | %b |", + A,B, nA, nB, nAandnB, AnorB, nAornB, AnandB); + A=1;B=0; #1 + $display("| %b %b | %b %b || %b | %b || %b | %b |", + A,B, nA, nB, nAandnB, AnorB, nAornB, AnandB); + A=1;B=1; #1 + $display("| %b %b | %b %b || %b | %b || %b | %b |", + A,B, nA, nB, nAandnB, AnorB, nAornB, AnandB); + $display("\n"); +end +endmodule diff --git a/hw1.v b/hw1.v new file mode 100644 index 0000000..49040eb --- /dev/null +++ b/hw1.v @@ -0,0 +1,26 @@ +// homework 1, exhaustively prove demorgan's law + +module demorgan +( + input A, + input B, + output nA, + output nB, + output nAandnB, + output AnandB, + output nAornB, + output AnorB +); + + wire nA; + wire nB; + not Ainv(nA, A); +// type: not, name: Ainv, output variable: nA, input variable: A + not Binv(nB, B); + and andgate(nAandnB, nA, nB); + nand nandgate(AnandB, A, B); + or orgate(nAornB, nA, nB); + nor norgate(AnorB, A, B); + +endmodule + diff --git a/results.txt b/results.txt new file mode 100644 index 0000000..3ed97de --- /dev/null +++ b/results.txt @@ -0,0 +1,9 @@ + + +| A B | ~A ~V || ~A~B | ~(A+B) || ~A+~B | ~(AB) | +| 0 0 | 1 1 || 1 | 1 || 1 | 1 | +| 0 1 | 1 0 || 0 | 0 || 1 | 1 | +| 1 0 | 0 1 || 0 | 0 || 1 | 1 | +| 1 1 | 0 0 || 0 | 0 || 0 | 0 | + +