# Regarding usage of $sformatf with assign statement in generate block

**URL:** <https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828>\
**Category:** UVM\
**Tags:** sformatf, assign, systemverilog-assignment-like, UVM\
**Created:** [September 8, 2022, 1:17pm UTC](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828 "2022-09-08T13:17:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandrashekarsg](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ecc23a/32.png) [@chandrashekarsg](https://verificationacademy.com/forums/u/chandrashekarsg)\
**Post date:** [September 8, 2022, 1:17pm UTC](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/1 "2022-09-08T13:17:43Z")

</div>

```verilog
generate
for(genvar idx=0; idx<16; idx++)begin//{
  assign $sformatf("p%0d_mfr_mdfiss_axiclk_aclk",idx) = mfr_axi_if.master_if[idx].aclk; //assignment-1
  assign mfr_axi_if.master_if[idx].arready = $sformatf("p%0d_mfr_mdfiss_data_axi_sport_arready",idx); //assignment-2
end
endgenerate

```

I’m getting below error :  
Error-[SE] Syntax error  
Following verilog source has syntax error :  
“/nfs/site/disks/alr\_mfr\_001/csg/mdfiss\_Sept8/src/val/tb\_top/mdfiss\_tb\_top.sv”,  
61: token is ‘$sformatf’  
assign $sformatf(“p%0d\_mfr\_mdfiss\_axiclk\_aclk”,idx) = mfr\_axi\_if.master\_if[idx].aclk ;

what’s wrong with these two assignments?  
Is it not permitted to use $sformatf to use like this ?  
If there is way, please let me know how to use…

Quick response will be really helpful.

Thanks in advance.  
Chandrashekar

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 8, 2022, 3:48pm UTC](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/2 "2022-09-08T15:48:24Z")

</div>

_In reply to [chandrashekarsg](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828):_

SystemVerilog is a compiled language (like C); you cannot build hierarchical references to signal name identifiers from strings. I suggest you use your text editor to replicate the lines of code.

There are other tool specific mechanisms to access signal names by string, but not very efficient. Check with your vendor.

---

<div class="post-metadata">

**Author:** ![chandrashekarsg](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ecc23a/32.png) [@chandrashekarsg](https://verificationacademy.com/forums/u/chandrashekarsg)\
**Post date:** [September 8, 2022, 4:59pm UTC](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/3 "2022-09-08T16:59:07Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/2):_

Thank you so much for your quick response Dave…  
I have got a reference where you have told the below in one of the past post. I felt bit of contradiction. So asking to clear my doubt.

**If you want to keep the continuous assignment, then you need to use $sformatf  
generate  
for (ganvar num = 0; num \< 12; num++) begin  
assign hello\_if.fruit[num] = $sformatf(“`HELLO.fruit\_num%0d”, num);  
end  
endgenerate**

[https://verificationacademy.com/forums/systemverilog/it-not-allowed-use-sformat-inside-generate-statement](https://verificationacademy.com/forums/systemverilog/it-not-allowed-use-sformat-inside-generate-statement)

Thanks,  
Chandrashekar

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 16, 2022, 6:32pm UTC](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/4 "2022-09-16T18:32:17Z")

</div>

_In reply to [chandrashekarsg](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/3):_

That example was a generate-for loop being used to construct a string. It was not clear what they intended to do with it.

---

<div class="post-metadata">

**Author:** ![mpattaje](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/mpattaje/32/2477_2.png) [@mpattaje](https://verificationacademy.com/forums/u/mpattaje)\
**Post date:** [November 21, 2022, 10:32pm UTC](https://verificationacademy.com/forums/t/regarding-usage-of-sformatf-with-assign-statement-in-generate-block/40828/5 "2022-11-21T22:32:57Z")

</div>

Hi Chandrashekar,

If your requirement is just assigning a valueto a variable in anyway, even the uvm\_hdl\_force works.

```verilog

generate
  for(genvar idx=0; idx<16; idx++)begin
    uvm_hdl_force($sformatf("p%0d_mfr_mdfiss_axiclk_aclk",idx),mfr_axi_if.master_if[idx].aclk); 
  end
endgenerate

```

-mpattaje
