[英]Why is iverilog complaining about my testbench module?
我正在为我的CompSci类编写一个verilog模块,该模块专门是数据存储模块。 从结构上和分析上,我正在研究它,并且它应该根据我拥有的其他文件来工作,但是我不确定为什么这个文件专门起作用并赋予我所有的x。 希望有新的眼光可以帮助您找到我错过的错误。 提前致谢。
datamem.v:
module datamem(Ina, Inb, enable, readwrite, dataOut, clk, rst);
input wire [31:0] Ina;
input wire [31:0] Inb;
input wire enable;
input wire readwrite;
input wire clk;
input wire rst;
reg [31:0] memory[0:65535];
output reg [31:0] dataOut;
always @(memory[Ina]) begin
dataOut = memory[Ina];
end
always @(posedge clk) begin
if(1'b1 == readwrite) begin
memory[Ina] = Inb;
end
end
endmodule
datamem_tb.v:
module datamem_tb();
reg [31:0] Ina;
reg [31:0] Inb;
reg enable;
reg readwrite;
reg clk;
reg rst;
wire [31:0] dataOut;
datamem DUT (Ina, Inb, enable, readwrite, dataOut, clk, rst);
initial
begin
Ina <= 32'd0;
Inb <= 32'd0;
enable <= 0;
readwrite <= 0;
#20 Ina <= 32'd1234;
#20 Inb <= 32'd1234;
#20 Ina <= 32'd0517;
#20 Inb <= 32'd10259;
end
always @(Ina or Inb)
#1 $display("| Ina = %d | Inb = %d | dataOut = %d |", Ina, Inb, dataOut);
endmodule
关于为什么得到所有'x
几件事:
initial begin
clk = 1'b0;
forever #5 clk = ~clk;
end
readwrite
(您在第20行将其设置为0
且从不更改)。 无需写入, memory
将为每个元素保留其原始值'x
除此之外,您的模块还有其他一些问题:
always @(memory[inA])
always @(*)
使用always @(*)
) memory[inA] <= inB
) $monitor
而不是$display
以避免计时问题,并且只需要在测试台的initial
块的开头调用它( http://referencedesigner.com/tutorials/verilog/verilog_09.php ) rst
和enable
arent的连接到任何东西。 存储单元实现的另一个示例可以在这里找到: 数据存储单元
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.