Verilog modules are building blocks of digital circuits that can be instantiated in other modules to create complex designs. A module in Verilog is defined using the module keyword, followed by the module name and a list of input and output ports. Here is an example module definition:
module adder ( input [3:0] a, input [3:0] b, output [4:0] sum );
In this example, the module is named “adder” and has three ports: two input ports named “a” and “b”, both 4 bits wide, and one output port named “sum”, which is 5 bits wide.
Ports in Verilog are used to connect modules together and are declared using the input, output, and inout keywords. Input ports are used to pass data into a module, while output ports are used to pass data out of a module. Inout ports are bidirectional and can both pass data into and out of a module.
Here is an example of how to instantiate the “adder” module and connect it to other modules:
module top_module (
input [3:0] a,
input [3:0] b,
output [4:0] sum
);
adder adder_inst (
.a(a),
.b(b),
.sum(sum)
);
endmodule
In this example, the “adder” module is instantiated as “adder_inst” and connected to the “a”, “b”, and “sum” ports of the “top_module” module.
Modules and ports are essential components of Verilog designs, and understanding how to use them is important for designing and describing the behavior of digital circuits. By using modules and ports, designers can create modular designs that can be easily modified and reused in other designs.