Home / Learn Verilog / Your First Module: Ports, Assign and Instantiation
Your First Module: Ports, Assign and Instantiation
Write a small module, then use it from a testbench.
Theory in plain words
In plain terms
A module declares its ports and describes behaviour. Another module instantiates it, like placing a chip on a board and wiring its pins.
Why we use it
Every Verilog design is a tree of modules. If you understand one module and its instance, you understand the whole language structure.
Under the hood
Declare ports in the module header. Inside, describe behaviour with assign or always. Instantiate with the module name, an instance name and the connections.
Real-world use
- All designs
- Reusable building blocks
- Hierarchical design
Half adder
The console prints the truth table. The instance is named ha. The connections .a(a) mean "module port a is connected to signal a".
- Write
module name(ports); - Describe behaviour (assign or always).
- End with
endmodule. - In another module, instantiate:
name inst(.port(signal), ...);
Quick quiz
1. half adder sum is...
XOR gives the sum bit.
2. A module instance needs...
name instance_name(connections);