【问题标题】:Assign a 2-dim real array in Verilog在 Verilog 中分配一个二维实数数组
【发布时间】:2021-09-12 16:01:29
【问题描述】:

我想在 Verilog 中分配一个二维实数数组。

下面的类似 C 的 approach 不起作用。

`timescale 1ns/10ps

module twodim ();
  
real xy[0:2][0:1] = {{1, 1}, {2, 4}, {3, 9}};
  
initial begin
  int n = 1;
  $display ("x[n] = %f y[n] = %f", xy[n][0], xy[n][1]);
  #1  $finish;
end
  
endmodule

正确的方法是什么?

【问题讨论】:

    标签: arrays verilog system-verilog


    【解决方案1】:

    EDAplayground 是 SystemVerilog,您需要使用的语法是分配模式。 '{}。这是因为 Verilog 已经使用 {} 进行积分连接。您只能将{} 用于数组的单个维度。

    module twodim ();
      
    real xy[0:2][0:1] = '{'{1, 1}, '{2, 4}, '{3, 9}};
      
    initial begin
      int n; // static variable 
      n = 1;
      $display ("x[n] = %f y[n] = %f", xy[n][0], xy[n][1]);
      #1  $finish;
    end
      
    endmodule
    

    【讨论】:

    • 感谢 Dave 提供 SystemVerilog 解决方案。在简单的 Verilog 中是否有类似的可能?
    • 没有。虽然您可以在 Verilog 中声明数组,但一次只能访问一个元素。几乎所有支持 Verilog 的模拟器也支持 SystemVerilog。
    猜你喜欢
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 2013-12-13
    • 1970-01-01
    相关资源
    最近更新 更多