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

$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);

$finish();
end
endmodule
26 changes: 19 additions & 7 deletions adder.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// define gates with delays
`define AND and #50
`define OR or #50
`define XOR xor #50


// Adder circuit

module behavioralFullAdder
(
output sum,
output sum,
output carryout,
input a,
input b,
input a,
input b,
input carryin
);
// Uses concatenation operator and built-in '+'
Expand All @@ -14,11 +20,17 @@ endmodule

module structuralFullAdder
(
output sum,
output sum,
output carryout,
input a,
input b,
input a,
input b,
input carryin
);
// Your adder code here
wire axorb, axorb_Cin, ab;

`XOR abxorgate (axorb, a, b);
`XOR sumxorgate (sum, carryin, axorb);
`AND abandgate (ab, a, b);
`AND axorbCinandgate (axorb_Cin, axorb, carryin);
`OR Coutorgate (carryout, ab, axorb_Cin);
endmodule
45 changes: 25 additions & 20 deletions decoder.t.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@
`timescale 1 ns / 1 ps
`include "decoder.v"

module testDecoder ();
module testDecoder ();
reg addr0, addr1;
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
$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);
enable=0;addr0=1;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
enable=0;addr0=0;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
enable=0;addr0=1;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=0;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | O0 Only", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=1;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | O1 Only", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=0;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | O2 Only", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=1;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | O3 Only", enable, addr0, addr1, out0, out1, out2, out3);
$dumpfile("decoder.vcd");
$dumpvars(0, addr0, addr1, enable, out0, out1, out2, out3);

$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);
enable=0;addr0=1;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
enable=0;addr0=0;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
enable=0;addr0=1;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | All false", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=0;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | O0 Only", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=1;addr1=0; #1000
$display("%b %b %b | %b %b %b %b | O1 Only", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=0;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | O2 Only", enable, addr0, addr1, out0, out1, out2, out3);
enable=1;addr0=1;addr1=1; #1000
$display("%b %b %b | %b %b %b %b | O3 Only", enable, addr0, addr1, out0, out1, out2, out3);

$finish();
end

endmodule
20 changes: 18 additions & 2 deletions decoder.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// define gates with delays
`define AND and #50
`define NOT not #50

// Decoder circuit

module behavioralDecoder
Expand All @@ -17,6 +21,18 @@ module structuralDecoder
input address0, address1,
input enable
);
// Your decoder code here
endmodule
wire nadd0, nadd1, add0add1, nadd0nadd1, nadd0add1, add0nadd1;

`NOT add0inv (nadd0, address0);
`NOT add1inv (nadd1, address1);

`AND nadd0nadd1andgate (nadd0nadd1, nadd0, nadd1);
`AND add0nadd1andgate (add0nadd1, address0, nadd1);
`AND nadd0add1andgate (nadd0add1, nadd0, address1);
`AND add0add1andgate (add0add1, address0, address1);

`AND Eadd0add1andgate (out0, nadd0nadd1, enable);
`AND Enadd0nadd1andgate (out1, add0nadd1, enable);
`AND Enadd0add1andgate (out2, nadd0add1, enable);
`AND Eadd0nadd1andgate (out3, add0add1, enable);
endmodule
36 changes: 35 additions & 1 deletion multiplexer.t.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,39 @@
`include "multiplexer.v"

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

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


// kind of a random error but I tried to test in a different order and this was the only one that didn't compile in errors - assuming it's due to order of assignments

initial begin
$dumpfile("multiplexer.vcd");
$dumpvars(0, address0, address1, in0, in1, in2, in3, out);

$display("A0 A1 | in0 in1 in2 in3 | Out | Expected Output");
address0=0;address1=0;in0=1'b0;in1='bx;in2='bx;in3='bx; #1000
$display(" %b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=1;address1=0;in0='bx;in1=1'b0;in2='bx;in3='bx; #1000
$display(" %b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=0;address1=1;in0='bx;in1='bx;in2=1'b0;in3='bx; #1000
$display(" %b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=1;address1=1;in0='bx;in1='bx;in2='bx;in3=1'b0; #1000
$display(" %b %b | %b %b %b %b | %b | 0", address0, address1, in0, in1, in2, in3, out);
address0=0;address1=0;in0=1'b1;in1=1'bx;in2=1'bx;in3=1'bx; #1000
$display(" %b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
address0=1;address1=0;in0=1'bx;in1=1'b1;in2=1'bx;in3=1'bx; #1000
$display(" %b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
address0=0;address1=1;in0=1'bx;in1=1'bx;in2=1'b1;in3=1'bx; #1000
$display(" %b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);
address0=1;address1=1;in0=1'bx;in1=1'bx;in2=1'bx;in3=1'b1; #1000
$display(" %b %b | %b %b %b %b | %b | 1", address0, address1, in0, in1, in2, in3, out);

$finish();
end

endmodule
26 changes: 24 additions & 2 deletions multiplexer.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// define gates with delays
`define AND and #50
`define OR or #50
`define NOT not #50

// Multiplexer circuit

module behavioralMultiplexer
Expand All @@ -19,6 +24,23 @@ module structuralMultiplexer
input address0, address1,
input in0, in1, in2, in3
);
// Your multiplexer code here
endmodule
wire nadd0, nadd1, en0, en1, en2, en3, selen0, selen1, selen2, selen3, out0, out1;

`NOT add0inv (nadd0, address0);
`NOT add1inv (nadd1, address1);

`AND nadd0nadd1 (en0, nadd0, nadd1);
`AND add0nadd1 (en1, address0, nadd1);
`AND nadd0add1 (en2, nadd0, address1);
`AND add0nadd1 (en3, address0, address1);

`AND selector0 (selen0, en0, in0);
`AND selector1 (selen1, en1, in1);
`AND selector3 (selen2, en2, in2);
`AND selector4 (selen3, en3, in3);

`OR in0orin1 (out0, selen1, selen2);
`OR in2orin3 (out1, selen0, selen3);

`OR out (out, out0, out1);
endmodule