A queue represents a First In First Out scheme and in System Verilog it is a variable-size ordered collection of elements of the same data type that can be pushed and popped out when required. It's similar to a one-dimensional unpacked array that grows and shrinks automatically. They can also be manipulated by indexing, concatenation and slicing operators. Queues can be passed to tasks/functions as ref or non-ref arguments.


A queue is distinguished by it's specification of the size using $ operator.

    [data_type]  [name_of_queue] [$];
    string       name_list [$];        // A queue of string elements
    byte         q [$];                // A queue of byte elements
    bit [3:0]    data [$];             // A queue of 4-bit elements
    logic [7:0]  elements [$:127];     // A bounded queue of 8-bits with maximum size of 128 slots
  string    name_list1 [$] =  { "Adam" };                              // A string queue with 1 element
  string      name_list2 [$] =  { "Chip", "Verify", "Austin" };          // string queue with 3 elements
  name_list = { "Breaking", "Bad", "CBS" };        // Initialize a queue that was declared before
  data      = { 4'he, 4'ha };                      // Initialize with 2 elements     
  q = {};                                          // An empty queue

Note the following about queues:

  • A queue slice expression like Q[a:b] will yield a queue with b - a + 1 elements
  • A queue slice expression like Q[a:b] where a < 0 is the same as Q[0:b]
  • A queue slice expression like Q[a:b] where b > $ is the same as Q[a:$]
  • A write to invalid index will be ignored or generate a warning, however writing to Q[$+1] is legal


Login to your free account to read more ...

Was this article helpful ?