Order of Associative Array of String Index

I have an associative array with string index

int tcb_field[string] = '{
“capture” : 1,
“scan” : 0,
“jtag_pins_param” : 0,
“cs_1” : 0,
“cs_0” : 0,
“DDSI1_0” : 0,
“DDSI1_1” : 0,
“FEFSI2_0” : 0,
“SDSI2_1” : 0,
“GPIO0_0” : 1,
“GPIO0_1” : 1}
bit [10:0] tcb_seq;
I want to convert this into 11’b10000000011 and bit order must be same.
I know the order of string associative array is lexicographical so I tried as shown below but it’s not working

for(int i=0;i<10;i++)
tcb_seq[11:0] = {tcb_seq[10:0],tcb_field[i]};

All I get is zeros.

Any tips would be appreciated.

looks like you are using int index for a string indexed AA.

for(int i=0;i<10;i++)
tcb_seq[11:0] = {tcb_seq[10:0],tcb_field[i]};

so its giving you default value.

You can try foreach (tcb_field[key]), but SV LRM does not gurantee order in which a foreach elements will be visited. it just requires all of them to be visited once in a foreach.

I would say use first(), next() to traverse the AA .

In reply to sohan_b:

Hi Sohan,

I tried with first,next traversing method. And found that Associatve array stores everything in Ascending order if the index is string. I ran the code in ncverilog.

1 module tb();
2
3 int tcb_field[string] = '{
4 “capture” : 1,
5 “scan” : 0,
6 “jtag_pins_param” : 0,
7 “cs_1” : 0,
8 “cs_0” : 0,
9 “DDSI1_0” : 0,
10 “DDSI1_1” : 0,
11 “FEFSI2_0” : 0,
12 “SDSI2_1” : 0,
13 “GPIO0_0” : 1,
14 “GPIO0_1” : 1};
15
16 bit [10:0] tcb_seq;
17
18
19 string f_idx;
20 string n_idx;
21 int i = 0;
22
23 initial begin
24
25 tcb_field.first(n_idx);
26 for(i = 0; i < tcb_field.num() ; i=i+1 ) begin
27 $display(“tcb_field[%0s]:%0d”,n_idx,tcb_field[n_idx]);
28 tcb_seq[i] = tcb_field[n_idx];
29 tcb_field.next(n_idx);
30 end
31
32 $display(“tcb_seq : %0bb”,tcb_seq);
33
34 end
35
36 endmodule

In reply to saravanan_kpk:

Hi Sohan/rezwan,

According to the LRM section 7.8.2 String index.
— The ordering is lexicographical (lesser to greater).

Thanks
Saravanan