RTL Reference

always_comb

A procedure for combinational logic. The simulator works out the sensitivity list for you.

Syntax

always_comb begin
  y = '0;            // default first
  if (sel) y = a;
end

Rules

  • It has no sensitivity list. It reruns when any signal it reads changes.
  • It also runs once at time zero, so outputs match inputs from the start.
  • Use blocking assignments (=).
  • Assign every output on every path. A missed path is a latch.
  • A variable written here may not be written by any other procedure.

Example

module tb;
  logic [1:0] sel;
  logic [3:0] a = 4'd3, b = 4'd9, y;

  always_comb begin
    y = '0;
    case (sel)
      2'd0: y = a;
      2'd1: y = b;
      2'd2: y = a + b;
    endcase
  end

  initial begin
    for (int i = 0; i < 4; i++) begin
      sel = i[1:0]; #1;
      $display("sel=%0d y=%0d", sel, y);
    end
  end
endmodule
Output on Icarus Verilog 12
sel=0 y=3
sel=1 y=9
sel=2 y=12
sel=3 y=0

Run It in the Playground

Common Mistake

A path that assigns nothing

always_comb begin
  if (en) y = d;   // no else: y must remember
end

When en is 0, y keeps its old value. Hardware that remembers without a clock is a latch.

Fix: Give y a default at the top, or add the else branch.

Learn It Properly

These lessons teach it step by step, with practice problems.

Standard

IEEE 1800-2023, 9.2.2.2.