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

Queue Example

SystemVerilog Arrays

Runnable example from the Systemverilog Queue tutorial.

Open in IDE
testbench.sv
module tb;
  	// Create a queue that can store "string" values
  string   fruits[$] =  { "orange", "apple", "lemon", "kiwi" };
  
	initial begin
   		// Select a subset of the queue
      	$display ("citrus fruits = %p", fruits[1:2]);
      
      	// Get elements from index 1 to end of queue
      	$display ("fruits = %p", fruits[1:$]);
      
      	// Add element to the end of queue
      	fruits.push_back("pineapple");   // equivalent to fruits[$+1] = ... (Verilator does not support the $+1 index)
      	$display ("fruits = %p", fruits);
      
      	// Delete first element
        fruits = fruits[1:$];
      	$display ("Remove orange, fruits = %p", fruits);
      	
	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.