Verilog's wire and reg keywords confuse almost every beginner โ because reg does not mean "register" in hardware. They describe how a signal is driven in the language, not always what silicon you get. SystemVerilog's logic fixes most of this.
wire = continuous connection (driven by assign or module output). reg = procedural assignment target (driven inside always). The synthesizer decides flops vs wires from context.
Verilog-1995 inherited naming from a gate-level world:
reg in a combinational always @(*) becomes combinational logic, not a flip-flop.wire is a pipe โ water (signal) flows through instantly from the source. reg is a bucket you fill in procedural steps โ but synthesis may replace the bucket with a pipe (combo) or a tank with a lid (flop), depending on the recipe.
reg is NOT always a register. Context (always block type) decides the hardware.
| Declaration | Driven by | Typical synthesis result |
|---|---|---|
wire | assign, module port, gate output | Net / routing / combo gate output |
reg in always @(posedge clk) | Non-blocking <= | Flip-flop or latch |
reg in always @(*) | Blocking = | Combinational logic (mux, adder) |
reg in initial | Procedural (TB only) | Not synthesized |
logic (SystemVerilog) | Either style | Tool infers from context |
// wire โ continuous driver wire y_combo; assign y_combo = a ^ b; // โ XOR gate // reg in sequential always โ flop reg q_seq; always @(posedge clk) q_seq <= d; // โ DFF // reg in combinational always โ combo reg y_mux; always @(*) y_mux = sel ? b : a; // โ MUX, NOT a register
Hardware nets have exactly one active driver (except tristate buses). Verilog enforces this at elaboration:
| Rule | wire | reg |
|---|---|---|
Assigned in assign? | โ Yes | โ No |
Assigned in always? | โ No | โ Yes |
Multiple assign drivers? | โ Error (multi-driver) | N/A |
Multiple always blocks? | N/A | โ Error if same reg |
| Left unassigned? | Floats to Z (sim) / tie-off (synth) | Inferred latch if combo |
// ILLEGAL โ two drivers on same wire wire x; assign x = a & b; assign x = c | d; // elaboration error // ILLEGAL โ wire in always wire bad; always @(*) bad = a; // error: wire cannot be procedural target // LEGAL โ one driver each wire y1, y2; assign y1 = a & b; assign y2 = c | d;
Accidentally driving the same signal from an assign and an always block. Pick one style per signal โ continuous or procedural, never both.
assign statementsoutput ports when driven combinationallymodule top (
input wire clk,
input wire [7:0] din,
output wire [7:0] dout
);
wire [7:0] internal_sig;
wire carry;
// wire driven by assign
assign internal_sig = din + 8'd1;
assign carry = |din;
child u_child (
.clk(clk),
.data(internal_sig),
.cout(carry),
.out(dout)
);
endmodule
always blockslogic in SV)module counter (
input wire clk,
input wire rst_n,
input wire en,
output reg [7:0] count // reg because always drives it
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count <= 8'd0;
else if (en)
count <= count + 8'd1;
end
endmodule
// TB: reg drives inputs
module counter_tb;
reg clk, rst_n, en;
wire [7:0] count;
// ...
endmodule
Output reg: If a module output is assigned in always, declare it output reg (Verilog) or output logic (SystemVerilog). You cannot use output wire with procedural drive.
SystemVerilog replaces the wire/reg split with a single type: logic. It can be driven by assign or always. Still one driver rule applies.
module modern_counter (
input logic clk,
input logic rst_n,
output logic [7:0] count
);
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) count <= '0;
else count <= count + 1;
end
endmodule
// logic works with assign too:
logic [3:0] nibble;
assign nibble = data[7:4];
| Verilog-2001 | SystemVerilog | Notes |
|---|---|---|
wire | logic (or keep wire) | logic is more flexible |
reg | logic | Drop "reg" in new code |
always @(posedge) | always_ff | Intent-clear sequential |
always @(*) | always_comb | Intent-clear combinational |
Course stance: We teach Verilog wire/reg first (industry legacy code), then introduce logic as the upgrade path. Both appear in real repos.
If a reg is assigned in combinational always but not in every branch, synthesis infers a latch โ usually unintentional.
// BAD โ incomplete if โ latch inferred reg y; always @(*) begin if (en) y = d; // when en=0, y holds old value โ latch! end // GOOD โ default assignment covers all inputs reg y_fixed; always @(*) begin y_fixed = 1'b0; // default if (en) y_fixed = d; end
Enable "latch inferred" warnings in your synthesis tool. Zero latches is a common team policy unless you explicitly need one.
wire = continuous assignment; reg = procedural assignment target.always @(posedge) โ flop; reg in always @(*) โ combo.logic replaces both; use always_ff / always_comb for clarity.