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 Arrays: Single Dimensional Unpacked Array

SystemVerilog Arrays

Runnable example from the SystemVerilog Unpacked Arrays tutorial (Single Dimensional Unpacked Array)

Open in IDE
design.sv
class stack #(type T = int);
  T item;             
	
  function T add_a (T a); 	
    return item + a;
  endfunction
endclass
testbench.sv
module tb;
	byte 	stack [8]; 		// depth = 8, 1 byte wide variable

	initial begin
		// Assign random values to each slot of the stack
		foreach (stack[i]) begin
			stack[i] = $random;
			$display ("Assign 0x%0h to index %0d", stack[i], i);
		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.