5

As a continuation to my previous question, is there a way, in Verilog, to instantiate n times a given module, without having to use n different lines:

myModule instance1();
myModule instance2();
myModule instance3();
...

Can I do "batch" instantiation in Verilog?

Randomblue
  • 10,953
  • 29
  • 105
  • 178

1 Answers1

6

Ok, found it. Search here for the "generate statement":

Verilog 2001 generate statement allow to either instantiating multiple modules without typing them so many times or instantiating modules conditionally. You can use if-else to conditionally instantiate the modules. Also, if you want to instantiate the same module multiple times then better use for loop. This will save you lot of time.

UPDATE

this link is viable 4.27.2023

http://web.archive.org/web/20120723031726/http://www.inno-logic.com:80/resourcesTips.html

The following code will do the job:

genvar i;
generate for (i = 0; i < n; i = i + 1) begin
    myModule instance();
end endgenerate
jsotola
  • 2,497
  • 2
  • 12
  • 21
Randomblue
  • 10,953
  • 29
  • 105
  • 178
  • 3
    If you are going to write an answer, include a bit more detail. When that link goes dead, your answer will have no value. – Kellenjb May 23 '12 at 15:32
  • 1
    For the record, VHDL also has a generate statement. – ajs410 May 24 '12 at 18:53
  • This answer doesn't work on Vivado 2013. It just instantiates one instance of myModule with the name "instance". Is there another solution? genvar i; generate for (i = 0; i < n; i = i + 1) begin myModule instance(); end endgenerate – Abdullah Giray Yağlıkçı Jan 14 '14 at 16:10