gpt4 book ai didi

verilog - Verilog中数组初始化错误

转载 作者:行者123 更新时间:2023-12-02 17:47:22 26 4
gpt4 key购买 nike

当我初始化数组 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。它显示的错误:

near "=": syntax error, unexpected '=', expecting IDENTIFIER or TYPE_IDENTIFIER

我用的是modelsim模拟器

最佳答案

您用于数组赋值的语法仅在 SystemVerilog 中有效,在 Verilog 中无效。

所以你的编译器需要支持这个,你需要告诉编译器这个文件是SystemVerilog。大多数编译器(包括 modelsim)将根据扩展名假定文件类型,例如.v == Verilog.sv == SystemVerilog,而其他的则需要转换。

此外,正如 toolic 的回答中所指出的,您需要将赋值放在 initial block 中,或者您可以将声明与赋值结合起来,如下所示:

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
};

关于verilog - Verilog中数组初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13087867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com