本声明:
reg [7:0] register_file [3:0] = 0;
产生此错误:
Error (10673): SystemVerilog error at simpleprocessor.v(27): assignments to unpacked arrays must be aggregate expressions
首先我使用的是Verilog,而不是SystemVerilog,为什么它会给我一个SystemVerilog错误?
其次,这个错误的原因是什么,我该如何解决?我在一个非常粗鲁的处理器的设计中使用它来将内部工作寄存器表示为多维内存数组。
我的寄存器可以直接从指令中访问。例如,这一行:
register_file[instruction[5:4]] <= register_file[instruction[3:2]] + register_file[instruction[1:0]];
但它没有用。有什么想法吗?
答案 0 :(得分:1)
您隐含了内存但未指定要设置为0的位置。
您可以使用汇总表达式来定义一行中的所有值:
reg [7:0] register_file [3:0] = {8'b0, 8'b0, 8'b0, 8'b0};
如果是fpga,你也可以使用initial
:
reg [7:0] register_file [3:0];
initial begin
for(int i=0; i<4; i++) begin
register_file[i] = 8'b0
end
end
在此瞬间,循环可以静态展开,因此是可合成的。
NB Verilog已折旧。 Verilog标准已于2009年与SystemVerilog合并,SystemVerilog 2012是最新版本。
答案 1 :(得分:1)
来自SystemVerilog LRM:
术语打包数组用于指代在数据标识符名称之前声明的维度。术语解压缩数组用于指代在数据标识符名称之后声明的维度。
bit [7:0] c1; // packed array of scalar bit types
real u [7:0]; // unpacked array of real types
您已声明解压缩数组,因此无法将其分配给值,因此会显示错误消息。使用解压缩的数组,您必须使用聚合表达式来分配整个数组:
logic [7:0] register_file [3:0] = {8'b0, 8'b0, 8'b0, 8'b0};
如果您声明压缩数组,则可以将其指定为平面向量:
logic [7:0][3:0] register_file = '0;