verilog调试
我不知道下面的代码有什么问题。有人可以帮我调试吗?
module iloop(z,a);
input [31:0] a;
output z;
reg [4:0] i;
reg s, z;
initial begin
s = 0;
for(i=0; i<32; i=i+1) s = s | a[i];
z = !s;
end
endmodule
I don't know what is wrong with the code below. Can someone help me debug?
module iloop(z,a);
input [31:0] a;
output z;
reg [4:0] i;
reg s, z;
initial begin
s = 0;
for(i=0; i<32; i=i+1) s = s | a[i];
z = !s;
end
endmodule
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码有一个无限循环。您已将
i
声明为 5 位寄存器,这意味着它的值范围是(十进制)0 到 31。但是,您的 for 循环会检查i
i
i
i
i
i
i 32
,这始终是正确的。一旦 i=31,
i
就会递增并翻转到 0。$display
是你的朋友。如果将其添加到 for 循环中,您将看到问题:我认为您想要
i<31
。或者,也许您想使用按位 OR 运算符将
a
的所有位组合在一起:您应该用文字解释您想要实现的目标。
Your code has an infinite loop. You have declared
i
as a 5-bit reg, which means its range of values is (decimal) 0 to 31. But, your for loop checks ifi < 32
, which is always true.Once i=31,
i
is incremented and rolls over to 0.$display
is your friend. If you add it to your for loop, you will see the problem:I think you want
i<31
.Or, maybe you want to OR all the bits of
a
together, using the bit-wise OR operator:You should explain in words what you are trying to achieve.