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

40 lines
1.1 KiB
Systemverilog
Raw Normal View History

2022-08-13 23:36:00 +00:00
// Module Name: ALU
// 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-13 23:36:00 +00:00
input Clk, Reset, WriteEn,
input [D-1:0] RaddrA, RaddrB, Waddr, // read anad write address pointers
input [W-1:0] DataIn, // data to be written
input Zero_in, Done_in, // since flags are stored in register file, need this as an input
output logic [W-1:0] DataOutA, DataOutB, // data to read out
output logic Zero_out, Done_out // output of zero and done flags
);
logic [W-1:0] Registers[2**D]; // 2^D registers of with W
logic Zero, Done;
// combination read
assign DataOutA = Registers[RaddrA];
assign DataOutB = Registers[RaddrB];
assign Zero_out = Zero;
assign Done_out = Done;
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
Zero <= 0;
Done <= 1; // default Done to halt machine
2022-08-13 23:36:00 +00:00
end
else if (WriteEn) begin
Registers[Waddr] <= DataIn;
Zero <= Zero_in;
Done <= Done_in;
end
end
2022-08-12 05:01:28 +00:00
endmodule