Chapter 2d - Verilog HDL Module Instantiation, Task Function
Chapter 2d - Verilog HDL Module Instantiation, Task Function
APPLICATIONS
BEB27303
CHAPTER 2D: Verilog HDL Module
Instantiation, Task & Function
Module Instantiations
› A define module can be used to be include in other
module
› This including a module is known as instantiation
› Modules are instantiated inside other modules, and
each instantiation creates a unique object from the
template
› Two types of instantiations - passing parameters
between the top module and lower level modules:
• Position (declarations are in the same order)
• Named (both declarations are listed and linked
Module Instantiations
› Connection by
position
• placing the ports
in exactly the
same positions in
the port lists of
both the template
and the instance
Module Instantiations
› Connection by name
• using a dot(.)
“ .template_port_nam
e
(name_of_wire_conne
cted_to_port)”.
Module Instantiations
module top ( input in1, in2, in3, in4, output out1, out2 );
dostuff first (in1, in2, out1); // Position instantiation -
must be in same order
dostuff second (.stin1(in3), .stin2(in4), .stout(out2)); //
Named instantiation - they don’t need to be in order
endmodule
module dostuff ( input stin1, stin2, output stout );
assign stout = stin1 & stin2;
endmodule
Module Instantiations
› Example 1: define a half adder to create a full adder
// Half Adder
module halfadd ( input a, b, output s, co );
assign s = a ^ b;
assign co = a & b;
endmodule