MIPS_Processor/sources_1/imports/single-cycle/RegisterFile.v

39 lines
1.2 KiB
Coq
Raw Permalink Normal View History

2024-06-29 06:20:54 +00:00
module RegisterFile(
input reset ,
input clk ,
input RegWrite ,
2024-06-30 15:01:11 +00:00
input Regwrite2 ,
2024-06-29 06:20:54 +00:00
input [5 -1:0] Read_register1 ,
input [5 -1:0] Read_register2 ,
input [5 -1:0] Write_register ,
2024-06-30 15:01:11 +00:00
input [5 -1:0] Write_register2,
2024-06-29 06:20:54 +00:00
input [32 -1:0] Write_data ,
2024-06-30 15:01:11 +00:00
input [32 -1:0] Write_data2 ,
2024-06-29 06:20:54 +00:00
output [32 -1:0] Read_data1 ,
output [32 -1:0] Read_data2
);
// RF_data is an array of 32 32-bit registers
// here RF_data[0] is not defined because RF_data[0] identically equal to 0
reg [31:0] RF_data[31:1];
// read data from RF_data as Read_data1 and Read_data2
assign Read_data1 = (Read_register1 == 5'b00000)? 32'h00000000: RF_data[Read_register1];
assign Read_data2 = (Read_register2 == 5'b00000)? 32'h00000000: RF_data[Read_register2];
integer i;
// write Wrtie_data to RF_data at clock posedge
always @(posedge reset or posedge clk)
if (reset)
for (i = 1; i < 32; i = i + 1)
RF_data[i] <= 32'h00000000;
2024-06-30 16:24:09 +00:00
else
begin
if (RegWrite && (Write_register != 5'b00000))
2024-06-29 06:20:54 +00:00
RF_data[Write_register] <= Write_data;
2024-06-30 16:24:09 +00:00
if (Regwrite2 && (Write_register2 != 5'b00000))
2024-06-30 15:01:11 +00:00
RF_data[Write_register2] <= Write_data2;
2024-06-30 16:24:09 +00:00
end
2024-06-29 06:20:54 +00:00
endmodule