|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
实现一个两个输入地址两个输出数据的寄存器,代码放下面,给了一些注释。verilog仿真出来两个输出的rdata都是0,不知道是design文件出了问题还是testbench出了问题,有好心的大佬能不能帮忙看看?谢谢!!
design文件:
`define DATA_WIDTH 32
`define ADDR_WIDTH 5
module reg_file(
input clk,
input rst,
input [`ADDR_WIDTH - 1:0] waddr,
input [`ADDR_WIDTH - 1:0] raddr1,
input [`ADDR_WIDTH - 1:0] raddr2,
input wen,
input [`DATA_WIDTH - 1:0] wdata,
output [`DATA_WIDTH - 1:0] rdata1,
output [`DATA_WIDTH - 1:0] rdata2
);
integer i;
reg [31:0]r[0:4];
initial
for(i=0; i<5; i=i+1)
r[i] <= 0;
always @ (posedge clk)
begin
if(rst)
for(i=0; i<5; i=i+1)
r[i] <= 0;
else
if(wen)
if(waddr != 0)
r[waddr] <= wdata;
else
r[waddr] <= 0;
end
assign rdata1 = r[raddr1];
assign rdata2 = r[raddr2];
endmodule
testbench文件:
`define DATA_WIDTH 32
`define ADDR_WIDTH 5
module reg_file_tb();
reg clk;
reg rst;
reg [`ADDR_WIDTH - 1:0] waddr;
reg wen;
reg [`DATA_WIDTH - 1:0] wdata;
reg [`ADDR_WIDTH - 1:0] raddr1;
reg [`ADDR_WIDTH - 1:0] raddr2;
wire [`DATA_WIDTH - 1:0] rdata1;
wire [`DATA_WIDTH - 1:0] rdata2;
initial begin
clk = 0;
forever #5 clk = ~clk;
end
initial begin
rst = 1;
wen = 1;
end
initial begin
waddr = 1;
#5 waddr = 2;
#5 waddr = 3;
#5 waddr = 4;
#5 waddr = 0;
end
initial begin
wdata = 132;
#5 wdata = 189;
#5 wdata = 2;
#5 wdata = 65;
#5 wdata = 233;
end
initial begin
raddr1 = 0;
#5 raddr1 = 1;
#5 raddr1 = 2;
#5 raddr1 = 3;
#5 raddr1 = 4;
end
initial begin
raddr2 = 1;
#5 raddr2 = 2;
#5 raddr2 = 3;
#5 raddr2 = 4;
#5 raddr2 = 0;
end
reg_file u_reg_file(
.clk(clk),
.rst(rst),
.waddr(waddr),
.raddr1(raddr1),
.raddr2(raddr2),
.wen(wen),
.wdata(wdata),
.rdata1(rdata1),
.rdata2(rdata2)
);
endmodule
(简单起见只随便列了几个状态,将就着看看~) |
|