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

Sequence Repetition Operator: Consecutive Repetition:

SystemVerilog Assertions

Runnable example from the SystemVerilog Sequence Repetition Operator tutorial (Consecutive Repetition:)

Open in IDE
testbench.sv
module tb;
  bit req1, req2;
  bit clk;

  always #10 clk = ~clk;

  // Once req1 is seen, req2 must stay high for 3 consecutive
  // cycles starting the very next cycle
  sequence s_consec;
    @(posedge clk) req1 ##1 req2[*3];
  endsequence

  assert property (s_consec)
    $display ("[%0t] Match: req2 held high for 3 consecutive cycles", $time);

  initial begin
    req1 <= 1; req2 <= 0;
    @(posedge clk);                 // 10ns: req1=1

    req1 <= 0; req2 <= 1;
    @(posedge clk);                 // 30ns: req2's 1st consecutive cycle

    @(posedge clk);                 // 50ns: req2's 2nd consecutive cycle

    @(posedge clk);                 // 70ns: req2's 3rd consecutive cycle - match completes

    req2 <= 0;
    @(posedge clk);                 // 90ns

    #20 $finish;
  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.