问题描述
我尝试在 always 块中查看与 for 循环相关的不同帖子,但我的问题看起来有所不同.这是我感兴趣的代码部分:
I have tried looking at different posts related to for loop inside an always block but my problem looks different. Here's the part of my code of interest :
always@(posedge clk) begin
for(i=2;i<UP_SPACES+2;i=i+1) begin //Ram_out
if(up_addr_d2[3:0]==i)
begin
up_dout_t2 <= ram_out[(i+1)*32-1:i*32];
end
end// for loop
end
我已将 i 声明为整数.此处编译器给出错误i 不是常量".我不确定是否可以通过这种方式进行编码,并且预计会出现多驱动程序错误,但我不明白这个错误.请投灯.
I have declared i as an integer. Here the compiler gives the error 'i is not a constant'. I was not sure if one can code this way and was expecting a multidriver error but this error i dont understand. Please throw light.
推荐答案
此行不合法:
up_dout_t2 <= ram_out[(i+1)*32-1:i*32];
在部分选择中使用冒号右侧的变量值是非法的.基本上,这是非法的:
It is illegal to have a variable value of the right hand side of the colon in a part-select. Basically, this is illegal:
i[a+3 : a]
相反,你必须说:
i[a+3 -: 4]
其中a+3
是起始索引,-:
表示倒计时,4
是宽度.所以,而不是
where a+3
is the starting index, -:
means count down and 4
is the width. So, instead of
i[a : a+3]
你必须说:
i[a +: 4]
i
的索引方向无关紧要.这些代码行适用于
The direction of the index of i
doesn't matter. These lines of code would work for either
reg [big:little] i;
或
reg [little:big] i;
因此,您的代码行应该是:
So, your line of code should be:
up_dout_t2 <= ram_out[(i+1)*32-1 -: 32];
或:
up_dout_t2 <= ram_out[i*32 +: 32];
这篇关于带有条件语句的 always 块内的 For 循环给出了意外错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!