Session 6 Additional features (1)
Session 6 Additional features (1)
● Task and
Function
automatic
Parameter Overloading
defparam and #
operator
Compiler directives
`define and its
variant Disable
Task and Functions
// the body of
function if (N ==
1)
fact = 1;
Else
fact = N * fact(N -
1); endfunction
endmodule
Parameter
Overloading
❑ Parameters can be defined in a module definition
❑ During compilation of Verilog modules, parameter values can be altered
separately for each module instance. This allows us to pass a
distinct set of parameter values to each module during
compilation regardless of predefined parameter values is called
parameter overloading/overriding
❑ Two ways to override a module parameter value during a module
instantiation.
1) defparam keyword (can modify only at the compilation time)
2) module instance parameter value assignment.
defparam
●Statement
Parameter values can be changed in any module instance in
the design
● Multiple defparam statements can appear in a module.
● Any parameter can be overridden with the defparam
statement.
module hello-world;
parameter id-num = 0; //define a module identification number = 0
initial
Sdisplay("Disp1aying hello-world id number = %dM, id-num);
endmodule
module top; //change parameter values in the instantiated modules .Use defparam statement
defparam
endmodulewl.id-num = 1, w2.id-num = 2; //simulated output
hello-world wl0;
Displaying hello-world id number = 1
hello-world w2 () ;
Displaying hello-world id number = 2
Module-Instance Parameter Values
● Parameter values can be overridden when a module is
instantiated
● Parameter values can also be modified using #delay
specification with module instantiation.
● If multiple parameters are defined in the module, during
module instantiation they can be overridden by specifying the
new values in the same order as the parameter declarations in
the module.
● If an overriding value is not specified, the default parameter
declaration values are taken
Module Instance Parameter Values:
Example
//define module with
delays module bus-
master; parameter
delay1 = 2; parameter
delay2 = 3; parameter
delay3 = 7;
...
<module internals>
...
endmodule
● ‘ else statement:
○ It is optional
○ A maximum of one 'else statement can accompany the 'ifdef.
● ‘ define statement:
○ used to set the conditional compilation flag in Verilog file.
▪ The Verilog compiler simply skips the portion if the conditional
compile flag is not set
▪ boolean expression is not allowed with the ' ifdef statement.
Conditional compilation : Example
//Example 1 //Example 2
'ifdef TEST module top;
//compile module test only if text macro TEST is bus-master bl0; //instantiate module unconditionally
defined 'ifdef ADD-B2
module test; bus-master b2 () ; //b2 is instantiated conditionally if text
... macro ADD-B2 is defined
endmodule ' endif
endmodule
'else //compile the module stimulus as default
module stimulus;
...
...
endmodule
EXAMPLE:
begin :
block_name rega
= regb;
disable
block_name;
regc = rega; // this assignment will never
execute end
Session 6: End(Additional
Features)