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

#0 Delay: The Gotcha: #0 Still Runs Before NBA

SystemVerilog Scheduling Semantics

Runnable example from the SystemVerilog #0 Delay tutorial (The Gotcha: #0 Still Runs Before NBA)

Open in IDE
testbench.sv
module tb;
  reg clk;
  reg [7:0] a;

  always #10 clk = ~clk;

  initial a = 0;

  // Updates a - the actual write is deferred to NBA
  always @ (posedge clk) begin
    a <= 5;
  end

  // Reads immediately, in Active
  always @ (posedge clk) begin
    $display ("[%0t] immediate read (Active):    a=%0d", $time, a);
  end

  // Reads after a #0 delay, in Inactive - still before NBA!
  always @ (posedge clk) begin
    #0;
    $display ("[%0t] #0-delayed read (Inactive): a=%0d", $time, a);
  end

  // Reads via $strobe, deferred to Postponed - after NBA has settled
  always @ (posedge clk) begin
    $strobe ("[%0t] strobe read (Postponed):    a=%0d", $time, a);
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.