0
votes

I'm trying to keep track of the number of times the program runs through a nested generate block in verilog and use it as the index for an array but it seems to require a constant for the index. Is there a way to do that? //I just tested it by manually creating the generate block and it works but I'd still like to know if what I was trying to do is possible Here is my code

module fivbmulti(input [4:0] xIn, yIn,
                  output [9:0] pOut );

wire [24:0] passSum, passCout, a_b;
integer count = 0;         //This is what I would like to use for the index
generate
genvar i;
for (i = 0; i <= 4; i = i+1) begin: row
    genvar j;
        for (j = 0; j <=4; j = j + 1) begin: col
            assign a_b[count] = xIn[j] & yIn[i];  //use it here as the index for a_b
            count = count + 1;        //increment it here after each generation
            end
    end
endgenerate

assign pOut[0] = a_b[0];

adder row0col0(.aIn(a_b[1]), .bIn(a_b[5]), .cIn(1'b0), .cOut(passCout[0]), .sum(pOut[1]));  
adder row1col1(.aIn(a_b[2]), .bIn(a_b[6]), .cIn(1'b0), .cOut(passCout[1]), .sum(passSum[1]));
adder row1col2(.aIn(a_b[3]), .bIn(a_b[7]), .cIn(1'b0), .cOut(passCout[2]), .sum(passSum[2]));
adder row1col3(.aIn(a_b[4]), .bIn(a_b[8]), .cIn(1'b0), .cOut(passCout[3]), .sum(passSum[3]));

adder row2col0(.aIn(passSum[1]), .bIn(a_b[10]), .cIn(passCout[0]), .cOut(passCout[4]), .sum(pOut[2]));
adder row2col1(.aIn(passSum[2]), .bIn(a_b[11]), .cIn(passCout[1]), .cOut(passCout[5]), .sum(passSum[5]));
adder row2col2(.aIn(passSum[3]), .bIn(a_b[12]), .cIn(passCout[2]), .cOut(passCout[6]), .sum(passSum[6]));
adder row2col3(.aIn(a_b[9]), .bIn(a_b[13]), .cIn(passCout[3]), .cOut(passCout[7]), .sum(passSum[7]));

adder row3col0(.aIn(passSum[5]), .bIn(a_b[15]), .cIn(passCout[4]), .cOut(passCout[8]), .sum(pOut[3]));
adder row3col1(.aIn(passSum[6]), .bIn(a_b[16]), .cIn(passCout[5]), .cOut(passCout[9]), .sum(passSum[9]));
adder row3col2(.aIn(passSum[7]), .bIn(a_b[17]), .cIn(passCout[6]), .cOut(passCout[10]), .sum(passSum[10]));
adder row3col3(.aIn(a_b[14]), .bIn(a_b[18]), .cIn(passCout[7]), .cOut(passCout[11]), .sum(passSum[11]));

adder row4col0(.aIn(passSum[9]), .bIn(a_b[20]), .cIn(passCout[8]), .cOut(passCout[12]), .sum(pOut[4]));
adder row4col1(.aIn(passSum[10]), .bIn(a_b[21]), .cIn(passCout[9]), .cOut(passCout[13]), .sum(passSum[13]));
adder row4col2(.aIn(passSum[11]), .bIn(a_b[22]), .cIn(passCout[10]), .cOut(passCout[14]), .sum(passSum[14]));
adder row4col3(.aIn(a_b[19]), .bIn(a_b[23]), .cIn(passCout[11]), .cOut(passCout[15]), .sum(passSum[15]));

adder row5col0(.aIn(passSum[13]), .bIn(1'b0), .cIn(passCout[12]), .cOut(passCout[16]), .sum(pOut[5]));
adder row5col1(.aIn(passSum[14]), .bIn(passCout[16]), .cIn(passCout[13]), .cOut(passCout[17]), .sum(pOut[6]));
adder row5col2(.aIn(passSum[15]), .bIn(passCout[17]), .cIn(passCout[14]), .cOut(passCout[18]), .sum(pOut[7]));
adder row5col3(.aIn(a_b[24]), .bIn(passCout[18]), .cIn(passCout[15]), .cOut(pOut[9]), .sum(pOut[8]));



endmodule
1

1 Answers

0
votes

If that style of syntax was possible count would have to be a genvar, however it does not seem that you can use it like that. You should base it entirely on i, and j something like i*4+j:

generate
genvar i;
genvar j;
  for (i = 0; i <= 4; i = i+1) begin: row
    for (j = 0; j <=4; j = j + 1) begin: col
      assign a_b[i*4+j] = xIn[j] & yIn[i];  //use it here as the index for a_b
    end
  end
endgenerate

I have used i * (number of iterations of j)+ j, which should evaluate to the equivalent of count incrementing.