Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Blocking Assignments

Verilog Examples

Runnable example from the Verilog Blocking & Non-Blocking tutorial (Blocking Assignments)

Open in IDE
testbench.v
module tb;
  reg [7:0] a, b, c, d, e;

  initial begin
    a <= 8'hDA;                                           // Schedule assignment to 'a' for end of time-step
    $display ("[%0t] a=0x%0h b=0x%0h c=0x%0h", $time, a, b, c);  // 'a' not updated yet!
    b <= 8'hF1;                                           // Schedule assignment to 'b' for end of time-step
    $display ("[%0t] a=0x%0h b=0x%0h c=0x%0h", $time, a, b, c);  // 'a', 'b' not updated yet!
    c <= 8'h30;                                           // Schedule assignment to 'c' for end of time-step
    $display ("[%0t] a=0x%0h b=0x%0h c=0x%0h", $time, a, b, c);  // None updated yet!
  end                                                     // End of time-step: Now a, b, c get their values

  initial begin
    d <= 8'hAA;                                           // Schedule assignment to 'd'
    $display ("[%0t] d=0x%0h e=0x%0h", $time, d, e);      // 'd' not updated yet!
    e <= 8'h55;                                           // Schedule assignment to 'e'
    $display ("[%0t] d=0x%0h e=0x%0h", $time, d, e);      // 'd', 'e' not updated yet!
  end                                                     // End of time-step: Now d, e get their values
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.