VLSI
VLSI
In fixed size array, array size will be constant throughout the simulation, Once the
array is declared no need to create it. By default, the array will be initialized with
value ‘o’.
Multidimensional array
Multidimensional arrays are also known as an array of arrays
int arr[2][3];
This array has total 2*3 = 6 elements.
Two-Dimensional Array
Int arr[2][3];
This array has total 2*3 = 6 elements.
Three-Dimensional Array
int arr[2][2][2];
This array has total 2*2*2 = 8 elements.
Two-Dimensional array declaration
int array3 [2:0][3:0];
The data in a two-dimensional array is stored in a tabular form as shown
in the below diagram.
Array assignment
array1 = ‘(0,1,2,3,4,5};
array2 ‘(0,1,2,3,4,5};
array3 = ‘{ ‘{0,1,2,3}, ‘{4,5,6,7}, ‘{8,9,10,11}}
;
Fixed Size Array Example
This example shows array declaration and array manipulation using for
and foreach loop.
Module fixedsize_array; //declaration of array’s
int array1[6]; //single dimension array
int array2[5:0]; //single dimension array
int array3[2:0][3:0]; //multi dimension array
int array4[4:0]; initial begin //array initialization
array1 = ‘{0,1,2,3,4,5};
array2 = ‘(0,1,2,3,4,5};
array3 = ‘{‘(0,1,2,3}, ‘(4,5,6,7}, ‘(8,9,10,11 }}; //displaying array elements
$display(“-------displaying array1-------“);
foreach(array1[i])
$display(“\t array1[%0d] = %0d”,I,array1[i]);
$display(“-- --displaying array2-------“);
for(int i=0;i<6;i++)
$display(“\t array2[%0d] = %0d”,I,array2[i]);
$display(“-- --displaying $display(“ array3-------“);
foreach(array3[I,j])
$display(“\t array3[%0d][%0d] = %0d”,I,j,array3[i][j]); -displaying uninitialized
array4-------“);
for(int i=0;i<5;i++)
$display(“\t array4[%0d] = %0d”,I,array4[i]);
end endmodule