quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Dynamic arrays

A dynamic array is one dimension of an unpacked array whose size can be set or changed at runtime. The space for a dynamic array doesn t exist until the array is explicitly created at runtime.

   

space.gif

SystemVerilog provides set of function to work with dynamic arrays.

   

space.gif

  • new[] : This operator is used to set or change the size of the array.
  • size(): This method returns the current size of the array.
  • delete() : This method clears all the elements yielding an empty array (zero size).
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Dynamic Array
   

space.gif


  1 module dynamic_array_data();
  2 
  3 // Declare dynamic array
  4 reg [7:0] mem [];
  5 
  6 initial begin
  7   // Allocate array for 4 locations
  8   $display ("Setting array size to 4");
  9   mem = new[4];
 10   $display("Initial the array with default values");
 11   for (int i = 0; i < 4; i ++) begin
 12     mem[i] = i;
 13   end
 14   // Doubling the size of array, with old content still valid
 15   mem = new[8] (mem);
 16   // Print current size
 17   $display ("Current array size is %d",mem.size());
 18   for (int i = 0; i < 4; i ++) begin
 19     $display ("Value at location %g is %d ", i, mem[i]);
 20   end
 21   // Delete array
 22   $display ("Deleting the array");
 23   mem.delete();
 24   $display ("Current array size is %d",mem.size());
 25    #1  $finish;
 26 end
 27 
 28 endmodule
You could download file dynamic_array_data.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output
   

space.gif

 Setting array size to 4
 Initial the array with default values
 Current array size is          8
 Value at location 0 is   0 
 Value at location 1 is   1 
 Value at location 2 is   2 
 Value at location 3 is   3 
 Deleting the array
 Current array size is          0
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com