Complete the code to start a generate block with a loop variable.
genvar i; generate for ([1] = 0; [1] < 4; [1] = [1] + 1) begin // module instances end endgenerate
The loop variable in a generate block is usually declared as genvar i; and used as i in the for loop.
Complete the code to instantiate a module inside a generate loop.
genvar i; generate for (i = 0; i < 3; i = i + 1) begin : gen_block my_module [1] (.in(i), .out(out[i])); end endgenerate
Each instance inside a generate loop should have a unique name. Using inst_i appends the loop variable to the instance name.
Fix the error in the generate loop header.
genvar [1]; generate for ([1] = 0; [1] < 5; [1] = [1] + 1) begin // instances end endgenerate
The loop variable must be the same in the declaration and the loop condition. Here, i is used in the condition, so the declaration must be genvar i.
Fill both blanks to create a generate loop that instantiates 8 modules with unique names.
genvar [1]; generate for ([2] = 0; [2] < 8; [2] = [2] + 1) begin : gen_loop mod u_[2] (.in([2]), .out(out[[2]])); end endgenerate
The genvar variable and the loop variable must be the same. Using i for both ensures consistency.
Fill all three blanks to create a generate block that instantiates modules only for even indices.
genvar [1]; generate for ([2] = 0; [2] < 10; [2] = [2] + 1) begin : gen_even if ([3] % 2 == 0) begin mod u_[2] (.in([2]), .out(out[[2]])); end end endgenerate
The genvar and loop variable must be the same. The condition uses the loop variable i to check for even indices.
