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};
  int res[$];
  
  initial begin  
    res = array.min();
    $display ("min          : %p", res);
  
    res = array.max();
    $display ("max          : %p", res);
  
    res = array.unique();
    $display ("unique       : %p", res);
  
    res = array.unique(x) with (x < 3);
    $display ("unique       : %p", res);
  
    res = array.unique_index;
    $display ("unique_index : %p", res);
  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.