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
38 commits
Select commit Hold shift + click to select a range
efb374b
Names
poosomooso Nov 5, 2017
c4a53a0
added gitignore
poosomooso Nov 11, 2017
fd06013
files from previous labs that are useful
poosomooso Nov 11, 2017
17aca95
Added sign extender and test bench
JosephLee19 Nov 12, 2017
7cd5a28
instruction decoder
poosomooso Nov 13, 2017
a30a04b
recursive fib
poosomooso Nov 13, 2017
94ca9b9
Create instruction_memory.v
JosephLee19 Nov 14, 2017
955224a
Added controller
bwerth Nov 15, 2017
e317d55
Added some things to the controller
bwerth Nov 15, 2017
9207766
controller
poosomooso Nov 15, 2017
7c99460
starter for cpu, added files we forgot
poosomooso Nov 16, 2017
ad68f34
includes for cpu
poosomooso Nov 16, 2017
90b0e1f
some work on the cpu
poosomooso Nov 16, 2017
beb3540
Finished most of the implementation
bwerth Nov 17, 2017
f069d63
most of the way there; in the middle of debugging
poosomooso Nov 16, 2017
a72e477
something that compiles but doesn't work, also has gratuitous print s…
poosomooso Nov 17, 2017
e5f928a
test script
poosomooso Nov 17, 2017
b469bf2
added a makefile for better compiling
poosomooso Nov 17, 2017
7c3b672
change mode of run.sh
poosomooso Nov 17, 2017
e9c6d00
debugged pc problem, renamed some variables, updated runsh
poosomooso Nov 19, 2017
d7091a2
fixed issue with writing with registers, made registers readable
poosomooso Nov 20, 2017
c5997b2
fixed some controller bugs
poosomooso Nov 23, 2017
5394abf
things work i think
poosomooso Nov 23, 2017
6baf79f
fixed some bugs in controller, muxes, registers; updated the program …
poosomooso Nov 26, 2017
fc07f3d
Added full path in instruction_memory.v for mem.dat and fixed data me…
bwerth Nov 27, 2017
26b4b0f
Fixed a thing
bwerth Nov 27, 2017
4bb9dbf
Data memory is working
bwerth Nov 27, 2017
6778f0d
fib works, deleted prints
poosomooso Nov 28, 2017
ab1fdfd
fixed a test
poosomooso Nov 28, 2017
11a7f07
actually fixed the test
poosomooso Nov 28, 2017
d947724
merging assembly tests
poosomooso Nov 28, 2017
c9e88ef
Added test bed for instruction_memory.t.v
bwerth Nov 28, 2017
8e466d0
Merge branch 'master' of https://github.com/poosomooso/Lab3
bwerth Nov 28, 2017
bb3e2c4
Fixed the instruction memory test bench
bwerth Dec 2, 2017
df84abd
Add files via upload
bwerth Dec 2, 2017
7d55d3c
changed default width and added datamemory testbench
JosephLee19 Dec 2, 2017
15b113f
added datamemory.t.v to dependencies
JosephLee19 Dec 2, 2017
53e7304
Finished writeup
JosephLee19 Dec 2, 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 @@
*.o
*.out
*.vvp
*.vcd
vivado*
Binary file added Block_Diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
164 changes: 164 additions & 0 deletions CPUcontroller.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@

/*

add: 000000 100000
addi: 001000
sub: 000000 100011
j 000010
jal: 000011
jr: 000000 001000
bne: 000101
xori: 001110
sw: 101011
lw: 100011
slt: 000000 101010

*/

`include "alu.v"

`define arith 6'b000000
`define addi 6'b001000
`define j 6'b000010
`define jal 6'b000011
`define bne 6'b000101
`define xori 6'b001110
`define sw 6'b101011
`define lw 6'b100011

`define add 6'b100000
`define sub 6'b100010
`define jr 6'b001000
`define slt 6'b101010


module CPUcontroller (
input [5:0] opcode, funct,
output reg [2:0] ALU3,
output reg dataWriteMuxSlt, writeback, notBNE, // writeback chooses where the output goes
output reg [1:0] operand2MuxSlt, regWriteAddrSlt, PCmux,
output reg reg_we, dm_we
);

//for adders
// ALU0 <= `opADD;
// ALU1 <= `opADD;
// ALU2 <= `opADD;

