寄存器堆
module Register(
input [4:0] R_Addr_A,
input [4:0] R_Addr_B,
input [4:0] W_Addr,
input Write_Reg,
input [31:0] Write_Data,
input clk,
input reset,
output [31:0] R_Data_A,
output [31:0] R_Data_B
);
reg [31:0] REG [0:31];
integer i = 0;
always@(posedge clk,negedge reset)
begin
if(!reset)
while(i<=31) begin
REG[i] <= 0;
i = i+1;
end
else
if(Write_Reg)
REG[W_Addr] <= Write_Data;
end
assign R_Data_A = REG[R_Addr_A];
assign R_Data_B = REG[R_Addr_B];
endmodule
寄存器堆测试文件
module test;
reg [4:0] R_Addr_A;
reg [4:0] R_Addr_B;
reg [4:0] W_Addr;
reg Write_Reg;
reg [31:0] Write_Data;
reg clk;
reg reset;
wire [31:0] R_Data_A;
wire [31:0] R_Data_B;
Register uut (
.R_Addr_A(R_Addr_A),
.R_Addr_B(R_Addr_B),
.W_Addr(W_Addr),
.Write_Reg(Write_Reg),
.Write_Data(Write_Data),
.clk(clk),
.reset(reset),
.R_Data_A(R_Data_A),