|
楼主 |
发表于 2021-1-20 17:01:29
|
显示全部楼层
模块源码如下:
module Register_Bank #
(
parameter DATA_WIDTH=32,
parameter ADDRESS_WIDTH=4,
parameter PIPE_DEPTH=16
)
(
input CLK,
input Reset,
input [DATA_WIDTH-1:0]W,
input [ADDRESS_WIDTH-1:0]RA,
input [ADDRESS_WIDTH-1:0]RB,
input [ADDRESS_WIDTH-1:0]RW,
input WE,
output [DATA_WIDTH-1:0]A,
output [DATA_WIDTH-1:0]B
);
reg [DATA_WIDTH-1:0]mem[PIPE_DEPTH-1:0];
reg [DATA_WIDTH-1:0]A_reg;
reg [DATA_WIDTH-1:0]B_reg;
//RA port read
always@(posedge CLK or negedge Reset)
begin
if(~Reset)
begin
A_reg<=0;
end
else
begin
if(~WE)
begin
A_reg<=mem[RA];
end
end
end
assign A=A_reg;
//RB port read
always@(posedge CLK or negedge Reset)
begin
if(~Reset)
begin
B_reg<=0;
end
else
begin
if(~WE)
begin
B_reg<=mem[RB];
end
end
end
assign B=B_reg;
//Write port
always@(posedge CLK)
begin
if(WE)
begin
mem[RW]<=W;
end
end
endmodule |
|