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 keywordRules
- A
logicvariable takes one continuous driver, or procedural assignments, not both. - A
wiremay have many drivers. Their values are resolved: 0 against 1 givesx. - Use
wirefor a tri-state bus and forinoutports. regdoes not mean a register. It is a variable, exactly likelogic.- Both hold four values: 0, 1,
xandz. A variable starts atx, a net atz.
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
endmoduleno driver: w=z v=x
one driver: w=1
two drivers: w=xCommon Mistake
Two continuous drivers on a logic variable
logic y;
assign y = a;
assign y = b; // error: a variable takes one driverA 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.