What is Blocking assignment?
Verilog's "=" assignment, which updates the left side immediately so the next statement sees the new value. Used in combinational always blocks and testbenches.
Japanese name: ブロッキング代入
Verilog's "=" assignment, which updates the left side immediately so the next statement sees the new value. Used in combinational always blocks and testbenches.
Japanese name: ブロッキング代入
A blocking assignment, written with a single equals sign, evaluates its right-hand side and updates the left-hand variable before the next statement in the same procedural block runs, much like assignment in C. Statements therefore act in order, and a later line sees the value an earlier line just wrote. A nonblocking assignment, by contrast, evaluates every right-hand side first and applies all the updates together later in the time step, so each statement sees the values from before the clock edge.
Inside a clocked always block, blocking assignments let one register see another's new value within the same edge. Writing "q1 = d; q2 = q1;" for a two-stage shift register gives q2 the freshly updated q1, which is d, so both simulation and the synthesized circuit delay by only one stage. Likewise "a = b; b = a;" leaves both equal to the old b instead of swapping them. Using nonblocking assignments for every register in a clocked block makes the code behave like parallel flip-flops regardless of statement order.
Blocking assignment belongs in combinational always blocks, written as always @(*) or SystemVerilog always_comb, where an intermediate variable computed on one line feeds the next and the result describes a chain of gates. It is also natural in testbench procedural code and for temporary variables inside functions and tasks. The widely followed rules are: nonblocking for clocked logic, blocking for combinational logic, and never assign the same variable with both kinds.
Driving a design input with a blocking assignment at exactly the same simulation time as the active clock edge creates a race: whether the design's flip-flops capture the old or the new value depends on which process the simulator happens to execute first, and results can differ between simulators. Common fixes are changing stimulus on the opposite clock edge or a short delay after the active edge, driving inputs with nonblocking assignments, or using SystemVerilog clocking blocks.
Answer: A. Whether the design captures the old or new value depends on execution order (a race); change inputs away from the clock edge or with nonblocking assignments
When the testbench updates an input at the same instant the design's flip-flops sample it, the captured value can be old or new depending on which the simulator executes first. This is a simulation race, and results may even differ between simulators. It is prevented by changing inputs on the falling edge or slightly after the edge, or by using nonblocking assignments or SystemVerilog clocking blocks.
Use nonblocking assignment for registers in clocked always blocks and blocking assignment in combinational blocks and for temporary variables. Do not mix both kinds on the same variable.
Most likely the stages are written with blocking assignments, so each stage receives the value the previous line just updated. Switching to nonblocking assignments makes every stage take the pre-edge value.
Yes, roughly: a VHDL variable assignment takes effect immediately within the process, while a VHDL signal assignment is scheduled and behaves more like a nonblocking assignment.
Blocking assignment appears in 3 practice questions across 1 topic, including HDL & Verification.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.