RTL Design / Module 3: Verilog from Scratch
Lesson 3.3

Continuous assign vs always โ€” when to use which

Verilog gives you two ways to describe logic: continuous assign and always blocks. Both can build combinational or sequential circuits โ€” but only when paired with the right sensitivity list and assignment operator. This lesson maps each construct to hardware.

Rule of thumb

assign for simple combo connections. always @(*) for procedural combo. always @(posedge clk) for sequential. Never mix drivers.

1

Continuous assign โ€” always "on"

A continuous assignment drives a wire whenever any signal on the right-hand side changes. In simulation it behaves like a permanent wire connection; in synthesis it becomes combinational logic.

assign_basics.v
wire y, carry;
assign y      = a ^ b;
assign carry  = a & b;

// Conditional (mux) with assign
wire [7:0] result;
assign result = sel ? b : a;

// Vector operations
wire [3:0] nibble;
assign nibble = data[7:4];
Featureassign
Target typewire only
EvaluationContinuous โ€” re-evaluates on any RHS change
SynthesisCombinational logic only
Best forSimple gates, muxes, bit slices, connects
Multiple statements?One per assign; use multiple assign lines
Analogy

assign is like soldering two points together โ€” the output is permanently "listening" to the inputs. Change the input, the output updates immediately (after gate delay in sim).

2

always @(*) โ€” combinational procedural

The always @(*) block (or always @(...) with full sensitivity) describes combinational logic procedurally. Use blocking assignment (=) inside. Every path must assign every output โ€” or you get latches.

always_combo.v
reg [7:0] result;
always @(*) begin
  case (opcode)
    3'b000: result = a + b;
    3'b001: result = a - b;
    3'b010: result = a & b;
    default: result = 8'd0;
  endcase
end
assign vs always combo

Both build combinational logic. Choose based on readability, not capability.

3

always @(posedge clk) โ€” sequential

Clocked always blocks describe sequential logic. Use non-blocking assignment (<=) for flops. Include async reset in the sensitivity list when needed.

always_seq.v
reg [7:0] count;
always @(posedge clk or negedge rst_n) begin
  if (!rst_n)
    count <= 8'd0;
  else if (en)
    count <= count + 8'd1;
end
always formAssignmentHardwareSensitivity
always @(*)= blockingCombinationalAll inputs (auto with *)
always @(posedge clk)<= non-blockingFlip-flopClock edge (+ async reset)
always @(a or b)= blockingCombo (legacy style)Explicit signal list
always @(posedge clk)= blockingโš ๏ธ Wrong โ€” sim/synth mismatchDon't do this

Golden rule: Combo always โ†’ blocking =. Clocked always โ†’ non-blocking <=. Mixing them in a clocked block is the #1 beginner bug (next lesson).

4

Sensitivity lists โ€” what triggers re-evaluation

In simulation, an always block only runs when a signal in its sensitivity list changes. Incomplete lists cause simulation/synthesis mismatches โ€” the hardware always "sees" everything, but your sim might not.

sensitivity.v
// GOOD โ€” @(*) auto-includes all RHS inputs
always @(*) y = a & b;

// LEGACY โ€” manual list (error-prone)
always @(a or b) y = a & b;

// BAD โ€” missing b in sensitivity list
always @(a) y = a & b;  // sim won't update when b changes!

// SEQUENTIAL โ€” only clock (and async reset)
always @(posedge clk) q <= d;  // d NOT in sensitivity โ€” correct for flops
List styleWhen to useRisk
@(*) or @(*)All combinational alwaysLow โ€” tool fills list
@(a or b or c)Legacy VerilogHigh โ€” easy to omit a signal
@(posedge clk)SequentialLow โ€” only clock matters for sync logic
@(posedge clk or negedge rst_n)Async reset flopsLow โ€” standard template
Trap

Using always @(clk) instead of always @(posedge clk) โ€” triggers on both edges in simulation, but synthesis only builds rising-edge flops. Always use explicit edge keywords.

5

Side-by-side: same mux, two styles

mux_assign.v
// Style A: assign (concise for simple mux)
wire [7:0] out_a;
assign out_a = sel ? b : a;
mux_always.v
// Style B: always @(*) (better for multi-output / complex)
reg [7:0] out_b;
always @(*) begin
  if (sel)
    out_b = b;
  else
    out_b = a;
end

Both synthesize to the same 2:1 mux. Pick the style that reads clearest for your team. Many codebases use always @(*) for all combo and assign only for trivial connects.

โ–ถ Run in Verilog Simulator
6

When to use which โ€” decision table

ScenarioRecommendedWhy
Simple gate (AND, XOR, invert)assignOne line, obvious
2:1 mux, bit sliceassignTernary is clean
Case statement / FSM next-state (combo)always @(*)Branching is readable
Counter, shift register, pipelinealways @(posedge clk)Only always does sequential
Multiple related combo outputsalways @(*)One block, shared logic
Tie-off, constant connectassignassign unused = 1'b0;
๐Ÿ“

assign strengths

Concise, no sensitivity worries, impossible to infer latches accidentally, great for dataflow-style RTL.

๐Ÿ”€

always strengths

Handles if/case/for loops, multiple outputs in one block, sequential logic, complex control flow.

7

What you cannot do

  • assign inside an always block โ€” illegal
  • Drive the same signal with both assign and always โ€” multi-driver error
  • Sequential logic with assign โ€” no flops from assign alone
  • Procedural targets (reg) with assign โ€” type mismatch
illegal_mix.v
// ILLEGAL examples โ€” do not compile

// assign inside always
always @(*) assign x = a;  // syntax error

// dual drivers
wire y;
assign y = a;
always @(*) y = b;         // multi-driver

// flop attempt with assign
assign q = d;              // combo only โ€” not a register!
Interview question

"Can you build a flip-flop with assign?" โ€” No. assign is purely combinational. Flops require a clocked always block (or a library cell instance).

8

SystemVerilog equivalents

VerilogSystemVerilogIntent
assign y = expr;assign y = expr;Same โ€” continuous
always @(*)always_combCombo โ€” tool checks completeness
always @(posedge clk)always_ffSequential โ€” tool enforces <=

always_comb automatically triggers once at time 0 and errors if you accidentally infer latches or write to the same variable from multiple blocks.

  • I can write simple combo logic with assign
  • I use always @(*) with blocking = for complex combo
  • I use always @(posedge clk) with <= for flops
  • I know @(*) fixes sensitivity list bugs
  • I never mix assign and always on one signal

๐ŸŽฏ What to remember

  • assign = continuous combinational drive on wire.
  • always @(*) + = = procedural combinational on reg/logic.
  • always @(posedge clk) + <= = sequential (flip-flops).
  • Use @(*) for auto sensitivity โ€” never guess signal lists.
  • Next lesson: blocking vs non-blocking โ€” why the assignment operator matters.
Advertisement