nbs*_*jan 1 verilog hdl system-verilog 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
};
Run Code Online (Sandbox Code Playgroud)
这实际上是sbox。显示的错误:
在“ =”附近:语法错误,意外的'=',期望IDENTIFIER或TYPE_IDENTIFIER
我正在使用modelsim模拟器
您用于数组分配的语法仅在中有效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
};
Run Code Online (Sandbox Code Playgroud)