Module 4: Introduction to Verilog HDL · 4.5 Dataflow Modeling

Continuous Assignments

Dataflow modeling describes digital circuits using boolean equations and continuous assignments. While structural modeling instantiates explicit gates, dataflow modeling defines functional relationships. The logic synthesis tool selects and optimizes the underlying logic gates automatically.

The assign Statement

A continuous assignment uses this syntax:

assign net_name = expression;

The right-hand expression can combine any Verilog operators. The synthesis tool generates the physical logic gates required to evaluate the expression:

assign sum        = a + b;                                   // Infers adder circuit
assign {cout, s}  = {1'b0, a} + {1'b0, b};                   // Adder preserving carry flag
assign y          = sel ? a : b;                             // Infers 2-to-1 multiplexer
assign eq         = (a == b);                                // Infers XOR comparison tree

Each continuous assignment represents a physical combinational circuit whose inputs continuously determine its output net.

Operational Rules of Continuous Assignments

  1. Continuous Operation: Whenever any input operand on the right-hand side transitions, the output net updates immediately in ideal simulation.
  2. Concurrent Execution: All assign statements operate in parallel. Textual statement order does not affect circuit behavior:
// These two code blocks generate identical hardware
assign sum = a + b;
assign eq  = (a == b);

assign eq  = (a == b);
assign sum = a + b;
  1. Net Type Target: The target of an assign statement must be a net type (such as wire). You cannot drive a reg variable with an assign statement.
  2. Single Active Driver: A wire can have only one continuous assignment. Driving a net with multiple assign statements causes multi-driver conflicts (x in simulation). Use multiplexers to select among multiple driving signals.

Declaration and Assignment Styles

Verilog supports explicit and combined declaration styles:

// Explicit declaration and assignment (recommended)
wire y;
assign y = a & b;

// Combined declaration and assignment
wire y = a & b;

The explicit style clearly separates signal declarations from circuit logic, improving source readability.

Circuit Representation of Continuous Assignments

A set of continuous assignments describes interconnected nodes in a schematic diagram:

assign p         = a ^ b;
assign g         = a & b;
assign sum_bit   = p ^ cin;
assign carry_out = g | (p & cin);

Each statement defines a logic node. Each operand references an input wire from an adjacent logic node (Figure 1).

A full adder as four assigns
Figure 1: Combinational full-adder nodes mapped to continuous assignments

Selecting assign Versus procedural always Blocks

Both constructs describe combinational logic. Choose based on design readability:

Logic Complexity Recommended Construct
Single boolean expression or single output Continuous assign statement
Simple multiplexer (2-to-1 or 4-to-1) Continuous assign with ternary operator ?:
Arithmetic adders and comparators Continuous assign statement
Complex logic driving multiple coordinated outputs Procedural always @(*) block
Multi-case decoders and priority tables Procedural always @(*) block with case
Sequential clocked registers Procedural always @(posedge clk) block

If an operation fits into a concise single-line expression, use assign. If an operation requires nested conditional branches, use an always @(*) block.

Dataflow Half Adder and Full Adder

`timescale 1ns / 1ps
`default_nettype none

module half_adder (
    input  wire a,
    input  wire b,
    output wire sum,
    output wire carry
);
    assign sum   = a ^ b;
    assign carry = a & b;
endmodule

module full_adder (
    input  wire a,
    input  wire b,
    input  wire cin,
    output wire sum,
    output wire cout
);
    wire xor_ab;
    wire carry_1, carry_2;

    assign xor_ab  = a ^ b;
    assign sum     = xor_ab ^ cin;
    assign carry_1 = a & b;
    assign carry_2 = xor_ab & cin;
    assign cout    = carry_1 | carry_2;

endmodule

These modules synthesize into the same gate netlists as the structural models in Section 4.4, using clearer and more maintainable code.

Practice Exercise

Design a 4-to-2 priority encoder using only continuous assign statements. The module accepts request bus req[3:0]. It produces a 2-bit grant[1:0] identifying the highest active request index and asserts a 1-bit valid flag when any request is high.

Solution
`timescale 1ns / 1ps
`default_nettype none

module priority_encoder_4to2 (
    input  wire [3:0] req,      // req[3] has the highest priority
    output wire [1:0] grant,
    output wire       valid
);
    assign valid = |req;        // Unary OR reduction detects any active request

    assign grant = req[3] ? 2'd3 :
                   req[2] ? 2'd2 :
                   req[1] ? 2'd1 :
                            2'd0;
endmodule

The chained conditional operator evaluates from highest bit to lowest bit. The unary reduction |req computes the valid signal cleanly.

The next article presents practical dataflow implementations of standard combinational building blocks.

← A 4-bit ALU from the Gates Up Dataflow in Practice →