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

Multidimensional Unpacked Array

SystemVerilog Data Types

Example of a simple MDA : https://www.chipverify.com/systemverilog/systemverilog-unpacked-arrays

Open in IDE
testbench.v
module tb;
  byte 	stack [2][4]; 		// 2 rows, 4 cols

	initial begin
		// Assign random values to each slot of the stack
		foreach (stack[i])
          foreach (stack[i][j]) begin
            stack[i][j] = $random;
            $display ("stack[%0d][%0d] = 0x%0h", i, j, stack[i][j]);
			end

		// Print contents of the stack
		$display ("stack = %p", stack);
	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.