RTL Design / Module 3: Verilog from Scratch
Lesson 3.2

wire vs reg / logic โ€” what is actually being stored

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.

Core idea

wire = continuous connection (driven by assign or module output). reg = procedural assignment target (driven inside always). The synthesizer decides flops vs wires from context.

1

Historical meaning โ€” why the names lie

Verilog-1995 inherited naming from a gate-level world:

  • wire โ€” a net, like a physical wire between gates. Value flows continuously from its driver.
  • reg โ€” a variable that can hold a value between procedural statements in simulation. The name suggests "register" but a reg in a combinational always @(*) becomes combinational logic, not a flip-flop.
Analogy

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.

wire vs reg synthesis

reg is NOT always a register. Context (always block type) decides the hardware.

2

What synthesizes to what

DeclarationDriven byTypical synthesis result
wireassign, module port, gate outputNet / 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 initialProcedural (TB only)Not synthesized
logic (SystemVerilog)Either styleTool infers from context
synth_mapping.v
// 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
3

Driving rules โ€” one driver per net

Hardware nets have exactly one active driver (except tristate buses). Verilog enforces this at elaboration:

Rulewirereg
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
multi_driver_bad.v
// 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;
Trap

Accidentally driving the same signal from an assign and an always block. Pick one style per signal โ€” continuous or procedural, never both.

4

When to use wire

  • Signals driven by assign statements
  • Connecting module instances (internal nets between children)
  • Module output ports when driven combinationally
  • Testbench signals that observe DUT outputs
wire_usage.v
module 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
5

When to use reg

  • Targets of assignments inside always blocks
  • Sequential state: counters, shift registers, FSM state
  • Combinational logic described procedurally (prefer logic in SV)
  • Testbench stimulus variables (driving DUT inputs)
reg_usage.v
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.

6

SystemVerilog logic โ€” the modern fix

SystemVerilog replaces the wire/reg split with a single type: logic. It can be driven by assign or always. Still one driver rule applies.

logic_example.sv
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-2001SystemVerilogNotes
wirelogic (or keep wire)logic is more flexible
reglogicDrop "reg" in new code
always @(posedge)always_ffIntent-clear sequential
always @(*)always_combIntent-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.

7

Inferred latches โ€” the reg trap

If a reg is assigned in combinational always but not in every branch, synthesis infers a latch โ€” usually unintentional.

latch_trap.v
// 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
โ–ถ Run in Verilog Simulator
Lint rule

Enable "latch inferred" warnings in your synthesis tool. Zero latches is a common team policy unless you explicitly need one.

8

Quick decision flowchart

New signal?โ†’ Driven by assign?โ†’ wire / logic
New signal?โ†’ Driven in always?โ†’ reg / logic
  • I know reg โ‰  register in hardware
  • I can pick wire vs reg based on driver style
  • I understand the one-driver rule
  • I know logic is the SV unified type
  • I watch for inferred latches in combo always

๐ŸŽฏ What to remember

  • wire = continuous assignment; reg = procedural assignment target.
  • reg in always @(posedge) โ†’ flop; reg in always @(*) โ†’ combo.
  • One driver per signal โ€” never mix assign and always on the same net.
  • SystemVerilog logic replaces both; use always_ff / always_comb for clarity.
  • Incomplete combo branches infer latches โ€” always default or cover all cases.
Advertisement