Module Structure
Part of the Fundamentals section of Coddy's Verilog journey — lesson 30 of 90.
A module is the basic building block in Verilog. Every design is built from modules that connect together to form larger systems.
A module is a hardware component with:
- A name
- Inputs (signals coming in)
- Outputs (signals going out)
- Internal logic (what the module does)
Think of a module as a chip with pins and internal circuitry.
Basic Module Structure
Every module follows this structure:
module module_name (
input signals,
output signals
);
// Internal declarations (wires, regs, etc.)
// Logic (assign statements, always blocks, etc.)
endmoduleParts of a Module
| Part | Purpose |
|---|---|
module keyword | Starts the module definition |
module_name | Name of the module |
( ) | List of input and output ports |
input / output | Declare port direction |
| Module body | Internal logic and connections |
endmodule | Ends the module definition |
Simple Module Example
module and_gate (
input a,
input b,
output c
);
assign c = a & b;
endmoduleThis module:
- Is named
and_gate - Has two inputs (
a,b) - Has one output (
c) - Contains one
assignstatement defining the logic
Rules for Module Structure
- One module per file is common practice
- Module name should describe its function
- Ports are listed between parentheses after the name
- Inputs are always
input(cannot be written inside) - Outputs are
output(can beregorwire) <strong>endmodule</strong>must close the module
Challenge
Fill the missing parts to complete this module.
What to do:
- Add the module name
my_and - Add
inputforx - Add
inputfory - Add
outputforz - Add the internal logic using
assign
Cheat sheet
A module is the basic building block in Verilog — a hardware component with inputs, outputs, and internal logic.
module module_name (
input a,
input b,
output c
);
// Internal logic
assign c = a & b;
endmodulemodule/endmodule— start and end the definitioninput— signal coming in (read-only inside module)output— signal going out (can beregorwire)assign— defines combinational logic
Try it yourself
module ______ ( // Add module name
______ x, // Add input
______ y, // Add input
______ z // Add output
);
// Add assign statement here (z = x & y)
endmoduleThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic