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

Unpacked Array: Register File

SystemVerilog Arrays

Four 16-bit registers in an unpacked array of packed elements, printed with foreach and %p

Open in IDE
testbench.sv
module tb;
  bit [1:0][7:0] regfile [4];   // 4 registers, 16 bits each

  initial begin
    foreach (regfile[i]) begin
      regfile[i] = $random;
      $display("regfile[%0d] = 0x%0h", i, regfile[i]);
    end

    $display("regfile = %p", regfile);
    $display("regfile[2] byte 1 = 0x%0h", regfile[2][1]);
  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.