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

Memory Array: Fill and Read

Verilog Arrays

A reg array used as a 16-word memory, filled in a loop and read back

Open in IDE
testbench.v
module tb;
  reg [7:0] mem [0:15];    // 16 words of 8 bits
  integer   i;

  initial begin
    for (i = 0; i < 16; i = i + 1)
      mem[i] = i * 3;      // One word per iteration

    $display("mem[0]=%0d mem[5]=%0d mem[15]=%0d", mem[0], mem[5], mem[15]);
  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.