You can certainly find a register using a string which has been composed programmatically. You will need to use uvm_reg_block::get_reg_by_name
.
The usage will look something like this:
function void write_reg_by_num(int num, bit[31:0] data);
string reg_name = $sformatf("REG%0d", num);
uvm_reg reg = regmodel.get_reg_by_name(reg_name);
if (reg == null) begin
// No reg was found... you likely want to flag an error here
end else begin
uvm_status_e status;
reg.write(status, data);
end
endfunction
Note that the resulting uvm_reg
object is of the base class type, so if you want to access individual fields you need to use the base class methods to access the fields. That is, you need to use the methods on uvm_reg
, e.g. uvm_reg::get_field_by_name