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 Deliverable 1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Report.pdf
Binary file not shown.
30 changes: 30 additions & 0 deletions multiplexer.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module mux32to1by1
(
output out,
input[4:0] address,
input[31:0] inputs
);

assign out=inputs[address];

endmodule

module mux32to1by32
(
output[31:0] out,
input[4:0] address,
input[(32 * 32) - 1:0] input0
);

wire[31:0] mux[31:0];

genvar i;
generate
for (i = 0; i < 32; i = i + 1) begin: registers
assign mux[i] = input0[32 * (i + 1) - 1:32 * i];
end
endgenerate

assign out = mux[address];

endmodule
59 changes: 58 additions & 1 deletion regfile.t.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// or broken register files, and verifying that it correctly identifies each
//------------------------------------------------------------------------------

`include "regfile.v"

module hw4testbenchharness();

wire[31:0] ReadData1; // Data from first register read
Expand Down Expand Up @@ -138,11 +140,66 @@ output reg Clk
$display("Test Case 2 Failed");
end

// Test Case 3:
// Write Enable is broken / ignored.
WriteRegister = 5'd2;
WriteData = 32'd1;
RegWrite = 0;
ReadRegister1 = 5'd2;
ReadRegister2 = 5'd2;

#5 Clk=1; #5 Clk=0;

if((ReadData1 == 1) || (ReadData2 == 1)) begin
dutpassed = 0;
$display("Test Case 3 Failed");
end

// Test Case 4:
// Decoder is broken.
WriteRegister = 5'd2;
WriteData = 32'd1;
RegWrite = 1;
ReadRegister1 = 5'd2;
ReadRegister2 = 5'd3;

#5 Clk=1; #5 Clk=0;
if((ReadData1 != 1) || (ReadData2 == 1)) begin
dutpassed = 0;
$display("Test Case 4 Failed");
end

// Test Case 5:
// Register Zero is actually a register.
WriteRegister = 5'd0;
WriteData = 32'd1;
RegWrite = 1;
ReadRegister1 = 5'd0;

#5 Clk=1; #5 Clk=0;
if (ReadData1 != 0) begin
dutpassed = 0;
$display("Test Case 5 Failed");
end

// Test Case 6:
// Port 2 is broken and always reads register 14.
WriteRegister = 5'd2;
WriteData = 32'd1;
RegWrite = 1;
#5 Clk=1; #5 Clk=0;
ReadRegister1 = 5'd2;

#5 Clk=1; #5 Clk=0;
if (ReadData1 != 1) begin
dutpassed = 0;
$display("Test Case 6 Failed");
end

// All done! Wait a moment and signal test completion.
#5
endtest = 1;

end

endmodule
endmodule
26 changes: 23 additions & 3 deletions regfile.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// 1 synchronous, positive edge triggered write port
//------------------------------------------------------------------------------

`include "decoders.v"
`include "multiplexer.v"
`include "register.v"

module regfile
(
output[31:0] ReadData1, // Contents of first register read
Expand All @@ -21,7 +25,23 @@ input Clk // Clock (Positive Edge Triggered)
// These two lines are clearly wrong. They are included to showcase how the
// test harness works. Delete them after you understand the testing process,
// and replace them with your actual code.
assign ReadData1 = 42;
assign ReadData2 = 42;
//assign ReadData1 = 42;
//assign ReadData2 = 42;

wire[31:0] writeFinal;
wire[(32*32) - 1:0] registerFinal;

decoder1to32 decoder(writeFinal, RegWrite, WriteRegister);
register32zero register1(registerFinal[31:0], WriteData, writeFinal[0], Clk);

genvar i;
generate
for (i = 1; i < 32; i = i + 1) begin: allRegisters
register32 register2(registerFinal[32 * (i + 1) - 1:32 * i], WriteData, writeFinal[i], Clk);
end
endgenerate

mux32to1by32 mux1(ReadData1, ReadRegister1, registerFinal);
mux32to1by32 mux2(ReadData2, ReadRegister2, registerFinal);

endmodule
endmodule
32 changes: 32 additions & 0 deletions register.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,36 @@ input clk
end
end

endmodule

module register32
(
output reg [31:0] q,
input [31:0] d,
input wrenable,
input clk
);

always @(posedge clk) begin
if(wrenable) begin
q[31:0] = d[31:0];
end
end

endmodule

module register32zero
(
output reg [31:0] q,
input [31:0] d,
input wrenable,
input clk
);

always @(posedge clk) begin
if(wrenable) begin
q[31:0] = 32'b0;
end
end

endmodule