Prev Problem
Next Problem

41. Assignment - Blocking vs Non-Blocking

module nb_blocking_order (
    input  clk,
    input  b,
    output reg c_block,
    output reg c_nblk
);
    reg a1, a2;

    initial begin
        a1 = 1'b0; a2 = 1'b0;
        c_block = 1'b0; c_nblk = 1'b0;
    end

    always @(posedge clk) begin
        // Flow 1: both blocking -> c_block sees NEW b immediately
        a1      = b;
        c_block = a1;

        // Flow 2: NBA then blocking -> c_nblk sees OLD a2 this edge
        a2     <= b;  // schedules update for end of timestep
        c_nblk =  a2; // reads old a2 now
    end
endmodule

💡Remember

  • Blocking = executes now, in order; later statements see the new value.
  • Non-blocking <= takes a snapshot now but updates at the end of the timestep.
  • Reordering doesn’t help: even if you write c_nblk = a2; a2 <= b;, c_nblk still sees old a2 this edge.
  • The effect here:
    • c_block = this cycle’s b
    • c_nblk = previous cycle’s b
  • Golden rule: = in combinational, <= in sequential. Avoid driving the same reg from different always blocks or mixing =/<= across blocks.