Day 1 · Welcome to Hardware Thinking

Anatomy of a Verilog Module

Video 3 of 4 · ~12 minutes

Dr. Mike Borowczak · Electrical & Computer Engineering · CECS · UCF

HDL ≠ Software Synth vs Sim Module Anatomy Logic Refresher

The Module: Verilog's Building Block

Every Verilog design is composed of modules.

Think of a module as a chip on a circuit board with labeled pins. You define what goes in, what comes out, and what happens inside.
Module anatomy: inputs on left, outputs on right, behavior inside

⚠️ If You're Thinking Like a Programmer…

❌ Wrong Model

input and output are like function parameters. Data ‘flows in’ through input ports when I ‘call’ the module.”

✓ Right Model

Module ports are physical pins on a chip-shaped abstraction. input ports are pins pulled by external wires; output ports are pins driven by internal logic. There's no “call” — the module is always active, like a DIP package soldered onto a board.

Consequence: There's no return value. Every value the module produces comes out of a named output port. Multi-output modules are the norm, not the exception.

The Module Template

module led_driver (
    input  wire i_switch,
    output wire o_led
);

    assign o_led = i_switch;

endmodule

module keyword + name

② Input ports — signals coming in

③ Output ports — signals going out

④ Semicolon after closing paren — don't forget this!

⑤ Behavior — assign, always, or sub-module instances

endmodule — no semicolon here

Port Style: ANSI (Modern) vs. Non-ANSI

ANSI Style (use this)

module adder (
    input  wire [3:0] i_a,
    input  wire [3:0] i_b,
    output wire [4:0] o_sum
);
    assign o_sum = i_a + i_b;
endmodule

Non-ANSI (legacy)

module adder (i_a, i_b, o_sum);
    input  [3:0] i_a;
    input  [3:0] i_b;
    output [4:0] o_sum;

    assign o_sum = i_a + i_b;
endmodule
ANSI style declares direction and type in one place. Less code, fewer bugs, easier to read. We use ANSI style exclusively in this course.

Naming Conventions

module my_design (
    input  wire       i_clk,        // i_ = input
    input  wire       i_reset,
    input  wire [7:0] i_data,
    output wire       o_valid,       // o_ = output
    output reg  [7:0] o_result
);
    wire [7:0] w_intermediate;       // w_ = internal wire
    reg  [3:0] r_counter;            // r_ = register (sequential)
    // ...
PrefixMeaningExample
i_Input porti_switch
o_Output porto_led
w_Internal wirew_sum
r_Register (assigned in always)r_count
These prefixes are a course convention, not a language requirement. You can always tell at a glance whether a signal is an input, output, register, or wire.
▶ LIVE DEMO

Build a Module from Scratch

Starting from an empty file → day01_ex01_led_driver.v

module → ports → assignendmodule

Common Error #1: The Missing Semicolon

module my_module (
    input  wire a,
    output wire y
)                         // ← MISSING SEMICOLON
    assign y = a;
endmodule
module my_module (
    input  wire a,
    output wire y
);                        // ← CORRECT
    assign y = a;
endmodule

You will make this mistake. The error message won't point to the right line. Now you know what to look for.

Common Error #2: Mismatched Widths

module oops (
    input  wire [7:0] i_data,    // 8 bits
    output wire [3:0] o_result   // 4 bits
);
    assign o_result = i_data;    // ← truncation! upper 4 bits lost
endmodule
Verilog silently truncates or zero-extends when widths don't match. No error — just quiet data loss. We'll cover this in detail on Day 2.
▶ LIVE DEMO

day01_ex02_button_logic.v

Multiple gates — concurrent assign statements

Direct → NOT → AND → XOR  ·  all operating simultaneously

🤖 Check the Machine

Ask an AI assistant: “What happens if I declare a signal as output reg but then drive it with an assign statement outside the module?”

TASK

Ask about mixing output reg with external assign.

BEFORE

Predict: “Compile error”? “Silent bug”? What's the failure mode?

AFTER

Correct answer: external assign to an output reg is a Verilog error. iverilog catches this.

TAKEAWAY

Compile first, trust the compiler second, verify third. Use iverilog -Wall always.

Key Takeaways

  Modules are the fundamental building block — inputs, outputs, behavior.

assign = permanent wire, not a one-time computation.

  Use ANSI-style ports and consistent naming (i_, o_, r_, w_).

  Don't forget the semicolon after ); in the port list.

🔗 Transfer

Digital Logic Refresher

Day 1, Video 4 of 4 · ~8 minutes

▸ WHY THIS MATTERS NEXT

You now have the module skeleton. Video 4 reminds you what goes inside — the combinational gates (AND, OR, XOR, MUX) you'll combine to build every combinational circuit in this course. If this material feels dusty from a prior class, that's fine: think of it as calibrating the vocabulary we'll use for Weeks 1 and 2.