Advertisement
Tutorial 06 ยท Verilog RTL Series

Blocking vs Non-Blocking Assignment

The = vs <= distinction is the single most common source of bugs for digital designers and a mandatory technical interview topic. Master the IEEE 1364 Stratified Event Queue, eliminate race conditions, and test the interactive simulator below.

= (blocking) <= (non-blocking) Race Condition Event Scheduler Shift Register Bug NBA Queue Cliff Cummings 8 Rules
Blocking = Executes sequentially in Active region a = b; โ†’ 'a' updates NOW. Next statement sees new 'a'. c = a + 1; โ†’ Uses newly updated 'a' (the new b) Result: Statements execute in procedural order โœ“ Use in combinational always @(*) Non-Blocking <= Schedules updates into NBA queue a <= b; โ†’ Evaluates b; queues update. 'a' still holds OLD value. c <= a + 1; โ†’ Uses OLD value of 'a' (parallel hardware capture!) All flip-flops update simultaneously at end of timeslot โœ“ Use in sequential always @(posedge clk) IEEE 1364 Event Scheduler: Evaluates in Active Region โ†’ Updates in NBA Region
Figure 1: Fundamental execution difference between blocking immediate update and non-blocking scheduled NBA update.

โšก The Verilog Golden Rule

Use = in always @(*) combinational blocks  ยท  Use <= in always @(posedge clk) sequential blocks
Never mix them in the same always block. Never assign the same variable from multiple blocks.

Interactive Event Queue & Shift Register Simulator Clock Cycles: 0

Click "Step Clock (โ†‘clk)" to watch how Verilog evaluates the 3-stage shift register (q1, q2, q3) in real time. Notice how the buggy blocking code collapses into a 1-clock pass-through!

Data In (D_in)
1
Driven by Testbench
Stage 1 (Q1)
0
q1 <= d_in
Stage 2 (Q2)
0
q2 <= q1
Stage 3 (Q3)
0
q3 <= q2
SIM READY Simulation initialized at Time 0. Click "Step Clock" below.

1. Blocking Assignment (=)

Blocking assignments use the = operator. They are called blocking because the execution of the procedural block is blocked until the assignment evaluates and updates the variable on the left-hand side (LHS).

In other words, statements execute sequentially in order, exactly like procedural code in C or Python. The very next statement in the same block immediately sees the updated value.

โœ“ CORRECT: Blocking in combinational logic
// Correct use of = in combinational logic
always @(*) begin
    temp = a & b;     // temp updates immediately
    out  = temp | c;  // 'out' evaluates with the newly calculated 'temp'
end

The sequential execution of blocking assignments in combinational always @(*) blocks is intentional and mathematically necessary. It allows you to create intermediate values and reuse them in subsequent calculations without synthesizing unintended hardware latches.

2. Non-Blocking Assignment (<=)

Non-blocking assignments use the <= operator. They are called non-blocking because they evaluate the right-hand side (RHS) expression immediately, but they do not block subsequent lines from executing.

Instead, the assignment update is scheduled into the Non-Blocking Assignment (NBA) event queue. All pending NBA updates in the design are applied simultaneously at the very end of the current simulation timestep.

โœ“ CORRECT: Non-blocking in sequential clocked logic
// Correct use of <= in sequential clocked logic
always @(posedge clk) begin
    b <= a;    // RHS evaluates: captures current 'a'
    c <= b;    // RHS evaluates: captures current 'b' (OLD value!)
    // End of timestep (NBA region): 'b' and 'c' update concurrently
end

3. The IEEE 1364 Verilog Event Scheduler

