SystemVerilog Language and Application193193SystemVerilog for Verification7/31/07Queue Indexing Exampleint q_int[$]; // queue declaration syntaxbit [7:0] q_bit[$:100]; // queue with maximum size of 100initial beginq_int = {0,q_int}; // {0}q_int = {q_int,1}; // {0,1}q_int = {2,q_int}; // {2,0,1}q_int = {q_int[0],3,q_int[1:$]}; // {2,3,0,1}q_int = {q_int[0:2],4,q_int[3]}; // {2,3,0,4,1}q_int = {q_int[0:1],q_int[3:4]}; // {2,3,4,1}q_int = {q_int[0:1],5,q_int[2:3]}; // {2,3,5,4,1}data = q_int[$]; q_int = q_int[0:$-1]; // {2,3,5,4} data = 1data = q_int[0]; q_int = q_int[1:$]; // {3,5,4} data = 2while (q_int.size()> 0) begin // checking queue sizedata = q_int[$]; // loop executes 3 timesq_int = q_int[0:$-1]; endq_bit = {8’h01,q_bit}; // {’h01}q_bit = {q_bit,8’h45}; // {’h01,’h45}q_bit = {8’h89,q_bit}; // {’89,’h01,’h45}endA queue is an array, so if you really want to, you can still use array indexing to insert and extract elements. As this example illustrates, you probably don’t really want to. The queue methods are much more friendly.We won’t bother examining this slide too closely.
