Verilog中数组错误的初始化
当我初始化一个数组Verilog中数组错误的初始化,verilog,system-verilog,hdl,array-initialization,Verilog,System Verilog,Hdl,Array Initialization,当我初始化一个数组sbox时,我得到了语法错误。请帮帮我 reg [7:0] sbox[15:0]; sbox = '{ 8'h63, 8'h7c, 8'h77, 8'h7b, 8'hf2, 8'h6b, 8'h6f, 8'hc5, 8'h30, 8'h01, 8'h67, 8'h2b, 8'hfe, 8'hd7, 8'hab, 8'h76 }; 这实际上是sbox。它显示的错误: 靠近“=”:语法错误,意外“=”,应为标识符或 类型标识符 我正在使用modelsim模拟器作业应
sbox
时,我得到了语法错误。请帮帮我
reg [7:0] sbox[15:0];
sbox = '{
8'h63, 8'h7c, 8'h77, 8'h7b,
8'hf2, 8'h6b, 8'h6f, 8'hc5,
8'h30, 8'h01, 8'h67, 8'h2b,
8'hfe, 8'hd7, 8'hab, 8'h76
};
这实际上是sbox。它显示的错误:
靠近“=”:语法错误,意外“=”,应为标识符或
类型标识符
我正在使用modelsim模拟器作业应该在
初始
或始终
块中:
module tb;
reg [7:0] sbox[15:0];
initial begin
sbox = '{
8'h63, 8'h7c, 8'h77, 8'h7b,
8'hf2, 8'h6b, 8'h6f, 8'hc5,
8'h30, 8'h01, 8'h67, 8'h2b,
8'hfe, 8'hd7, 8'hab, 8'h76
};
end
endmodule
分配应位于
初始
或始终
块内:
module tb;
reg [7:0] sbox[15:0];
initial begin
sbox = '{
8'h63, 8'h7c, 8'h77, 8'h7b,
8'hf2, 8'h6b, 8'h6f, 8'hc5,
8'h30, 8'h01, 8'h67, 8'h2b,
8'hfe, 8'hd7, 8'hab, 8'h76
};
end
endmodule
用于数组分配的语法仅在
SystemVerilog
中有效,而在Verilog
中无效
所以你的编译器需要支持这个,你需要告诉编译器这个文件是SystemVerilog。大多数编译器(包括modelsim)将根据扩展名采用文件类型,例如.v==Verilog
和.sv==SystemVerilog
,而其他编译器则需要开关
此外,正如toolic在回答中指出的,您需要将赋值放在initial
块中,或者您可以将声明与赋值结合起来,如下所示:
reg [7:0] sbox[15:0] = '{
8'h63, 8'h7c, 8'h77, 8'h7b,
8'hf2, 8'h6b, 8'h6f, 8'hc5,
8'h30, 8'h01, 8'h67, 8'h2b,
8'hfe, 8'hd7, 8'hab, 8'h76
};
用于数组分配的语法仅在
SystemVerilog
中有效,而在Verilog
中无效
所以你的编译器需要支持这个,你需要告诉编译器这个文件是SystemVerilog。大多数编译器(包括modelsim)将根据扩展名采用文件类型,例如.v==Verilog
和.sv==SystemVerilog
,而其他编译器则需要开关
此外,正如toolic在回答中指出的,您需要将赋值放在initial
块中,或者您可以将声明与赋值结合起来,如下所示:
reg [7:0] sbox[15:0] = '{
8'h63, 8'h7c, 8'h77, 8'h7b,
8'hf2, 8'h6b, 8'h6f, 8'hc5,
8'h30, 8'h01, 8'h67, 8'h2b,
8'hfe, 8'hd7, 8'hab, 8'h76
};
是的,我也尝试过,但无法编译代码。Iam收到这些错误错误错误:(vlog-2110)对内存“sbox”的非法引用**错误:非法的LHS赋值。这个语法适用于我使用两个不同的模拟器(VCS和Incisive)。也许您的模拟器不支持这种合法语法。或者,您可能需要使用特殊的模拟器选项使其接受语法。阅读你的模拟器文档。是的,我也尝试过,但无法编译代码。Iam收到这些错误错误错误:(vlog-2110)对内存“sbox”的非法引用**错误:非法的LHS赋值。这个语法适用于我使用两个不同的模拟器(VCS和Incisive)。也许您的模拟器不支持这种合法语法。或者,您可能需要使用特殊的模拟器选项使其接受语法。阅读您的模拟器文档。