always @ (*) begin

casex(opcode)
`addi: begin
dataWriteMuxSlt <= 1'd1;
operand2MuxSlt <= 2'd2;
regWriteAddrSlt <= 2'd0;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
writeback <= 1'd0;
ALU3 <= `opADD;
end
`j: begin
PCmux <= 2'd1;
notBNE<=1'd1;
reg_we <= 1'd0;
dm_we<= 1'd0;
end
`jal: begin
dataWriteMuxSlt <= 1'd0;
regWriteAddrSlt <= 2'd2;
PCmux <= 2'd1;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
end
`bne: begin
PCmux <= 2'd2;
notBNE<=1'd0;
reg_we <= 1'd0;
dm_we<= 1'd0;
ALU3 <= `opSUB;
end
`xori: begin
dataWriteMuxSlt <= 1'd1;
operand2MuxSlt <= 2'd1;
regWriteAddrSlt <= 2'd0;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
writeback <= 1'd0;
ALU3 <= `opXOR;
end
`sw: begin
operand2MuxSlt <= 2'd2;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd0;
dm_we<= 1'd1;
ALU3 <= `opADD;
end
`lw: begin
dataWriteMuxSlt <= 1'd1;
operand2MuxSlt <= 2'd2;
regWriteAddrSlt <= 2'd0;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
writeback <= 1'd1;
ALU3 <= `opADD;
end
`arith: begin
case(funct)
`add: begin
dataWriteMuxSlt <= 1'd1;
operand2MuxSlt <= 2'd0;
regWriteAddrSlt <= 2'd1;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
writeback <= 1'd0;
ALU3 <= `opADD;
end
`sub: begin
dataWriteMuxSlt <= 1'd1;
operand2MuxSlt <= 2'd0;
regWriteAddrSlt <= 2'd1;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
writeback <= 1'd0;
ALU3 <= `opSUB;
end
`jr: begin
PCmux <= 2'd0;
notBNE<=1'd1;
reg_we <= 1'd0;
dm_we<= 1'd0;
end
`slt: begin
dataWriteMuxSlt <= 1'd1;
operand2MuxSlt <= 2'd0;
regWriteAddrSlt <= 2'd1;
PCmux <= 2'd2;
notBNE<=1'd1;
reg_we <= 1'd1;
dm_we<= 1'd0;
writeback <= 1'd0;
ALU3 <= `opSLT;
end
endcase

end
default: begin
reg_we <= 1'd0;
dm_we<= 1'd0;
end
endcase
end

endmodule
58 changes: 58 additions & 0 deletions adder.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Adder circuit

module structuralFullAdder
(
output sum,
output carryout,
input a,
input b,
input carryin
);

wire ab;
xor aXORb(ab, a, b);
xor abXORc(sum, ab, carryin);

wire aAndb, oneAndC;
and aANDb(aAndb, a, b);
and aXORbANDc(oneAndC, ab, carryin);
or aorborc(carryout, aAndb, oneAndC);

endmodule

module FullAdder32bit
(
output[31:0] sum,
output carryout,
output overflow,
input[31:0] a,
input[31:0] b
);
wire[31:0] carry;
wire[31:0] over;
assign carry[0] = 1'b0;
genvar i;
generate
for (i=0; i<31; i=i+1)begin : add_block
structuralFullAdder add0 (sum[i], carry[i+1], a[i], b[i], carry[i]);
end
endgenerate
structuralFullAdder add0 (sum[31], carryout, a[31], b[31], carry[31]);
xor overflowCheck(overflow, carry[31], carryout);
endmodule

module Subtractor32bit
(
input[31:0] a, b,
output[31:0] sum,
output carryout, overflow
);

wire[31:0] notb, b2comp;
wire unusedCarryout, invertingOverflow, totalOverflow;

not32 notbgate (notb, b);
FullAdder32bit add1tob(b2comp, unusedCarryout, invertingOverflow, notb, 32'd1);
FullAdder32bit getsum(sum, carryout, totalOverflow, a, b2comp);
or overflowgate(overflow, totalOverflow, invertingOverflow);
endmodule
Loading