Verilog 编译错误:意外的“[”,期望“IDENTIFIER”或“TYPE_IDENTIFIER”或'#'或'('
我想设计一个带有生成结构和二维内存的简单乘法器。但我无法编译以下 verilog 代码。有人可以给一些提示吗?
module classic_multiplier(
a, b,
a_by_b);
parameter M = 2;
input [M-1:0] a, b;
output reg [M-1:0] a_by_b [0:2*M-2];
//the first and
genvar i, k;
generate begin
for(k = 0; k <= M-1; k=k+1) begin
for(i = 0; i <= k; i=i+1) begin
a_by_b[k][i] = a[i] & b[k-i];
end
end
end
endgenerate
endmodule
I want to design a simple multiplier with the generate construct and two dimensional memory. But I can not compile the following verilog code. Could anyone give some hint please?
module classic_multiplier(
a, b,
a_by_b);
parameter M = 2;
input [M-1:0] a, b;
output reg [M-1:0] a_by_b [0:2*M-2];
//the first and
genvar i, k;
generate begin
for(k = 0; k <= M-1; k=k+1) begin
for(i = 0; i <= k; i=i+1) begin
a_by_b[k][i] = a[i] & b[k-i];
end
end
end
endgenerate
endmodule
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的问题似乎是您有一个 2D 输出端口 (
a_by_b
)。我不太确定为什么你需要它作为乘法器,输出端口大小应该是2*M
,所以:另外,不需要
begin
> 在generate
之后(因此不需要匹配end
),但是好吧,这不是真正的问题,如果您愿意,您可以添加它们。接下来,需要为
generate
块内的for循环命名,例如:当然,如果更改
a_by_b。
It seems the problem here is that you have a 2D output port (
a_by_b
). I'm not quite sure why you would need it for a multiplier anyway, the output port size should be2*M
, so:Also, there is no need for the
begin
aftergenerate
(and thus no need either for the matchingend
), but ok, that's not really the problem here, you can add them if you want.Next, for loops inside a
generate
block need to be named, for example:Of course, you will need to change the code inside the for loops if you change the definition of
a_by_b
.当工具看到a_by_b[k][i] = a[i] & b[ki]; 它确保 a_bay_b 是一个模块。在该行中添加
assign
或always @*
前缀,该工具将接受该代码。生成块在编译细化期间扩展代码。使用给定的代码:
将扩展为:
使用
assign
的正确代码:将计算为:
或使用
always @*
:将计算为:
或者,可以使用单个always块在没有生成块的情况下使用:
When the tool sees
a_by_b[k][i] = a[i] & b[k-i];
it assures that a_bay_b is a module. Prefix anassign
oralways @*
to the line and the tool will accept accept the code.A generate blocks expands the code during the compile elaboration time. With the given code:
Will expand to:
The correct code with
assign
:Will evaluate to:
Or with
always @*
:Will evaluate to:
Alternatively an single always block can be used without a generate block: