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

Associative Array: Initialization Example

SystemVerilog Arrays

Runnable example from the SystemVerilog Associative Array tutorial (Initialization Example)

Open in IDE
testbench.sv
module tb;

	int   	array1 [int]; 			// An integer array with integer index
	int   	array2 [string]; 		// An integer array with string index
	string  array3 [string]; 		// A string array with string index
  
  	initial begin
      	// Initialize each dynamic array with some values
    	array1 = '{ 1 : 22,
	            	6 : 34 };
  
		array2 = '{ "Ross" : 100,
	            	"Joey" : 60 };
  
		array3 = '{ "Apples" : "Oranges",
	            	"Pears" : "44" };
  
      	// Print each array
      $display ("array1 = %p", array1);
      $display ("array2 = %p", array2);
      $display ("array3 = %p", array3);
    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.