Showing posts with label output. Show all posts
Showing posts with label output. Show all posts

Saturday, 5 December 2015

1.Dynamic array of queue
2.Queue of queue
3.Associative array of queue



module array_of_queue;

typedef int qint_t[$];

// dynamic array of queues
qint_t DAq[]; // same as int DAq[][$];

// queue of queues
qint_t Qq[$]; // same as int Qq[$][$];

// associative array of queues
qint_t AAq[string]; // same as int AAq[string][$];

initial begin

// 1).Dynamic array of 5 queues
DAq = new[5];
// Push something onto one of the queues
DAq[3].push_back(7);
// initialize another queue with three entries
DAq[0] = {1,2,3,4,5};
  $display("%p",DAq);

// 2).Queue of queues -two
  Qq= '{'{1,2},'{3,4,5}};
Qq.push_back(qint_t'{6,7});
Qq[2].push_back(1);
  $display("%p",Qq);

// 3).Associative array of queues

AAq["one"] = {};
AAq["two"] = {1,2,3,4};
AAq["one"].push_back(5);
  $display("%p",AAq);
end

endmodule
-------------------------------------------------------------------------
OUTPUT:

'{'{1, 2, 3, 4, 5} , '{}, '{}, '{7} , '{}}
'{'{1, 2} , '{3, 4, 5} , '{6, 7, 1} }
'{"one":'{5} , "two":'{1, 2, 3, 4} } 


Wednesday, 26 August 2015

System Verilog Queue Example

module queues;
byte qu [$] ;

initial
  begin
    qu.push_front(1);
    qu.push_front(2);
    qu.push_front(3);
    qu.push_back(4);
    qu.push_back(5);

    foreach(qu[i])begin
      $display(i,qu[i]);
    end

    qu.delete(3);                                          //Delete element at index 3

    $display(" %d ",qu.pop_front() );       // pop_front operation removes first element
    $display(" %d ",qu.size() );

    foreach(qu[i])begin
      $display(i,qu[i]);
    end

    $display(" %d ",qu.pop_back() );    // pop_back operation removes last element

    foreach(qu[i])begin
      $display(i,qu[i]);
    end

  $display(" %d ",qu.size() );
  end
endmodule

OUTPUT:

0 3
1 2
2 1
3 4
4 5

3
//pop front

0 2
1 1
2 5

5 //pop back

0 2
1 1

2