# UVM reg field access via name

**URL:** <https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253>\
**Category:** UVM\
**Tags:** UVM, uvm\_reg, UVM\_reg\_field, get\_field\_by\_name, get\_parent\
**Created:** [June 28, 2017, 8:58am UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253 "2017-06-28T08:58:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayurverf](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@mayurverf](https://verificationacademy.com/forums/u/mayurverf)\
**Post date:** [June 28, 2017, 8:58am UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/1 "2017-06-28T08:58:46Z")

</div>

Is anyone aware as to how we get the details of all the parent registers for a given bit field via name especially if the bit filed is spread over multiple registers … ?

In our register map … we have a bit field[BIT\_FIELD\_NAME of width 10 bits] … spread over two registers 4 bits in one and remaining in another

When we try to get the following :

uvm\_status\_e status;  
uvm\_reg\_data\_t value;  
string name1;  
uvm\_reg\_field reg\_field;  
uvm\_reg parent\_reg;  
name1 = “BIT\_FIELD\_NAME”;

reg\_field=user\_reg\_block.user\_reg\_map0.get\_field\_by\_name(name1);

parent\_reg=reg\_field.get\_parent();

The above only returns the first parent register … is their a way in which i can get the entire list of parent registers … ?

---

<div class="post-metadata">

**Author:** ![Tudor\_Timi](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/tudor_timi/32/1897_2.png) [@Tudor\_Timi](https://verificationacademy.com/forums/u/Tudor_Timi)\
**Post date:** [June 28, 2017, 10:18am UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/2 "2017-06-28T10:18:01Z")

</div>

_In reply to [mayurverf](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253):_

The brute force approach is to loop over all registers and collect all of them that have the field:

```verilog

uvm_reg regs[$];
uvm_reg regs_with_field[$];
reg_map.get_registers(regs);

foreach (regs*)
  if (regs[i].get_field_by_name(field_name) != null)
    regs_with_field.push_back(regs[i]);

```

There’s a [i]get\_fields(…)\* function in _uvm\_reg\_map_ that returns all fields in all regs. You could alternatively loop over those to find the fields with the same name and get their parents.

---

<div class="post-metadata">

**Author:** ![mayurverf](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@mayurverf](https://verificationacademy.com/forums/u/mayurverf)\
**Post date:** [June 28, 2017, 11:22am UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/3 "2017-06-28T11:22:18Z")

</div>

_In reply to [Tudor Timi](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/2):_

Thanks Tudor,

Your suggestion should be able to give me the list … just one more question here …

is their any way i can get to know the which bits of the bit filed are present in the concerned register …

For e.g the 1st register would have bits [4:0] and the 2nd register would have bits [9:5] of the same bit field … ?

---

<div class="post-metadata">

**Author:** ![Tudor\_Timi](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/tudor_timi/32/1897_2.png) [@Tudor\_Timi](https://verificationacademy.com/forums/u/Tudor_Timi)\
**Post date:** [June 28, 2017, 1:27pm UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/4 "2017-06-28T13:27:21Z")

</div>

_In reply to [mayurverf](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/3):_

All UVM REG classes provide introspection functions to be able to inspect various properties. The API docs should help you, such as this one for [uvm\_reg\_field](https://www.vmmcentral.com/uvm_vmm_ik/files3/reg/uvm_reg_field-svh.html). You can get this information by calling _get\_lsb\_pos()_ and _get\_n\_bits()_ on each field object.

---

<div class="post-metadata">

**Author:** ![prashantk](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/ccd318/32.png) [@prashantk](https://verificationacademy.com/forums/u/prashantk)\
**Post date:** [June 12, 2019, 5:57pm UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/5 "2019-06-12T17:57:03Z")

</div>

_In reply to [Tudor Timi](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/4):_

Hi Tudor ,

Is there any way to set those fields by some value. I am using the same foreach loop to get all the registers.But performing some tasks in the fields of those registers.

For example : -

```verilog
foreach (maps[j])
                   begin 
                       foreach (fields[k]) 
                          begin 
                             if(fields[k].get_n_bits()> 1)
                              begin 
                               for(int n = 0;n < fields[k].get_n_bits();n++)
                                  register_var[regidx].fields[k].set(data[n]); //setting the desired value 
                              end
                           end
                    end

```

But this code is not working as the register variable do not have “fields” in them.

Thanks

---

<div class="post-metadata">

**Author:** ![Tudor\_Timi](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/tudor_timi/32/1897_2.png) [@Tudor\_Timi](https://verificationacademy.com/forums/u/Tudor_Timi)\
**Post date:** [June 19, 2019, 9:43am UTC](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/6 "2019-06-19T09:43:07Z")

</div>

_In reply to [pk\_94](https://verificationacademy.com/forums/t/uvm-reg-field-access-via-name/33253/5):_

Just do:

```verilog

fields[k].set(data[n]);

```

The field already knows which register it belongs to.
