constants - 如何在verilog中使用const

标签 constants verilog hdl system-verilog

而不是使用

module ... ( .. )  ;

     #15 
endmodule

我想用
module ... ( ... ) ;
 // GateDelay is a const, like in c language const int GateDelay = 15 ;
 # GateDelay     

endmodule

或者同样的事情
module ... ( ... ) ;
 // assume Wordsize is defined at " define Wordsize 15 "
 reg [ Wordsize -1 : 0 ] mem ;

endmodule

我可以在 verilog 中实现这个愿望吗?

最佳答案

你有几个选择:

  • 带有 `define 的宏s
  • parameter s
  • localparam s

  • 这是一个包含所有这些的小例子。
    `define CONSTANT_MACRO 1          /* important: no ';' here */
    module mymodule
        #( parameter WIDTH = 5 )
        ( 
          input wire [WIDTH-1:0] in_a,
          output wire [WIDTH-1:0] out_a
        );
    
        localparam CONSTANT_LOCAL = 2;
    
        assign out_a = in_a + `CONSTANT_MACRO - CONSTANT_LOCAL;
    
    endmodule 
    

    关于constants - 如何在verilog中使用const,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5849054/

    相关文章:

    verilog - xilinx中声明变量的位置有什么区别?

    c - C中const的外部链接

    c++ - const_cast 类构造函数中的 const 成员

    verilog - #1在verilog中是什么意思?

    verilog : Variable index is not supported in signal

    verilog - Quartus 不允许在 Verilog 中使用生成模块

    php - 如何使用具有复杂( curl )语法的常量?

    c++ - ctor 声明/定义中接受的 const 限定符(llvm 错误?)

    verilog - 在两个 1 之间填充 0's with 1' s(可合成)

    verilog - 在(系统)verilog 仿真中从命令行定义参数