System Verilog Array Methods – manipulating Methods
Array Manipulating Methods in System Verilog
Arrays :
1. size( )
2. delete( )
-
-
Queues
-
Bounded Queues
-
Queues methods
-
-
1.size( )
2. delete( ) & delete(index)
3. insert( )
4. push( ) methods
5. pop( ) methods
-
-
Associative arrays
-
Associative array methods
-
-
1.size( )
2.delete ( ) & delete(index)
3.num ( )
4.exists( )
5.first( ) ,next( ), prev ( ), last( )
Common Methods for Dynamic Arrays & Queues :
Manipulating Methods of an Array in System Verilog
–> The elements in an array can be manipulated as per our requirement . Some of the methods which can perform
different operations are as follows :
1. reverse( ) : It will reverse the elements of an array from the last index.
Syntax : array_name.reverse( );
2. sort ( ) : It will arrange the elements of an array in ascending order.
Syntax : array_name.sort( );
3. rsort( ) : It will arrange the elements of an array in descending order.
Syntax : array_name.rsort( );
4. shuffle ( ): It will shuffle the elements of an array.
Syntax : array_name.shuffle( );
5. min( ) : It will returns the lowest value of all the elements of an array.
Syntax : array_name.min( );
6. max ( ) : It will returns the highest value of an array .
Syntax : array_name.max( );
7.unique( ) : It will returns the unique values of an array i.e the values which are not repeating.
Syntax : array_name.unique( );
Simulated_Example:
module tb ( );
int mem[ ] = { 1,3,5,8,5,9};
int ram[ ] = {50,20,5,30,40};
int array[ ] = {9,18,3,6,27};
int xtn[ ] = {16,20,4,24,32};
initial
begin
mem.reverse( );
ram.sort( );
array.rsort( );
xtn.shuffle( );
$display(” reversed array values of mem = %p “,mem);
$display(” sorted array values ram= %p “,ram);
$display(” reverse sorted values of array = %p “,array);
$display(” shuffled values of xtn = %p “,xtn);
$display(” minimum value of ram array = %p “,ram.min());
$display(” maximum value of ram array = %p “,ram.max());
$display(“unique value of mem array= %p “, mem.unique());
end
endmodule
Simulator_output:
***********************************************************************************
reversed array values of mem = ‘{9, 5, 8, 5, 3, 1}
sorted array values ram= ‘{5, 20, 30, 40, 50}
reverse sorted valuesof array = ‘{27, 18, 9, 6, 3}
shuffled values of xtn = ‘{24, 20, 32, 16, 4}
minimum value of ram array = ‘{5}
maximum value of ram array = ‘{50}
unique value of mem array = ‘{9, 5, 8, 3, 1}
***********************************************************************************