Writing to reg field

I want to write all ones to the fields of a register.
space = uvm_reg_field::type_id::create(“space”);
sky = uvm_reg_field::type_id::create(“sky”);
gravity = uvm_reg_field::type_id::create(“gravity”);
mass = uvm_reg_field::type_id::create(“mass”);
Lets say we have the above fields, having different field width.
I use get_fields() method to get the field list. get_n_bits() to get the field width,once I get the field width I want to write all ones to the field width.
say the field width for SPACE is 2, I want to write 2’b11 to space field of the register, similarly sky being 4 bit wide I want to write 4’b1111 to that register field.
How should I proceed??

In reply to 100rabhh:

Hello, I’m quite sure you wanna select which field has to hold all 1, rather then writing all ones into the register. So you wanna just:

  1. Check the access_policy (RW or so)
  2. Create a mask containing 1s based on the width
  3. Use the mask to gate the FFFFFF in order to write 1s only to that specific field

// Get the register's fields first
// check if your provided field is in the register targeted 
idxs = fields.find_first with(item.get_full_name == "name you provide");
if(idx.size() > 0) begin
else begin
// Create the mask
foreach(idx[ii]) begin
if(fields[idx[ii]].get_access() == "RW") begin
    // This is for all the fields
    for (int j = fields[idx[ii]].get_lsb_pos(); j < fields[idx[ii]].get_lsb_pos()+fields[idx[ii]].get_n_bits(); j++)
       mask[j] = 1'b0;
// Create write data mask has been previously init to 0
wr_data = 32hFFFF_FFFF & mask;