Using a generate with for loop in verilog

后端 未结 2 1655
北恋
北恋 2021-01-11 23:31

I\'m trying to understand why we use generate in verilog along with a for loop.

Using a generate and for loop together:

reg [3:0] temp;
genvar i;
gen         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 00:05

    In general, the main difference between generate for loop and regular for loop is that the generate for loop is generating an instance for each iteration. Meaning that in your example there will be 3 always blocks (as opposed to 1 block in the regular loop case).

    A good example of code that requires generate for is:

    module A();
    ..
    endmodule;
    
    module B();
    parameter NUM_OF_A_MODULES = 2; // should be overriden from higher hierarchy
    genvar i;
    for (i=0 i

    In this example a regular for cannot do the work of creating NUM_OF_A_MODULES instances.

    In your example, you can acheive the required result in both ways. (as long as you fix some minor bugs :) )

提交回复
热议问题