JavaEar 专注于收集分享传播有价值的技术资料

Verilog错误:范围必须由常量表达式限制 (Verilog error: Range must be bounded by constant expressions)

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

And the error says "the range must be bounded by constant expressions."

Any ideas how else I could write it to do the same operation?

Thanks a lot

1个回答

    最佳答案

  1. 英文原文

    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.


    中文翻译

    您需要做的是创建 mask free 的蒙版和移位版本。

      reg [n-1:0] mask,free,local_mask,local_free;
    始终@(*)开始//命令或id或掩码或free或subcounter_of_counter
    if(command == increment)开始
        local_mask = mask&amp; ((64'b1&LT;&LT;编号+ 1)-1); //清除id + 1以上的位
        local_free =免费&amp; ((64'b1&LT;&LT;编号+ 1)-1); //清除id + 1以上的位
        for(int i = 0; i&lt; n; i = i + 1)开始
            if(i&lt; id)开始
                subcounter_of_counter [I] = 1'b0;
            如果(i == id)开始,则结束
                subcounter_of_counter [I] = 1'b1的;
            结束其他开始
                if((| local_mask)||(| local_free))开始
                    subcounter_of_counter [I] = 1'b0;
                结束其他开始
                    subcounter_of_counter [I] = 1'b1的;
                结束
            结束
        结束
    local_mask = local_mask&gt;&gt; 1; //清除以下位
    local_free = local_free&gt;&gt; 1;
    结束//为
    结束//永远
     

    我没有尝试过这段代码,但希望它能指出你正确的方向。

    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.

    您需要做的是创建 mask free 的蒙版和移位版本。

      reg [n-1:0] mask,free,local_mask,local_free;
    始终@(*)开始//命令或id或掩码或free或subcounter_of_counter
    if(command == increment)开始
        local_mask = mask&amp; ((64'b1&LT;&LT;编号+ 1)-1); //清除id + 1以上的位
        local_free =免费&amp; ((64'b1&LT;&LT;编号+ 1)-1); //清除id + 1以上的位
        for(int i = 0; i&lt; n; i = i + 1)开始
            if(i&lt; id)开始
                subcounter_of_counter [I] = 1'b0;
            如果(i == id)开始,则结束
                subcounter_of_counter [I] = 1'b1的;
            结束其他开始
                if((| local_mask)||(| local_free))开始
                    subcounter_of_counter [I] = 1'b0;
                结束其他开始
                    subcounter_of_counter [I] = 1'b1的;
                结束
            结束
        结束
    local_mask = local_mask&gt;&gt; 1; //清除以下位
    local_free = local_free&gt;&gt; 1;
    结束//为
    结束//永远
     

    我没有尝试过这段代码,但希望它能指出你正确的方向。