是否可以在“生成”内部增加/初始化变量?在verilog中?
我对generate
有疑问,我的代码是:
parameter m=1;
generate
for(i=0; i<m; i=i+1) :loopstart
begin
statements;
end
endgenerate
在这个循环中,m应该是2^0、2^1、2^2等等。自从 不支持求幂,我想到了初始化m然后 每次迭代时将其乘以 2。
我有几个问题:
是否可以使用 m << 1
以某种方式生成(因为这与 乘以 2)?如果我这样做,就会导致错误。
我参考了 Samir Palnitkar 的书,其中说always 语句在生成中有效,所以我尝试:
always @(m)
m <= m*2; // (or m << 1)
这不起作用。我意识到这是不可能的,因为 m
是一个参数而不是一个变量。
如果我的想法是正确的,那么也不能用 genvar 来完成,因为 genvar 无法初始化。
还有其他选择吗?
I have a doubt in the generate
, my code is:
parameter m=1;
generate
for(i=0; i<m; i=i+1) :loopstart
begin
statements;
end
endgenerate
Inside this loop, m should be 2^0, 2^1, 2^2, and so on. Since
exponentiation is not supported, I thought of initializing m and then
multiplying it by 2 on each iteration.
I have a few questions:
Is it possible to use m << 1
inside the generate in some way (since this is the same as
multiplying by 2)? If I do that, it results in an error.
I referred to Samir Palnitkar's book, which says that always statement works inside a generate, so I tried:
always @(m)
m <= m*2; // (or m << 1)
This doesn't work. I realize it can't be done because m
is a parameter and not a variable.
If what I think is right, it can't be done with genvar
either, since a genvar
can't be initialized.
Is there an alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题似乎是因为不支持指数而产生的。它们是:
注意:
由于某些原因,这是错误的
<=
我还会避免命名敏感度列表,并使用
always @*
来避免因不完整的敏感度列表而导致硬件模拟不匹配。参数和本地参数用于定义常量,如果它们不是常量,则使用其他类型,例如逻辑或整数类型。
The question seem to have been created because exponentials are not supported. They are :
NB:
This is wrong for a few reasons
<=
in combinatorial blocksI would also avoid named sensitivity lists and use
always @*
to avoid hardware simulation mismatches from incomplete sensitivity lists.parameters and localparams are for defining constants, if they are not constant use something else like a logic or integer type.
相反,
i++
使用i=i+1
并且......忘记 C。
Instead
i++
usei=i+1
And.. forget C.