Array operations in the SystemVerilog

Source: Internet
Author: User
Tags shuffle

Array basic operations in SV:

/*      exercsise platform :     questa  sim 10.1b*/class array;  int array[9:0] ;    function  New ();      for ( int i = 0 ; i < 10 ;  i++ )          array[i] = i ;       /*          array =  ' {' {{5{5}},default:0};          }, ' The basic method of assignment cannot be used, Maybe the compiler's version is too low       */  endfunction:new      Function void print ();     foreach (Array[i])  begin        $display (" array[%d] = %d ", I,array[i]);    end     for  ( int i = 0 ; i < 10 ; i++ ) begin        $write (" ** ");    end     $display ();   endfunction:print    function void funcs ();       int pos[$] ;    //    reduction of Operation &NBSP;XOR&NBSP;,&NBSP;OR&NBSP;  and ,  xnor  , sum , product  et     $ Display ("the sum is %d ", Array.sum ());     $display ("the and  is %d  ", Array.and ());     $display (" the  or is %d  ", Array.or ()  );     $display ("the xor is %d ", Array.xor ());      $display ("the product is %d ", Array.product ());         //    Index Operations: Obtain the appropriate array primitive location      $display (" max value is %d ", Array.max () [0]);     $display (" min value is %d ", Array.min () [0]);     array = array.unique ();     print ();        //   when in a class, calls the function of its own class, which can be called directly. This is the same as CPP     pos = array.find with  ( item == 7 )  ;     //  find  a variety of variants:  find_first   find_last   find_first_index   find_last_index     $display (" pos  : %d ? value: %d  ", Pos[0],array[pos[0]]);         //   Sort operations:  sort ,  rsort  , reverse , shuffle  ,     //  where  sort ,rsort&nbspThe;  can be combined with the with, sorting     array.shuffle ();     $display according to the conditions with the (" Shuffled: ");     print ();     array.sort ();     $ Display ("Sorted:");     print ();     array.rsort ();      $display ("resorted:");     print ();     array.reverse ();      $display ("Reversed:");     print ();     endfunction: funcsendclass:arraymodule top;  array array;  int arr[] ;      //    declaration of dynamic Arrays     initial begin     //  initial process    array=new ();     Array.print ();     array.funcs ();    arr = new[20];    //    Allocating memory Size      foreach (Arr[i])   $display (" arr[%2d] = %d ", I,arr[i]);       $display ("***************");     arr.delete ();  endendmodule//     all operations on fixed-length arrays can be used on dynamic arrays


Array operations in the SystemVerilog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.