Mask fields in register for specific generic value

Hi,
I have as declaration of register :

class ral_reg_CFGR1 extends uvm_reg;
	rand uvm_reg_field SEC0;
	rand uvm_reg_field SEC1;
	rand uvm_reg_field SEC2;
	rand uvm_reg_field SEC3;
	rand uvm_reg_field SEC4;
	rand uvm_reg_field SEC5;
	rand uvm_reg_field SEC6;
	rand uvm_reg_field SEC7;
	rand uvm_reg_field SEC8;
	rand uvm_reg_field SEC9;
	rand uvm_reg_field SEC10;
	rand uvm_reg_field SEC11;
	rand uvm_reg_field SEC12;
	rand uvm_reg_field SEC13;
	rand uvm_reg_field SEC14;
	rand uvm_reg_field SEC15;
	rand uvm_reg_field SEC16;
	rand uvm_reg_field SEC17;
	rand uvm_reg_field SEC18;
	rand uvm_reg_field SEC19;
	rand uvm_reg_field SEC20;
	rand uvm_reg_field SEC21;
	rand uvm_reg_field SEC22;
	rand uvm_reg_field SEC23;
	rand uvm_reg_field SEC24;
	rand uvm_reg_field SEC25;
	rand uvm_reg_field SEC26;
	rand uvm_reg_field SEC27;
	rand uvm_reg_field SEC28;
	rand uvm_reg_field SEC29;
	rand uvm_reg_field SEC30;
	rand uvm_reg_field SEC31;
	function new(string name = "RISC_RISC_SECCFGR1");
		super.new(name, 32,build_coverage(UVM_CVR_REG_BITS));
		if (has_coverage(UVM_CVR_REG_BITS))
			cg_bits = new();
	endfunction: new
   virtual function void build();
      this.SEC0 = uvm_reg_field::type_id::create("SEC0",,get_full_name());
      this.SEC0.configure(this, 1, 0, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC1 = uvm_reg_field::type_id::create("SEC1",,get_full_name());
      this.SEC1.configure(this, 1, 1, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC2 = uvm_reg_field::type_id::create("SEC2",,get_full_name());
      this.SEC2.configure(this, 1, 2, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC3 = uvm_reg_field::type_id::create("SEC3",,get_full_name());
      this.SEC3.configure(this, 1, 3, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC4 = uvm_reg_field::type_id::create("SEC4",,get_full_name());
      this.SEC4.configure(this, 1, 4, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC5 = uvm_reg_field::type_id::create("SEC5",,get_full_name());
      this.SEC5.configure(this, 1, 5, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC6 = uvm_reg_field::type_id::create("SEC6",,get_full_name());
      this.SEC6.configure(this, 1, 6, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC7 = uvm_reg_field::type_id::create("SEC7",,get_full_name());
      this.SEC7.configure(this, 1, 7, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC8 = uvm_reg_field::type_id::create("SEC8",,get_full_name());
      this.SEC8.configure(this, 1, 8, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC9 = uvm_reg_field::type_id::create("SEC9",,get_full_name());
      this.SEC9.configure(this, 1, 9, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC10 = uvm_reg_field::type_id::create("SEC10",,get_full_name());
      this.SEC10.configure(this, 1, 10, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC11 = uvm_reg_field::type_id::create("SEC11",,get_full_name());
      this.SEC11.configure(this, 1, 11, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC12 = uvm_reg_field::type_id::create("SEC12",,get_full_name());
      this.SEC12.configure(this, 1, 12, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC13 = uvm_reg_field::type_id::create("SEC13",,get_full_name());
      this.SEC13.configure(this, 1, 13, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC14 = uvm_reg_field::type_id::create("SEC14",,get_full_name());
      this.SEC14.configure(this, 1, 14, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC15 = uvm_reg_field::type_id::create("SEC15",,get_full_name());
      this.SEC15.configure(this, 1, 15, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC16 = uvm_reg_field::type_id::create("SEC16",,get_full_name());
      this.SEC16.configure(this, 1, 16, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC17 = uvm_reg_field::type_id::create("SEC17",,get_full_name());
      this.SEC17.configure(this, 1, 17, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC18 = uvm_reg_field::type_id::create("SEC18",,get_full_name());
      this.SEC18.configure(this, 1, 18, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC19 = uvm_reg_field::type_id::create("SEC19",,get_full_name());
      this.SEC19.configure(this, 1, 19, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC20 = uvm_reg_field::type_id::create("SEC20",,get_full_name());
      this.SEC20.configure(this, 1, 20, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC21 = uvm_reg_field::type_id::create("SEC21",,get_full_name());
      this.SEC21.configure(this, 1, 21, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC22 = uvm_reg_field::type_id::create("SEC22",,get_full_name());
      this.SEC22.configure(this, 1, 22, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC23 = uvm_reg_field::type_id::create("SEC23",,get_full_name());
      this.SEC23.configure(this, 1, 23, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC24 = uvm_reg_field::type_id::create("SEC24",,get_full_name());
      this.SEC24.configure(this, 1, 24, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC25 = uvm_reg_field::type_id::create("SEC25",,get_full_name());
      this.SEC25.configure(this, 1, 25, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC26 = uvm_reg_field::type_id::create("SEC26",,get_full_name());
      this.SEC26.configure(this, 1, 26, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC27 = uvm_reg_field::type_id::create("SEC27",,get_full_name());
      this.SEC27.configure(this, 1, 27, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC28 = uvm_reg_field::type_id::create("SEC28",,get_full_name());
      this.SEC28.configure(this, 1, 28, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC29 = uvm_reg_field::type_id::create("SEC29",,get_full_name());
      this.SEC29.configure(this, 1, 29, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC30 = uvm_reg_field::type_id::create("SEC30",,get_full_name());
      this.SEC30.configure(this, 1, 30, "RW", 0, 1'h0, 1, 0, 0);
      this.SEC31 = uvm_reg_field::type_id::create("SEC31",,get_full_name());
      this.SEC31.configure(this, 1, 31, "RW", 0, 1'h0, 1, 0, 0);
   endfunction: build

I want that depends on generic1 which has value of 28, the fields 28,29,30 and 31 will be configured as Reserved.
I have to check multiple values of generic1, so I want to have a generic method to handle this feature.
could you have any idea ?
best regards

In reply to bensaidi:

It would have been so much easier if you had declared an array of fields

class ral_reg_CFGR1 extends uvm_reg;
	rand uvm_reg_field SEC[32];

	function new(string name = "RISC_RISC_SECCFGR1");
		super.new(name, 32,build_coverage(UVM_CVR_REG_BITS));
		if (has_coverage(UVM_CVR_REG_BITS))
			cg_bits = new();
	endfunction: new
   virtual function void build();
      foreach(SEC[field]) begin
           this.SEC0 = uvm_reg_field::type_id::create($sformatf("SEC%0d",field),,get_full_name());
           if (field < generic1) b
              this.SEC[field].configure(this, 1, 0, "RW", 0, 1'h0, 1, 0, 0);
           else
              this.SEC[field].configure(this, 1, 31, "R0", 1, 1'h0, 1, 0, 0); // you can use "NO_ACCESS" for uvm1.2
      end
   endfunction: build

But instead you will have to replicate the code for each field.

In reply to dave_59:

Hi,
thank you for your response. I think this is the best way.