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

Array Manipulation: Mandatory 'with' Clause

SystemVerilog Arrays

Runnable example from the SystemVerilog Array Manipulation tutorial (Mandatory 'with' Clause)

Open in IDE
testbench.sv
module tb;
  int array[9] = '{4, 7, 2, 5, 7, 1, 6, 3, 1};
  
  initial begin  
    array.reverse();
    $display ("reverse  : %p", array);
  
    array.sort();
    $display ("sort     : %p", array);
  
    array.rsort();
    $display ("rsort    : %p", array);
  
    for (int i = 0; i < 5; i++) begin
    	array.shuffle();
      $display ("shuffle Iter:%0d  = %p", i, array);
    end
  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.