SystemVerilog Reference

logic, wire and reg

logic is a four-state variable that replaces reg. A wire is a net, the only kind that resolves several drivers.

Syntax

logic [7:0] data;     // variable: one driver
wire  [7:0] bus;      // net: several drivers are resolved
reg   [7:0] old;      // same as logic; the older keyword

Rules

  • A logic variable takes one continuous driver, or procedural assignments, not both.
  • A wire may have many drivers. Their values are resolved: 0 against 1 gives x.
  • Use wire for a tri-state bus and for inout ports.
  • reg does not mean a register. It is a variable, exactly like logic.
  • Both hold four values: 0, 1, x and z. A variable starts at x, a net at z.

Example

module tb;
  wire  w;
  logic en_a = 0, en_b = 0;
  logic v;

  assign w = en_a ? 1'b1 : 1'bz;
  assign w = en_b ? 1'b0 : 1'bz;

  initial begin
    #1 $display("no driver:   w=%b  v=%b", w, v);
    en_a = 1;
    #1 $display("one driver:  w=%b", w);
    en_b = 1;
    #1 $display("two drivers: w=%b", w);
  end
endmodule
Output on Icarus Verilog 12
no driver:   w=z  v=x
one driver:  w=1
two drivers: w=x

Run It in the Playground

Common Mistake

Two continuous drivers on a logic variable

logic y;
assign y = a;
assign y = b;   // error: a variable takes one driver

A variable has no resolution rule, so the compiler rejects the second driver. This check is useful: it catches accidental double drivers.

Fix: Drive it from one place. If the signal really is a shared bus, declare it wire.

Learn It Properly

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

Standard

IEEE 1800-2023, 6.5.