禾雨

导航

SV 之 关联数组

module coarr;

  bit[63:0]  rom[bit[63:0]] ;   // 构建关联数组

  bit[63:0]  idx ;     //  相对应的索引

 

  function automatic void print(bit[63:0] pos, ref bit[63:0] rom[bit[63:0]]);

    $display(" rom[%d] = %d ",pos,rom[pos]);

  endfunction:print

 

  initial begin

     idx = 1 ;

     repeat(64) begin        //  对关联数组初始化,但实际上只存储了64个值

       rom[idx] = idx ;

       idx = idx << 1 ;

     end

    

     if( rom.first(idx)) begin     //  找到第一个索引的位置

       print(idx,rom);

       while( rom.next(idx) ) print(idx,rom);    //   找到之后的索引的位置

     end

     

  end

endmodule:coarr

 

仿真结果:

#  rom[            1] =                    1 
#  rom[           2] =                    2 
#  rom[          4] =                    4 
#  rom[           8] =                    8 
#  rom[          16] =                   16 
#  rom[          32] =                   32 
#  rom[          64] =                   64 
#  rom[          128] =                  128 
#  rom[         256] =                  256 
#  rom[          512] =                  512 
#  rom[         1024] =                 1024 
#  rom[         2048] =                 2048 
#  rom[         4096] =                 4096 
#  rom[         8192] =                 8192 
#  rom[        16384] =                16384 
#  rom[        32768] =                32768 
#  rom[         65536] =                65536 
#  rom[        131072] =               131072 
#  rom[        262144] =               262144 
#  rom[        524288] =               524288 
#  rom[       1048576] =              1048576 
#  rom[       2097152] =              2097152 
#  rom[       4194304] =              4194304 
#  rom[       8388608] =              8388608 
#  rom[       16777216] =             16777216 
#  rom[       33554432] =             33554432 
#  rom[       67108864] =             67108864 
#  rom[      134217728] =            134217728 
#  rom[      268435456] =            268435456 
#  rom[      536870912] =            536870912 
#  rom[      1073741824] =           1073741824 
#  rom[      2147483648] =           2147483648 
#  rom[      4294967296] =           4294967296 
#  rom[      8589934592] =           8589934592 
#  rom[     17179869184] =          17179869184 
#  rom[     34359738368] =          34359738368 
#  rom[     68719476736] =          68719476736 
#  rom[     137438953472] =         137438953472 
#  rom[     274877906944] =         274877906944 
#  rom[     549755813888] =         549755813888 
#  rom[     1099511627776] =        1099511627776 
#  rom[    2199023255552] =        2199023255552 
#  rom[    4398046511104] =        4398046511104 
#  rom[     8796093022208] =        8796093022208 
#  rom[    17592186044416] =       17592186044416 
#  rom[    35184372088832] =       35184372088832 
#  rom[    70368744177664] =       70368744177664 
#  rom[    140737488355328] =      140737488355328 
#  rom[   281474976710656] =      281474976710656 
#  rom[   562949953421312] =      562949953421312 
#  rom[   1125899906842624] =     1125899906842624 
#  rom[   2251799813685248] =     2251799813685248 
#  rom[   4503599627370496] =     4503599627370496 
#  rom[   9007199254740992] =     9007199254740992 
#  rom[  18014398509481984] =    18014398509481984 
#  rom[  36028797018963968] =    36028797018963968 
#  rom[  72057594037927936] =    72057594037927936 
#  rom[  144115188075855872] =   144115188075855872 
#  rom[  288230376151711744] =   288230376151711744 
#  rom[  576460752303423488] =   576460752303423488  
#  rom[ 1152921504606846976] =  1152921504606846976 
#  rom[ 2305843009213693952] =  2305843009213693952 
#  rom[ 4611686018427387904] =  4611686018427387904 
#  rom[ 9223372036854775808] =  9223372036854775808

 

posted on 2019-08-21 17:28  禾雨  阅读(3602)  评论(0编辑  收藏  举报