R
Riad KACED
Guest
Dear Community,
I'm fairly new to Verilog and I'm already hitting some hurdles using
the 'genvar' statement.
I have written 2 verilog modules, both of them are using for loops.
though the for loop index is required to be genvar when used out of
always/initial block.
This is my example:
1. The loop index is genvar, the compile fails otherwise:
module rkXor (xout, xin1, xin2);
parameter width = 4;
output [1:width] xout;
input [1:width] xin1, xin2;
genvar i;
for ( i = 1; i <= width; i=i+1 )
assign xout = xin1 ^ xin2;
endmodule
2. The loop index is integer, the compile would complain otherwise:
module clock1(clock);
parameter period = 20;
parameter nbBits = 4;
output [0:nbBits-1] clock;
reg [0:nbBits-1] clock;
integer i,j;
initial begin
for (i = 0; i < nbBits; i=i+1) begin: loop1
clock = 0;
end
end
always
begin
for (j = 0; j < nbBits; j=j+1) begin: loop2
#(period/2) clock[j] = 1;
#(period/2) clock[j] = 0;
end
end
endmodule
Can someone shed some light on this please ? i.e. why the loop is
behaving differently when used in the always/initial bloc ?
Thank you very much in advance,
Regards,
Riad.
I'm fairly new to Verilog and I'm already hitting some hurdles using
the 'genvar' statement.
I have written 2 verilog modules, both of them are using for loops.
though the for loop index is required to be genvar when used out of
always/initial block.
This is my example:
1. The loop index is genvar, the compile fails otherwise:
module rkXor (xout, xin1, xin2);
parameter width = 4;
output [1:width] xout;
input [1:width] xin1, xin2;
genvar i;
for ( i = 1; i <= width; i=i+1 )
assign xout = xin1 ^ xin2;
endmodule
2. The loop index is integer, the compile would complain otherwise:
module clock1(clock);
parameter period = 20;
parameter nbBits = 4;
output [0:nbBits-1] clock;
reg [0:nbBits-1] clock;
integer i,j;
initial begin
for (i = 0; i < nbBits; i=i+1) begin: loop1
clock = 0;
end
end
always
begin
for (j = 0; j < nbBits; j=j+1) begin: loop2
#(period/2) clock[j] = 1;
#(period/2) clock[j] = 0;
end
end
endmodule
Can someone shed some light on this please ? i.e. why the loop is
behaving differently when used in the always/initial bloc ?
Thank you very much in advance,
Regards,
Riad.