From 0e6f1c7cbb1b2bc00b60999330eeabc67011e0d0 Mon Sep 17 00:00:00 2001 From: Changjun Lim Date: Thu, 14 Sep 2017 00:01:29 -0400 Subject: [PATCH] Homework 1 --- hw1.t.v | 24 ++++++++++++++++++++++++ hw1.v | 27 +++++++++++++++++++++++++++ results.txt.txt | 5 +++++ 3 files changed, 56 insertions(+) create mode 100644 hw1.t.v create mode 100644 hw1.v create mode 100644 results.txt.txt diff --git a/hw1.t.v b/hw1.t.v new file mode 100644 index 0000000..3e4818b --- /dev/null +++ b/hw1.t.v @@ -0,0 +1,24 @@ +`include "hw1.v" + +module demorgan_test (); + + // Instantiate device/module under test + reg A, B; // Primary test inputs + wire nA, nB, nAandnB; // 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 + $display("A B | ~A ~B | ~A~B | ~(A+B) | ~A+~B | ~(AB)"); // 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 | %b | %b ", A,B, nA, nB, nAandnB, n_AorB, nAornB, n_AandB); + A=0;B=1; #1 // Set A and B, wait for new update + $display("%b %b | %b %b | %b | %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB, nAornB, n_AandB); + A=1;B=0; #1 + $display("%b %b | %b %b | %b | %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB, nAornB, n_AandB); + A=1;B=1; #1 + $display("%b %b | %b %b | %b | %b | %b | %b ", A,B, nA, nB, nAandnB, n_AorB, nAornB, n_AandB); + end +endmodule // End demorgan_test diff --git a/hw1.v b/hw1.v new file mode 100644 index 0000000..1bb7a77 --- /dev/null +++ b/hw1.v @@ -0,0 +1,27 @@ +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, // Signle bit output, ~(A+B) + output nAornB, // Signle bit output, (~A)+(~B) + output n_AandB // Signle bit output, ~(A*B) +); + + 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); + and andgate(nAandnB, nA, nB); // AND gate produces nAandnB from nA and nB + and andgate2(AandB, A, B); + or orgate1(AorB, A, B); + or orgate2(nAornB, nA, nB); + not not_and(n_AandB, AandB); + not not_or(n_AorB, AorB); + +endmodule diff --git a/results.txt.txt b/results.txt.txt new file mode 100644 index 0000000..4095753 --- /dev/null +++ b/results.txt.txt @@ -0,0 +1,5 @@ +A B | ~A ~B | ~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 \ No newline at end of file