菜鸟关于verilog中函数调用的问题
时间:10-02
整理:3721RD
点击:
源程序如下:在但是仿真波形输出的 y值是 xxxxxxx
module hanshu(x,y
);
input [3:0]x;
output integer y;
function automatic integer factor;
input [3:0]a;
reg [3:0]i;
begin
factor=1;
for(i=2;i<=a;i=i+1)
begin
factor=factor*i;
$display("the value of fanctor at present is :%e",factor);
end
end
endfunction
always@(x)
begin
y=factor(x);
end
endmodule
module hanshu(x,y
);
input [3:0]x;
output integer y;
function automatic integer factor;
input [3:0]a;
reg [3:0]i;
begin
factor=1;
for(i=2;i<=a;i=i+1)
begin
factor=factor*i;
$display("the value of fanctor at present is :%e",factor);
end
end
endfunction
always@(x)
begin
y=factor(x);
end
endmodule
X输入问题。

把i,a换成integer试一试。
function automatic integer factor;
input integer a;
integer i;
或者,这样试一试:
把testbench中的
#10 x=4'b1111;
换成
#10 x=4'b0111;
a=4'b1111时,
for(i=2;i<=a;i=i+1)
是个无限循环。
太复杂了
