【发布时间】:2016-03-21 12:54:17
【问题描述】:
这里有一些在 Verilog 中定义二维线数组的简单代码。
module test(a, b, c);
input [63:0] a;
input [63:0] b;
output [63:0] c [63:0];
endmodule
当我编译代码时,我得到了这个错误。
Illegal reference to net array "c".
【问题讨论】:
这里有一些在 Verilog 中定义二维线数组的简单代码。
module test(a, b, c);
input [63:0] a;
input [63:0] b;
output [63:0] c [63:0];
endmodule
当我编译代码时,我得到了这个错误。
Illegal reference to net array "c".
【问题讨论】:
我不认为这个问题https://stackoverflow.com/questions/3011510/... 有助于解决这个特定问题。
您会收到此错误,因为在 Verilog(2009 年之前,当它合并到 SystemVerilog 时)具有二维(或更多)维数组的端口是非法的;对于端口上的数组,只允许简单的一维向量。
您可以拥有两个(或更多)维的网络或变量数组,因为这个问题确实解释了https://stackoverflow.com/questions/3011510/...。
值得注意的是,System-Verilog中没有这样的限制(或者:允许多维数组。
【讨论】:
虽然 Verilog 不允许定义二维或多维网络数组,但使用“生成”语句有一个很好的解决方法。您可以生成一组连线,然后使用特定的迭代对其进行寻址。这是一个例子:
module Example (
input[7:0] in,
output[7:0] out
);
generate
genvar i;
for (i=0; i<=7; i=i+1) begin: stage
wire[7:0] net;
if (i!=0) assign net = stage[i-1].net;
end
endgenerate
assign stage[0].net = in;
assign out = stage[7].net;
endmodule
在这个例子中,创建了一个 8*8 的线阵列,它们使用前一次迭代的说明符顺序连接,之后第一次和最后一次迭代连接到模块的输入和输出。
以类似的方式,您可以创建 3 维或更多维数组。
【讨论】: