Menu
Coddy logo textTech

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.)
  
endmodule

Parts of a Module

PartPurpose
module keywordStarts the module definition
module_nameName of the module
( )List of input and output ports
input / outputDeclare port direction
Module bodyInternal logic and connections
endmoduleEnds the module definition

Simple Module Example

module and_gate (
  input a,
  input b,
  output c
);
  assign c = a & b;
endmodule

This module:

  • Is named and_gate
  • Has two inputs (a, b)
  • Has one output (c)
  • Contains one assign statement defining the logic

Rules for Module Structure

  1. One module per file is common practice
  2. Module name should describe its function
  3. Ports are listed between parentheses after the name
  1. Inputs are always input (cannot be written inside)
  2. Outputs are output (can be reg or wire)
  3. <strong>endmodule</strong> must close the module
challenge icon

Challenge

Fill the missing parts to complete this module.

What to do:

  1. Add the module name my_and
  2. Add input for x
  3. Add input for y
  4. Add output for z
  5. 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;

endmodule
  • module / endmodule — start and end the definition
  • input — signal coming in (read-only inside module)
  • output — signal going out (can be reg or wire)
  • 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)
  
endmodule
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals