I just wrote a design in Verilog that takes two operands as input,
(leftOp) and (rightOp), and outputs one operand, (result), where the
common length of all operands is defined by parameter (nmBits), that
defaults to 1. I want to loop through the bits in (result), and make
each the exclusive or of the bit on the opposite side on (leftOp) and
(rightOp). My code is:
1 | module rbwx ( result, leftOp, rightOp);
|
2 | parameter nmBits = 1;
|
3 | integer highBit = nmBits - 1;
|
4 | output [ highBit:0] result;
|
5 | input [ highBit:0] leftOp;
|
6 | input [ highBit:0] rightOp;
|
7 |
|
8 | genvar ix, opp;
|
9 |
|
10 | for (ix = 0; ix < nmBits; ix = ix + 1)
|
11 | begin
|
12 | opp = highBit - ix;
|
13 | xor2 x2( result[ ix], leftOp[ opp], rightOp[ opp]);
|
14 | end
|
15 |
|
16 | endmodule
|
When I run Icarus on this I get:
1 | D:\Hf\Verilog\Unpacked\Common>\Icarus\bin\iverilog -g2009 -o rbwx.out rbwx.sv
|
2 | rbwx.sv:12: syntax error
|
3 | rbwx.sv:12: error: Invalid module instantiation
|
4 |
|
5 | D:\Hf\Verilog\Unpacked\Common>
|
So my design is generating a syntax error right where I assign (opp) to
the difference between (highBit) and (ix). Why can't I do this, since
(opp) is defined as a (genvar)? Can I only use (genvar)s in the control
section of a loop?