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
Show all changes
41 commits
Select commit Hold shift + click to select a range
e3d178d
fixed table in Specification section
Halliax Oct 5, 2017
01453d9
work plan
Halliax Oct 5, 2017
6403681
Stubbed out files and figured out FOR loops in verilog
Oct 7, 2017
35ba29f
add gitignore
Halliax Oct 9, 2017
d07e1ea
updated gitignore
Halliax Oct 9, 2017
9080604
Added combinatorial gates testing in BitSlice.t.v and dummy code for …
aehoppe Oct 9, 2017
f07a20e
Gitignore growing pains
aehoppe Oct 9, 2017
2c9f28c
Started Writeup
aehoppe Oct 9, 2017
8434dad
Added VCD to gitignore
aehoppe Oct 9, 2017
171d21c
Finished BitSlice.t.v exhaustive testing
aehoppe Oct 9, 2017
6db7cf4
implemented bitslice design, copied over structural adder code, test …
Halliax Oct 9, 2017
20ad830
Replaced image at beginning of report
aehoppe Oct 11, 2017
b44ea7e
Merge branch 'master' of github.com:halliax/Lab1
aehoppe Oct 11, 2017
fc8b58e
Fixed minor errors in ADD and SUB and added SLT test
aehoppe Oct 11, 2017
c542c44
added SLT inverting logic to bitslice.v, set correct SLT flag in test…
Halliax Oct 11, 2017
5cbf622
Added maybe working ADD and SUB test code
aehoppe Oct 11, 2017
2d6b029
ALU control LUT, 4 bit ALU, 4 bit ALU with generate block
Halliax Oct 11, 2017
ada4847
Merge branch 'master' of https://github.com/Halliax/Lab1
Halliax Oct 11, 2017
47b15b5
Added gtkwave dumps
aehoppe Oct 11, 2017
fc48b39
Merge branch 'master' of github.com:halliax/Lab1
aehoppe Oct 11, 2017
ea7b7ed
fixed syntax errors, lots of tests still failing
Halliax Oct 11, 2017
2ece048
Merge branch 'master' of https://github.com/Halliax/Lab1
Halliax Oct 11, 2017
aa715b3
typo
Halliax Oct 11, 2017
d2e8589
Wrong bitwise inversion, fixed
aehoppe Oct 11, 2017
573633f
Got subtract logic testing working
aehoppe Oct 12, 2017
7663e8d
Made change to SLT criteria, swapped OR for XOR between final sum and…
Halliax Oct 12, 2017
06e3041
comments, changed zero flag logic to be string of gates instead of gi…
Halliax Oct 12, 2017
85bccef
Stubbed out test harness
aehoppe Oct 12, 2017
fadf97b
mostly finished report, missing some images and test cases
Halliax Oct 12, 2017
c7c1073
corrected worst-case delay calculations
Halliax Oct 12, 2017
2af36f7
Widened requisite buses for ADD SUB SLT cases that were failing
aehoppe Oct 12, 2017
fa184ae
Merge branch 'master' of https://github.com/Halliax/Lab1
Halliax Oct 12, 2017
461520b
Added reversed test logic output to show all tests passing
aehoppe Oct 12, 2017
f76314f
added worst case delay image
Halliax Oct 12, 2017
5d1e966
Merge branch 'master' of https://github.com/Halliax/Lab1
Halliax Oct 12, 2017
8d189a4
added and formatted test result blocks, besides boolean
Halliax Oct 12, 2017
f4691d9
added boolean cases to writeup
Halliax Oct 12, 2017
3d3fda3
Added image of final ALU design
aehoppe Oct 12, 2017
2188032
Appropriately widened logic block operands
aehoppe Oct 12, 2017
a8dda80
Fixed width of logic block operands
aehoppe Oct 12, 2017
3e9b2bb
finished writeup
Halliax Oct 12, 2017
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*.out
*.vcd
28 changes: 28 additions & 0 deletions ALUcontrolLUT.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// `define ADD 3'd0
// `define SUB 3'd1
// `define XOR 3'd2
// `define SLT 3'd3
// `define AND 3'd4
// `define NAND 3'd5
// `define NOR 3'd6
// `define OR 3'd7