To understand why race conditions occur, you must understand the IEEE 1364 Verilog Stratified Event Queue. Within each discrete simulation time step, the simulator processes events through four primary regions:

  1. Active Events Region: Most Verilog code executes here. The simulator evaluates continuous assignments (assign), evaluates RHS expressions, executes procedural blocking statements (=), and displays messages ($display).
  2. Inactive Events Region: Processes events that have explicit zero-delay procedural controls (e.g. #0 a = b;).
  3. Non-Blocking Assign (NBA) Events Region: Updates the LHS variables of all non-blocking assignments (<=) whose RHS expressions were evaluated in the Active Region. Because all RHS evaluations are complete before the NBA region updates anything, all flip-flops sample pre-clock values simultaneously!
  4. Postponed / Monitor Region: Executes $strobe and $monitor calls after all logic updates in the current timestep have settled.
Why this matters in silicon: In physical CMOS hardware, all flip-flops connected to the same clock wire sample their inputs concurrently at the rising edge. Non-blocking assignments (<=) were explicitly designed into Verilog to mirror this exact physical behavior in event-driven software simulation.

4. Race Condition Example: Register Swap

Consider two concurrent always blocks trying to swap two register values on every clock tick. Because Verilog simulators are free to execute concurrent always blocks in any arbitrary order, using blocking assignments creates an unpredictable race condition:

โš ๏ธ BUG: Blocking assignments cause non-deterministic race
// TWO SEPARATE ALWAYS BLOCKS WITH BLOCKING ASSIGNMENT:
always @(posedge clk) a = b;   // blocking
always @(posedge clk) b = a;   // blocking

// UNDEFINED BEHAVIOR:
// If Block 1 runs first: 'a' gets old 'b', then Block 2 runs and 'b' gets the NEW 'a'! (Both end up with 'b')
// If Block 2 runs first: 'b' gets old 'a', then Block 1 runs and 'a' gets the NEW 'b'! (Both end up with 'a')
// Outcome depends entirely on simulator tool vendor and compile flags!
โœ“ CORRECT: Non-blocking eliminates order-dependence
// CLEAN AND ORDER-INDEPENDENT:
always @(posedge clk) a <= b;  // Active Region: schedules 'a' to get old 'b'
always @(posedge clk) b <= a;  // Active Region: schedules 'b' to get old 'a'

// NBA Region: Both updates apply concurrently!
// 'a' takes old 'b' and 'b' takes old 'a'. Perfect ping-pong swap on every cycle!

5. The Classic Shift Register Collapse Bug

This is the single most tested question in semiconductor technical interviews. Imagine designing a 3-stage shift register (pipelined delay line):

โš ๏ธ DISASTROUS BUG: 3-Stage Shift Register Collapses to 1 Stage
always @(posedge clk) begin
    b = a;   // 'b' is overwritten with 'a' IMMEDIATELY
    c = b;   // 'c' reads the NEW 'b' (which is already 'a'!)
    d = c;   // 'd' reads the NEW 'c' (which is also 'a'!)
end

// In simulation: All 3 registers update to 'a' on a SINGLE clock edge!
// In synthesis: Yosys/Design Compiler synthesizes 3 flip-flops in series.
// Result: CATASTROPHIC SIMULATION / SYNTHESIS MISMATCH!
Why this is deadly in ASIC design: Your RTL functional simulation will show data passing through in 1 clock cycle. But once synthesized onto silicon (or mapped to FPGA registers), the physical flip-flops require 3 actual clock cycles. Your testbench will pass, but the physical silicon tapeout will fail!

6. Synthesis & Simulation Summary Table

Feature Blocking (=) Non-Blocking (<=)
Execution Order Sequential, procedural (immediate update) Concurrent, scheduled (NBA region update)
Subsequent Code Sees Newly assigned value immediately Previous (pre-clock) value until timeslot ends
Combinational Blocks always @(*) โœ“ Correct (Models combinational logic) โœ— Dangerous (Causes simulation slowdowns & loops)
Sequential Blocks always @(posedge clk) โœ— Disastrous (Causes race conditions & synthesis mismatches) โœ“ Correct (Models physical CMOS flip-flops)
Mixing in Same Always Block โœ— NEVER mix = and <= in the same always block!
Synthesis Mapping Combinational logic gates / intermediate wires D-type Flip-Flops with clock enable

7. Cliff Cummings' 8 Golden Rules of Verilog Assignments

In his seminal award-winning SNUG paper ("Nonblocking Assignments in Verilog GUI, Synthesis and Simulation Issues"), EDA authority Cliff Cummings codified the 8 fundamental guidelines followed by every tier-1 semiconductor company:

  1. When modeling sequential logic, use non-blocking assignments (<=).
  2. When modeling latches, use non-blocking assignments (<=).
  3. When modeling combinational logic with an always block, use blocking assignments (=).
  4. When modeling both sequential and combinational logic within the same always block, use non-blocking assignments (<=).
  5. Do not mix blocking and non-blocking assignments in the same always block.
  6. Do not make assignments to the same variable from more than one always block.
  7. Use $strobe or $monitor to display values assigned with the non-blocking assignment operator.
  8. Do not make assignments using #0 delays.
Pro Interview Tip: If an interviewer asks, "Why can't we use blocking assignments for flip-flops?", immediately cite the Shift Register Collapse Bug and the Stratified Event Queue Active vs NBA region. This proves you understand the underlying compiler mechanics and physical silicon implementation, not just syntax memorization!