而不是使用
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/