module ALUcontrolLUT
(
output reg ADD, SUB, XOR, SLT, AND, NAND, NOR, OR,
input[2:0] ALUcommand
);

always @(ALUcommand) begin
case (ALUcommand)
3'd0: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b10000000; end
3'd1: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b01000000; end
3'd2: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00100000; end
3'd3: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00010000; end
3'd4: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00001000; end
3'd5: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00000100; end
3'd6: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00000010; end
3'd7: begin {ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00000001; end
endcase
end
endmodule
151 changes: 151 additions & 0 deletions BitSlice.t.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//Test harness for exhaustively testing individual bit_slice modules

`include "BitSlice.v"

module BitSliceTestHarness ();

// Declare registers for inputs
reg ADD, SUB, XOR, SLT, AND, NAND, NOR, OR, A, B, CIN;

// Declare output wires
wire cout, sum, res;

// Instantiate DUT
BitSlice bit_slice (cout, sum, res, ADD, SUB, XOR, SLT, AND, NAND, NOR, OR, A, B, CIN);

// Declare helper variable registers
reg[3:0] inputs;
reg testfailed;

initial begin
// Test bench code here.
$dumpfile("BitSlice.vcd");
$dumpvars(0,bit_slice);

// Initialize test failed to 0
testfailed = 0;

// Test simpler gates, OR, NOR, NAND, AND, XOR
// OR
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00000001; // Set OR flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (res != (A|B)) begin
testfailed = testfailed+1;
$display("Test Case OR Cin:%b A:%b B:%b Failed, Got %b Expected %b", CIN, A, B, res, (A|B));
end
end

// NOR
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00000010; // Set NOR flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (res != (A~|B)) begin
testfailed = testfailed+1;
$display("Test Case NOR Cin:%b A:%b B:%b Failed, Got %b Expected %b", CIN, A, B, res, (A~|B));
end
end

// NAND
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00000100; // Set NAND flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (res != (A~&B)) begin
testfailed = testfailed+1;
$display("Test Case NAND Cin:%b A:%b B:%b Failed, Got %b Expected %b", CIN, A, B, res, (A~&B));
end
end

// AND
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00001000; // Set AND flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (res != (A&B)) begin
testfailed = testfailed+1;
$display("Test Case AND Cin:%b A:%b B:%b Failed, Got %b Expected %b", CIN, A, B, res, (A&B));
end
end

// XOR
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00100000; // Set XOR flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (res != (A^B)) begin
testfailed = testfailed+1;
$display("Test Case XOR Cin:%b A:%b B:%b Failed, Got %b Expected %b", CIN, A, B, res, (A^B));
end
end

// Test more complicated gates: ADD and SUB
// ADD
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b10000000; // Set ADD flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (sum != (A^B^CIN)) begin
testfailed = testfailed+1;
$display("Test Case ADD Cin:%b A:%b B:%b Failed, Got Sum:%b Expected Sum:%b", CIN, A, B, sum, A^B^CIN);
end
if (res != (A^B^CIN)) begin
testfailed = testfailed+1;
$display("Test Case ADD Cin:%b A:%b B:%b Failed, Got Res:%b Expected Res:%b", CIN, A, B, res, A^B^CIN);
end
if (cout != ((A&B)|((A^B)&CIN))) begin // (A&B)|((A^B)&CIN) is the correct carryout logic
testfailed = testfailed+1;
$display("Test Case ADD Cin:%b A:%b B:%b Failed, Got Cout:%b Expected Cout:%b", CIN, A, B, cout, (A&B)|((A^B)&CIN));
end
end

// SUB is identical to ADD but all of the B inputs to the test cases are inverted.
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b01000000; // Set SUB flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (sum != (A^(!B)^CIN)) begin
testfailed = testfailed+1;
$display("Test Case SUB Cin:%b A:%b B:%b Failed, Got Sum:%b Expected Sum:%b", CIN, A, B, sum, A^(!B)^CIN);
end
if (res != (A^(!B)^CIN)) begin
testfailed = testfailed+1;
$display("Test Case SUB Cin:%b A:%b B:%b Failed, Got Res:%b Expected Res:%b", CIN, A, B, res, A^(!B)^CIN);
end
if (cout != ((A&(!B))|((A^(!B))&CIN))) begin // (A&(!B))|((A^(!B))&CIN) is the correct carryout logic
testfailed = testfailed+1;
$display("Test Case SUB Cin:%b A:%b B:%b Failed, Got Cout:%b Expected Cout:%b", CIN, A, B, cout, (A&(!B))|((A^(!B))&CIN));
end
end

// SLT is identical to SUB but all of the res outputs should be 0
{ADD, SUB, XOR, SLT, AND, NAND, NOR, OR} = 8'b00010000; // Set SLT flag
for (inputs=4'b0; inputs<4'b1000; inputs=inputs+4'b1) begin
{CIN, A, B} = inputs; #1000 // Set inputs and wait
// $display( "%b %b %b", index, A, B); //
if (sum != (A^(!B)^CIN)) begin
testfailed = testfailed+1;
$display("Test Case SLT Cin:%b A:%b B:%b Failed, Got Sum:%b Expected Sum:%b", CIN, A, B, sum, A^(!B)^CIN);
end
if (res != 0) begin
testfailed = testfailed+1;
$display("Test Case SLT Cin:%b A:%b B:%b Failed, Got Res:%b Expected Res:%b", CIN, A, B, res, 0);
end
if (cout != ((A&(!B))|((A^(!B))&CIN))) begin // (A&(!B))|((A^(!B))&CIN) is the correct carryout logic
testfailed = testfailed+1;
$display("Test Case SLT Cin:%b A:%b B:%b Failed, Got Cout:%b Expected Cout:%b", CIN, A, B, cout, (A&(!B))|((A^(!B))&CIN));
end
end

if(testfailed == 0) begin
$display("Tests Passed");
end
else begin
$display("%d Test Failures", testfailed);
end

end

endmodule
43 changes: 43 additions & 0 deletions BitSlice.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//Single bit slice module for ALU
`define NAND nand #20
`define NOR nor #20
`define NOT not #10
`define XOR xor #30
`define OR or #30
`define NAND7 nand #70

`include "adder.v"

