Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

*.o
40 changes: 40 additions & 0 deletions hw1.t.v
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions hw1.v
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions results.txt
Original file line number Diff line number Diff line change
@@ -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