【问题标题】:Initialization of array error in VerilogVerilog中数组错误的初始化
【发布时间】:2012-10-26 13:26:08
【问题描述】:

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

“=”附近:语法错误,意外的“=”,需要 IDENTIFIER 或 TYPE_IDENTIFIER

我用的是modelsim模拟器

【问题讨论】:

    标签: verilog system-verilog hdl array-initialization


    【解决方案1】:

    您用于数组赋值的语法仅在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
    };
    

    【讨论】:

      【解决方案2】:

      分配应该在initialalways 块内:

      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
      

      【讨论】:

        猜你喜欢
        • 2014-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-23
        相关资源
        最近更新 更多