DIFFERENT ARRAY TYPES AND QUEUES IN SYSTEM VERILOG

Print

Dynamic Array: Usage of dynamic array when user to allocate its size for storage during run time.Dynamic array store a contiguous collection of data.

The array indexing should be always integer type.

To allocate the size of a dynamic array, we have to use a new[] operator.

Example:

int dyn_arr [];

initial

  begin

    dyn_arr = new[10];        //Allocated 10 elements 

  end


How to resize a dynamic array?

Example:

initial 

  begin 

    dyn_arr = new[25](dyn_arr);     //Resize the Array and Copy 

  end 


Dynamic Array Methods:

int my_addr[ ] = new[256];

initial begin

$display("Size of my_addr = %0d", my_addr.size() );

my_addr.delete();

$display("Size of my_addr (after delete) = %0d", my_addr.size());

end


Associative Array: 

Example:

bit i_array[*]; // associative array of bits (unspecified index)

                     // unspecified index (*) implies any integral value

bit [7:0] age [string]; // associative array of 8-bit vectors, indexed by string

initial 

  begin

    string tom = “tom”;

    age [tom] = 21;

    age [“joe”] = 32;

    $display("%s is %d years of age ", tom, age[tom], "[%0d ages available]", age.num());

  end


Associative Array Methods:

Queue:

Example:

module test_example ; 

int my_queue[$] = { 1, 2, 3 }; 

string s_queue [$] = {"first","second","third","fourth"}; 

string store;

initial 

begin

// Use of the size() method/operator 

$display("\n size() operator used"); 

for (int i = 0 ; i < my_queue.size(); i++ ) 

$display (my_queue[i]); 

$display("\n\n Elements of s_queue is :"); 

for (int i = 0; i < s_queue.size; i++) 

$write(s_queue[i]," "); 

// Use of insert() method/operator 

s_queue.insert(1,"next"); // Previous element 1 is now turned to element 2. 

s_queue.insert(2,"somewhere"); 

$display("\n\n insert() operator used"); 

for (int i = 0; i < s_queue.size; i++) 

$write(s_queue[i]," "); 

// Use of delete() method/operator 

s_queue.delete(1); // delete the element 1 

s_queue.delete(3); // delete the element 3 

$display("\n\n delete() operator used"); 

for (int i = 0; i < s_queue.size; i++) 

$write(string_queue[i]," "); 

// Use of pop_front() method/operator (it deletes the front of the queue) 

store = s_queue.pop_front(); 

$display("\n\n pop_front() operator used"); 

$display(" %s",store); 

for (int i = 0; i < s_queue.size; i++) 

$write(s_queue[i]," "); 

// Use of pop_back() method/operator (it deletes the back of the queue) 

store= s_queue.pop_back(); 

$display("\n\n pop_back() operator used"); 

$display(" %s",store); 

for (int i = 0; i < s_queue.size; i++) 

$write(s_queue[i]," "); 

// Use of push_front() and push_back() method/operator 

s_queue.push_front("in-front"); 

s_queue.push_back("in-back"); 

$display("\n\n push_front() and push_back() operator used"); 

for (int i = 0; i < s_queue.size; i++) 

$write(s_queue[i]," \n "); 

end 

endmodule


 Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

 

Last Updated ( Tuesday, 29 March 2022 00:55 )