Verilog错误:范围必须由常量表达式限制 [英] Verilog error: Range must be bounded by constant expressions
本文介绍了Verilog错误:范围必须由常量表达式限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Verilog的新手,我正在为我的课程做一个项目.所以这是我的代码:
I'm new to verilog and I am doing a project for my class. So here is my code:
wire [n-1:0] subcounter_of_counter;
reg [n-1:0] mask,free;
//subcounter_of_counter: dinei ena vector apo poious subcounter apoteleitai o counter(id)
always @(*) begin //command or id or mask or free or subcounter_of_counter
if (command==increment) begin
for (int i = 0; i < n; i=i+1)begin
if (i<id) begin
subcounter_of_counter[i]=1'b0;
end else if (i==id) begin
subcounter_of_counter[i]=1'b1;
end else begin
if( (|mask[id+1:i]) || (|free[id+1:i]) ) begin
subcounter_of_counter[i]=1'b0;
end else begin
subcounter_of_counter[i]=1'b1;
end
end
end
end
end
错误提示范围必须由常量表达式限制."
有什么想法我还能编写它来执行相同的操作吗?
Any ideas how else I could write it to do the same operation?
非常感谢
推荐答案
您需要做的是创建mask
和free
的蒙版和移位版本.
What you will need to do is create a masked and shifted version of mask
and free
.
reg [n-1:0] mask,free,local_mask, local_free;
always @(*) begin //command or id or mask or free or subcounter_of_counter
if (command==increment) begin
local_mask = mask & ((64'b1<<id+1)-1); // clear bits above id+1
local_free = free & ((64'b1<<id+1)-1); // clear bits above id+1
for (int i = 0; i < n; i=i+1)begin
if (i<id) begin
subcounter_of_counter[i]=1'b0;
end else if (i==id) begin
subcounter_of_counter[i]=1'b1;
end else begin
if( (|local_mask) || (|local_free) ) begin
subcounter_of_counter[i]=1'b0;
end else begin
subcounter_of_counter[i]=1'b1;
end
end
end
local_mask = local_mask >> 1; // clear bits below i
local_free = local_free >> 1;
end // for
end // always
我没有尝试这段代码,但希望它能为您指明正确的方向.
I didn't try this code, but hopefully it points you in the right direction.
这篇关于Verilog错误:范围必须由常量表达式限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文