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
Binary file added Write Up HW2.pdf
Binary file not shown.
24 changes: 22 additions & 2 deletions adder.t.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ module testFullAdder();
reg a, b, carryin;
wire sum, carryout;

behavioralFullAdder adder (sum, carryout, a, b, carryin);
//behavioralFullAdder adder (sum, carryout, a, b, carryin);
structuralFullAdder adder (sum, carryout, a, b, carryin);

initial begin
// Your test code here
$dumpfile("adder.vcd");
$dumpvars;

$display("A B CIn | Sum COut | Expected Output");
a=0; b=0; carryin=0; #1000
$display("%b %b %b | %b %b | 0 0", a, b, carryin, sum, carryout);
a=0; b=0; carryin=1; #1000
$display("%b %b %b | %b %b | 1 0", a, b, carryin, sum, carryout);
a=0; b=1; carryin=0; #1000
$display("%b %b %b | %b %b | 1 0", a, b, carryin, sum, carryout);
a=0; b=1; carryin=1; #1000
$display("%b %b %b | %b %b | 0 1", a, b, carryin, sum, carryout);
a=1; b=0; carryin=0; #1000
$display("%b %b %b | %b %b | 1 0", a, b, carryin, sum, carryout);
a=1; b=0; carryin=1; #1000
$display("%b %b %b | %b %b | 0 1", a, b, carryin, sum, carryout);
a=1; b=1; carryin=0; #1000
$display("%b %b %b | %b %b | 0 1", a, b, carryin, sum, carryout);
a=1; b=1; carryin=1; #1000
$display("%b %b %b | %b %b | 1 1", a, b, carryin, sum, carryout);
end
endmodule
16 changes: 15 additions & 1 deletion adder.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
`define AND and #50
`define OR or #50
`define XOR xor #50

// Adder circuit

module behavioralFullAdder
Expand All @@ -20,5 +24,15 @@ module structuralFullAdder
input b,
input carryin
);
// Your adder code here

wire AxorB;
wire AandB;
wire AxorBandCarryIn;

`XOR (AxorB, a, b);
`XOR (sum, AxorB, carryin);
`AND (AandB, a, b);
`AND (AxorBandCarryIn, AxorB, carryin);
`OR (carryout, AxorBandCarryIn, AandB);

endmodule
7 changes: 5 additions & 2 deletions decoder.t.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ module testDecoder ();
reg enable;
wire out0,out1,out2,out3;

behavioralDecoder decoder (out0,out1,out2,out3,addr0,addr1,enable);
//structuralDecoder decoder (out0,out1,out2,out3,addr0,addr1,enable); // Swap after testing
//behavioralDecoder decoder (out0,out1,out2,out3,addr0,addr1,enable);
structuralDecoder decoder (out0,out1,out2,out3,addr0,addr1,enable); // Swap after testing

initial begin
$dumpfile("decoder.vcd");
$dumpvars;

$display("En A0 A1| O0 O1 O2 O3 | Expected Output");
enable=0;addr0=0;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
Expand Down
15 changes: 14 additions & 1 deletion decoder.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
`define AND and #50
`define NOT not #50

// Decoder circuit

module behavioralDecoder
Expand All @@ -17,6 +20,16 @@ module structuralDecoder
input address0, address1,
input enable
);
// Your decoder code here

wire nA;
wire nB;

`NOT (nA, address0);
`NOT (nB, address1);
`AND (out0, nA, nB, enable);
`AND (out1, address0, nB, enable);
`AND (out2, nA, address1, enable);
`AND (out3, address0, address1, enable);

endmodule

31 changes: 30 additions & 1 deletion multiplexer.t.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,34 @@
`include "multiplexer.v"

module testMultiplexer ();
// Your test code here
wire out;
reg address0, address1;
reg in0, in1, in2, in3;

//behavioralMultiplexer multiplexer (out, address0, address1, in0, in1, in2, in3);
structuralMultiplexer multiplexer (out, address0, address1, in0, in1, in2, in3);

initial begin
$dumpfile("multiplexer.vcd");
$dumpvars;

$display("A0 A1 | In0 In1 In2 In3 | Out | Expected Output");
address0=0; address1=0; in0=0; in1=0; in2=0; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=0; address1=0; in0=1; in1=0; in2=0; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
address0=0; address1=1; in0=0; in1=0; in2=0; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=0; address1=1; in0=0; in1=0; in2=1; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
address0=1; address1=0; in0=0; in1=0; in2=0; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=1; address1=0; in0=0; in1=1; in2=0; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
address0=1; address1=1; in0=0; in1=0; in2=0; in3=0; #1000
$display("%b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=1; address1=1; in0=0; in1=0; in2=0; in3=1; #1000
$display("%b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
end

endmodule
22 changes: 20 additions & 2 deletions multiplexer.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
`define AND and #50
`define OR or #50
`define NOT not #50

// Multiplexer circuit

module behavioralMultiplexer
Expand All @@ -19,6 +23,20 @@ module structuralMultiplexer
input address0, address1,
input in0, in1, in2, in3
);
// Your multiplexer code here
endmodule

wire nA;
wire nB;
wire nAandnBandin0;
wire AandnBandin1;
wire nAandBandin2;
wire AandBandin3;

`NOT (nA, address0);
`NOT (nB, address1);
`AND (nAandnBandin0, nA, nB, in0);
`AND (AandnBandin1, address0, nB, in1);
`AND (nAandBandin2, nA, address1, in2);
`AND (AandBandin3, address0, address1, in3);
`OR (out, nAandnBandin0, AandnBandin1, nAandBandin2, AandBandin3);

endmodule