This repository has been archived on 2023-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
cse141L-project/RTL/RegFile.sv

35 lines
959 B
Systemverilog
Raw Normal View History

2022-08-14 23:05:44 +00:00
// Module Name: RegFile
2022-08-13 23:36:00 +00:00
// Project Name: CSE141L
// Description: register file
2022-08-12 05:01:28 +00:00
module RegFile #(parameter W=8, D=4)( // W = data path width (leave at 8); D = address pointer width
2022-08-26 04:02:47 +00:00
input logic Clk, Reset, WriteEn,
input logic [D-1:0] RaddrA, RaddrB, Waddr, // read anad write address pointers
input logic [W-1:0] DataIn, // data to be written
input logic start, // start signal from testbench
2022-08-26 04:02:47 +00:00
output logic [W-1:0] DataOutA, DataOutB // data to read out
2022-08-13 23:36:00 +00:00
);
logic [W-1:0] Registers[2**D]; // 2^D registers of with W
// combination read
assign DataOutA = Registers[RaddrA];
assign DataOutB = Registers[RaddrB];
2022-08-12 05:01:28 +00:00
2022-08-13 23:36:00 +00:00
// sequential (clocked) writes
always_ff @ (posedge Clk) begin
if (Reset) begin // reset all registers to 0 when reset
for(int i=0; i<2**D; i++) begin
Registers[i] <= 'h0;
end
end
else if (start) begin
Registers[Waddr] <= DataIn;
2022-08-13 23:36:00 +00:00
end
else if (WriteEn) begin
Registers[Waddr] <= DataIn;
end
end
2022-08-12 05:01:28 +00:00
endmodule