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: Array Reduction Methods

SystemVerilog Arrays

Runnable example from the SystemVerilog Array Manipulation tutorial (Array Reduction Methods)

Open in IDE
testbench.sv
module tb;
  int array[4] = '{1, 2, 3, 4};
  int res[$];
  
  initial begin
    $display ("sum     = %0d", array.sum());  
    $display ("product = %0d", array.product());  
    $display ("and     = 0x%0h", array.and());
    $display ("or      = 0x%0h", array.or());  
    $display ("xor     = 0x%0h", array.xor());  
  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.