没有办法,循环次数必须是整形变量或常量,只能写成:
module fun(ope,fac);
function[31:0] factorial;
input[3:0] opa;
reg[3:0] i;
begin
factorial = opa ? 1 : 0;
i=2;
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
if(i<=opa)
begin
factorial = i* factorial;
i=i+1;
end
end
endfunction
input[3:0] ope;
output[31:0] fac;
reg[31:0] fac;
always @(ope)
begin
fac=factorial(ope);
end