Module 4: Introduction to Verilog HDL · 4.4 Structural Modeling

Module Instantiation

Complex digital systems scale through hierarchical module instantiation. Rather than duplicating logic, designers instantiate verified submodules and connect them with internal wires. All module instances execute concurrently in physical silicon.

Instantiation Syntax

A module instantiation follows this general format:

module_type instance_name ( port_connections );
full_adder u_fa0 (
    .a   (a_in),
    .b   (b_in),
    .cin (carry_in),
    .sum (sum_out),
    .cout(carry_out)
);

In this statement, full_adder identifies the target module type. The label u_fa0 assigns a unique instance identifier. The .port(signal) syntax maps the submodule port to an enclosing net.

Named Versus Positional Port Connections

Verilog provides two port connection syntaxes:

full_adder u_fa_named (
    .a   (operand_a),
    .b   (operand_b),
    .cin (carry_in),
    .sum (partial_sum),
    .cout(carry_out)
);

Positional Connections (Discouraged)

full_adder u_fa_pos (operand_a, operand_b, carry_in, partial_sum, carry_out);

Positional instantiation binds signals strictly by order of appearance. If an engineer reorders ports in the module definition, positional connections miswire silently. Named connections bind signals by port identifier, independent of declaration order. Always use named port connections.

Overriding Module Parameters

Specify parameter overrides using the #(...) construct placed between the module type and the instance name:

adder #(
    .WIDTH(16)
) u_adder_16 (
    .a   (operand_a),
    .b   (operand_b),
    .cin (1'b0),           // Tie unused carry-in to constant 0
    .sum (result_wide),
    .cout(carry_flag)
);

Always use named parameter assignments (#(.WIDTH(16))) instead of positional parameter lists.

Port Expression Types

You can connect signals, constants, or vector slices to module ports:

  • Constant Literals: Tie unused control inputs to static logic levels:
uart_tx u_uart (
    .clk      (sys_clk),
    .rst_n    (reset_n),
    .baud_div (16'd868),     // 100 MHz clock divided for 115200 baud
    .data     (tx_data),
    .start    (tx_start),
    .tx_pin   (uart_tx_out)
);
  • Vector Slices and Concatenations:
wide_module u_wide (
    .bus_in  ({ctrl_bits, data_byte}),  // Concatenated bus input
    .low_byte(data_bus[7:0]),           // Vector slice input
    .high_out(result_bus[31:16])        // Vector slice output
);

Always provide sized constants (16'd868) to match port bit widths.

Handling Unused Ports

When an output port is unneeded, leave the port connection empty or connect a dangling wire:

wire unused_carry;

adder u_adder (
    .a   (op_a),
    .b   (op_b),
    .cin (1'b0),
    .sum (result),
    .cout()              // Explicitly unconnected output port
);

Synthesis tools optimize away logic that exclusively drives unused output ports.

Never leave an input port unconnected. An unconnected input floats at high-impedance (z), which resolves to unknown (x) in simulation. Tie unused input ports to explicit logic levels (1'b0 or 1'b1).

4-Bit Ripple-Carry Adder Example

The following module builds a 4-bit ripple-carry adder by cascading four 1-bit full adder instances:

`timescale 1ns / 1ps
`default_nettype none

module rca_4bit_simple (
    input  wire [3:0] a,
    input  wire [3:0] b,
    input  wire       cin,
    output wire [3:0] sum,
    output wire       cout
);
    wire c1, c2, c3;    // Carry nets between full-adder stages

    full_adder u_fa0 (
        .a   (a[0]),
        .b   (b[0]),
        .cin (cin),
        .sum (sum[0]),
        .cout(c1)
    );

    full_adder u_fa1 (
        .a   (a[1]),
        .b   (b[1]),
        .cin (c1),
        .sum (sum[1]),
        .cout(c2)
    );

    full_adder u_fa2 (
        .a   (a[2]),
        .b   (b[2]),
        .cin (c2),
        .sum (sum[2]),
        .cout(c3)
    );

    full_adder u_fa3 (
        .a   (a[3]),
        .b   (b[3]),
        .cin (c3),
        .sum (sum[3]),
        .cout(cout)
    );

endmodule

The carry chain ripples through internal wires c1, c2, and c3 (Figure 1).

Four full adders
Figure 1: 4-bit ripple-carry adder constructed from four full-adder instances

SystemVerilog Port Connection Shortcuts

SystemVerilog introduces convenient port connection shortcuts:

  • .port_name: Automatically connects a port to a wire with the identical name.
  • .*: Automatically binds all ports to matching same-named wires across the module boundary.

These shortcuts are valid in SystemVerilog (IEEE 1800) but are illegal in classic Verilog-2001.

Practice Exercise

A comparator module defines a parameter WIDTH (default 4), inputs a and b, and outputs a_gt_b, a_eq_b, and a_lt_b. Instantiate this module with WIDTH = 8, connect inputs to data_x and data_y, connect a_gt_b to is_greater, and leave the remaining outputs unconnected.

Solution
wire is_greater;

comparator #(
    .WIDTH(8)
) u_cmp (
    .a     (data_x),
    .b     (data_y),
    .a_gt_b(is_greater),
    .a_eq_b(),           // Explicitly left unconnected
    .a_lt_b()            // Explicitly left unconnected
);

Leaving output port parentheses empty clearly documents that the unused outputs are deliberate omissions.

The next article examines port connection rules in detail: width mismatch handling, bus slicing across multiple instances, and multidriver contention.

← Gate Primitives Port Connections in Detail →