如何倒入一个包装的阵列
logic [4:0] count_zeros;
logic [2:0] id;
integer i;
logic [7:0] [15:0] vld;
always@*
begin
count_zeros = 5'b0;
for (i=0; i<2; i=i+1)
count_zeros = count_zeros + ~vld[id][i];
end
对于d8
的输入,我将count_zeros
作为1e
。我的预期输出是2。上面的片段中有什么问题?
〜
是一个位否定的,!
是逻辑上的否定。我要去哪里?
logic [4:0] count_zeros;
logic [2:0] id;
integer i;
logic [7:0] [15:0] vld;
always@*
begin
count_zeros = 5'b0;
for (i=0; i<2; i=i+1)
count_zeros = count_zeros + ~vld[id][i];
end
For an input as d8
, I get count_zeros
as 1e
. My expected output is 2. What is wrong in the above snippet?
~
is a bitwise negation and !
is logical negation. Where am I going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Verilog扩展单个位值(
vld [id] [i]
)以匹配其所在的表达式的宽度,这是5位,因为count_zeros
信号。在应用位倒置操作员之前,这是完成的。由于vld [0] [0]
是1'b0
,1'b0
被扩展到5'b00000
。然后〜(5'b00000)
在5'b11111
中结果。创建一个1位信号,例如
temp
,然后将其直接设置为倒数的位值。然后在添加表达式中使用它。请参阅IEEE STD 1800-2017,第11.6节表达位长度。
Verilog expands the single bit value (
vld[id][i]
) to match the width of the expression it is in, which is 5 bits because of thecount_zeros
signal. This is done before the bitwise invert operator is applied. Sincevld[0][0]
is1'b0
,1'b0
is expanded to5'b00000
. Then~(5'b00000)
results in5'b11111
.Create a 1-bit signal, such as
temp
, and directly set it to the inverted bit value. Then use it in the addition expression.Refer to IEEE Std 1800-2017, section 11.6 Expression bit lengths.