module BitSlice
(
output cout, sum, res,
input ADD, SUB, XOR, SLT, AND, NAND, NOR, OR, A, B, CIN
);
// internal wires
wire sum, sub_slt, b_inv, xor_ab, and_ab, nand_ab, nor_ab, or_ab;
// individual outputs into nand collector
wire add_out, sub_out, xor_out, and_out, nand_out, nor_out, or_out;

// individual operator blocks
`OR or_sub_slt (sub_slt, SUB, SLT);
`XOR inv_input (b_inv, B, sub_slt);
fullAdder adder (sum, cout, A, b_inv, CIN);
`XOR xor_operator (xor_ab, A, B);
`NAND nand_operator (nand_ab, A, B);
`NOR nor_operator (nor_ab, A, B);
`NOT not_nand (and_ab, nand_ab);
`NOT not_nor (or_ab, nor_ab);

// nand control line selectors
`NAND add_switch (add_out, sum, ADD);
`NAND sub_switch (sub_out, sum, SUB);
`NAND xor_switch (xor_out, xor_ab, XOR);
`NAND and_switch (and_out, and_ab, AND);
`NAND nand_switch (nand_out, nand_ab, NAND);
`NAND nor_switch (nor_out, nor_ab, NOR);
`NAND or_switch (or_out, or_ab, OR);

// collector for all individual outputs
`NAND7 collector (res, add_out, sub_out, xor_out, and_out, nand_out, nor_out, or_out);

endmodule
Loading