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
47 commits
Select commit Hold shift + click to select a range
4d48757
Create work_plan.txt
apan64 Oct 4, 2017
c2d8cec
Merge branch 'master' of https://github.com/CompArchFA17/Lab1
apan64 Oct 8, 2017
0b388a9
Adder subtractor and friends
kwinter213 Oct 8, 2017
bb619e8
fixed the mux
apan64 Oct 10, 2017
90b15d3
Fixed a little. added a new test case that breaks it though :(
kwinter213 Oct 10, 2017
ec8c677
made slt
apan64 Oct 10, 2017
4c60389
32 bit ALU & friendz
kwinter213 Oct 11, 2017
0a79f2e
changed slt to output 32 bits
apan64 Oct 11, 2017
5fe898d
created and, nand, and nor
apan64 Oct 11, 2017
07d3136
added delays
apan64 Oct 11, 2017
b0bc947
created or and xor
Oct 11, 2017
5a6cdca
Merge branch 'master' of https://github.com/apan64/Lab1
Oct 11, 2017
25ef21b
More ALU32 bit
kwinter213 Oct 11, 2017
5035fd7
Merge branch 'master' of https://github.com/apan64/Lab1
kwinter213 Oct 11, 2017
028671a
merge and added time delays, changed number of adder inputs
apan64 Oct 11, 2017
05fe413
Delete adder_subtracter
apan64 Oct 11, 2017
ea32165
Delete and_32bit
apan64 Oct 11, 2017
1148a0d
Delete nand_32bit
apan64 Oct 11, 2017
9e05231
Delete nor_32bit
apan64 Oct 11, 2017
57fa00a
Delete slt
apan64 Oct 11, 2017
75e26ad
ALU32bit.v
kwinter213 Oct 11, 2017
d5c75e2
removed binary, added gitignore
apan64 Oct 11, 2017
f10ad7b
Merge branch 'master' of https://github.com/apan64/Lab1
apan64 Oct 11, 2017
ae45cbe
pls work gitignore
apan64 Oct 11, 2017
4c18e24
slightly better ALU
kwinter213 Oct 11, 2017
2f1f889
Merge branch 'master' of https://github.com/apan64/Lab1
kwinter213 Oct 11, 2017
04bd1a7
proper naming
kwinter213 Oct 11, 2017
c364263
Delay added
Oct 11, 2017
2c5358d
Merge branch 'master' of https://github.com/apan64/Lab1
Oct 11, 2017
42fb7e5
Reconfigured test definitions
Oct 11, 2017
8b1bf8d
initial alu test file
Oct 11, 2017
5299730
delays and stuff
apan64 Oct 11, 2017
b2f0059
fixed slt
apan64 Oct 11, 2017
54fc47a
Cleaned up test file
Oct 11, 2017
717565a
switched to switch statement in alu.t.v
apan64 Oct 11, 2017
2487179
Merge branch 'master' of https://github.com/apan64/Lab1
apan64 Oct 11, 2017
531eb87
cout and flag only nonzero for adder_subtracter
apan64 Oct 11, 2017
24f3844
ALU test cases
Oct 11, 2017
ec2358b
fixed alu, changed some test cases
apan64 Oct 11, 2017
cac6e5e
fixed some slt test cases
apan64 Oct 11, 2017
8598003
Delays Fixed
Oct 11, 2017
803cc3e
added comments, deleted ALU32bit
apan64 Oct 12, 2017
6e869a4
added module level comments
apan64 Oct 12, 2017
3f546c1
test case error detection
Oct 12, 2017
1f6b0cb
added more test cases
apan64 Oct 12, 2017
a1810fc
Merge branch 'master' of https://github.com/apan64/Lab1
apan64 Oct 12, 2017
e91c9e6
added report
apan64 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore all
*

# Unignore all with extensions
!*.*
76 changes: 76 additions & 0 deletions adder.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Adder circuit

module behavioralFullAdder
(
output sum,
output carryout,
input a,
input b,
input carryin
);
// Uses concatenation operator and built-in '+'
assign {carryout, sum}=a+b+carryin;
endmodule

module structuralFullAdder
(
output sum,
output carryout,
input a,
input b,
input carryin
);
wire ab; //setting up wires
wire acarryin;
wire bcarryin;
wire orpairintermediate;
wire orsingleintermediate;
wire orall;
wire andsumintermediate;
wire andsingleintermediate;
wire andall;
wire invcarryout;
and #(50) andab(ab, a, b); // a and b
and #(50) andacarryin(acarryin, a, carryin); // a and carryin
and #(50) andbcarryin(bcarryin, b, carryin); // b and carryin
or #(50) orpair(orpairintermediate, ab, acarryin); // (a and b) or (a and carryin)
or #(50) orcarryout(carryout, orpairintermediate, bcarryin); // ((a and b) or (a and carryin)) or (b and carryin)
or #(50) orintermediate(orsingleintermediate, a, b); // a or b
or #(50) orallinputs(orall, orsingleintermediate, carryin); // (a or b) or carryin
not #(50) inv(invcarryout, carryout); // not carryout
and #(50) sumintermediate(andsumintermediate, invcarryout, orall); // (a or b or carryin) and not carryout
and #(50) andintermediate(andsingleintermediate, a, b); // a and b
and #(50) andallinputs(andall, andsingleintermediate, carryin); // (a and b) and carryin
or #(50) adder(sum, andsumintermediate, andall); // ((a or b or carryin) and not carryout) or (a and b and c)
endmodule

module FullAdder4bit
(
output[3:0] sum, // 2's complement sum of a and b
output carryout, // Carry out of the summation of a and b
output overflow, // True if the calculation resulted in an overflow
input[3:0] a, // First operand in 2's complement format
input[3:0] b, // Second operand in 2's complement format
input carryin
);
wire carryout1; // wire setup for carryouts from each adder
wire carryout2;
wire carryout3;
wire aandb;
wire anorb;
wire bandsum;
wire bnorsum;
wire abandnoror;
wire bsumandnornor;
structuralFullAdder #50 adder1(sum[0], carryout1, a[0], b[0], carryin); // first adder to handle the first added bits
structuralFullAdder #50 adder2(sum[1], carryout2, a[1], b[1], carryout1); // second adder to take the carryout from the first adder and the next added bits
structuralFullAdder #50 adder3(sum[2], carryout3, a[2], b[2], carryout2); // third adder to take the second carryout and the third added bits
structuralFullAdder #50 adder4(sum[3], carryout, a[3], b[3], carryout3); // fourth adder to take the third carryout and the fourth bits
and #50 andinputs(aandb, a[3], b[3]); // logic to determine overflow (overflow occurs when two positives result in a negative or two negatives result in a positive, the larges bit in both inputs are equal and the largest bit in the output is not the same)
nor #50 norinputs(anorb, a[3], b[3]);
and #50 andsum(bandsum, b[3], sum[3]);
nor #50 norsum(bnorsum, b[3], sum[3]);
or #50 orinputcombs(abandnoror, aandb, anorb);
nor #50 norsumcombs(bsumandnornor, bandsum, bnorsum);
and #50 finaland(overflow, abandnoror, bsumandnornor);
endmodule
60 changes: 60 additions & 0 deletions adder_subtracter.t.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Adder_subtacter testbench

`timescale 1 ns / 1 ps
`include "adder_subtracter.v"

module test32bitAdder();
reg[31:0] a;
reg[31:0] b;
reg[2:0] carryin;
wire[31:0] ans;
wire carryout, overflow;

adder_subtracter adder0(ans[31:0], carryout, overflow, a[31:0], b[31:0], carryin[2:0]);

initial begin
$display("Input A Input B Command | Output Flag Carryout");

// Addition tests
a=32'b00000000000000000000000000000001;
b=32'b00000000000000000000000000000001;
carryin=3'b100; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

a=32'b10000000000000000000000000000001;
b=32'b10000000000000000000000000000001;
carryin=3'b000; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

// Subtraction Tests
a=32'b00000000000000000000000000000001;
b=32'b00000000000000000000000000000001;
carryin=3'b001; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

a=32'b00000000001000000000000000000000;
b=32'b00000000000000000000000010000000;
carryin=3'b001; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

a=32'b10000000001000010000000000000000;
b=32'b10000000000000010000000010000000;
carryin=3'b001; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

a=32'b10000000000000000000000000000001;
b=32'b10000000000000000000000000000001;
carryin=3'b001; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

a=32'b00000000000000000000000000000000;
b=32'b10000000000000000000000000000001;
carryin=3'b001; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);

a=32'b10000000000000000000000000000001;
b=32'b10000000000000000000000000000001;
carryin=3'b000; #5000
$display("%b %b %b | %b %b %b", a[31:0],b[31:0],carryin,ans[31:0],carryout, overflow);
end
endmodule
Loading