Using defparam
Parameter values can be changed in any module instance in the design with keyword defparam. Hierarchical name of the module instance can be used to override parameter values.
//Define a module hello-world
module hello-world;
parameter id-num = 0; //define a module identification number = 0
initial //display the module identification number
Sdisplay("Disp1aying hello-world id number = %dM, id-num);
Endmodule
//define top-level module
module top;
//change parameter values in the instantiated modules
//Use defparam statement
defparam wl.id-num = 1, w2.id-num = 2;
//instantiate two hello-world modules
hello-world wl0;
hello-world w2 ( ) ;
endmodule
Module hello-world was defined with a default id-num = 0. Though, when module instances wl and w2 of the type hello-world are created, their id-num values are modified with defparam statement.
If we simulate above design, we would get the below output:
Displaying hello-world id number = 1
Displaying hello-world id number = 2
Multiple defparam statements can appear in a module. Any parameter can be overridden with the defparam statement.