|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
避免大家下载,我把我的源码贴出来,欢迎讨论使用仿真软件questasim10.2c
脚本执行操作
vlib work
vlog -sv ./tst_4.sv
vsim -t 1ps work.tb -novopt
run 1ns
tst_4.sv源码如下
module tb; // should not compile
int c1,c2;
int c3,c4;
initial
begin
fork
c1 = add(1,1);
c2 = add(2,2);
join_none
#1ps
$display("the data c1 is %d,time is %t",c1,$realtime);
$display("the data c2 is %d,time is %t",c2,$realtime);
fork
c3 = add_no(1,1);
c4 = add_no(2,2);
join_none
#1ps
$display("the data c3 is %d,time is %t",c3,$realtime);
$display("the data c4 is %d,time is %t",c4,$realtime);
end
function automatic int add(input int a,input int b);
int c;
c = a+b;
return c;
endfunction
function static
int add_no(input int a,input int b);
static int c;
c = a+b;
return c;
endfunction
endmodule
////////////////////////////////打印显示////////////////////////////////////////////////
# the data c1 is 2,time is 1
# the data c2 is 4,time is 1
# the data c3 is 2,time is 2
# the data c4 is 4,time is 2
为什么结果一致,automatic使用和没有使用结果一样呢,不是说静态的使用一个存储空间么?
以为是function不是task
就修改了task一版代码如下,发现没有什么用
module tb; // should not compile
int c1,c2;
int c3,c4;
initial
begin
fork
add(1,1,c1);
add(2,2,c2);
join_none
#1ps
$display("the data c1 is %d,time is %t",c1,$realtime);
$display("the data c2 is %d,time is %t",c2,$realtime);
fork
add_no(1,1,c3);
add_no(2,2,c4);
join_none
#1ps
$display("the data c3 is %d,time is %t",c3,$realtime);
$display("the data c4 is %d,time is %t",c4,$realtime);
end
task automatic add(input int a,input int b,output int c);
c = a+b;
endtask
task add_no(input int a,input int b,output int c);
c = a+b;
endtask
endmodule
////////////////////////////////打印显示////////////////////////////////////////////////
# the data c1 is 2,time is 1
# the data c2 is 4,time is 1
# the data c3 is 2,time is 2
# the data c4 is 4,time is 2
大侠路过时,提示一两句吧
还有为什么在initial end内部申明对象,比如 packet P1 = new(); 需要加上automatic和static信息,在initial end外部就不需要,
希望给些解释
再贴一个小例子辅助理解,这个加不加影响最终结果,加了为120,不加结果为1;没有搞懂,和我发的例子有啥区别,不是static均共享内存么?
module tb;
reg [31:0] n;
reg [31:0] result;
initial begin
n = 5;
result = 0;
result = factorial(n);
$display("n=%d, result=%d", n, result);
$finish;
end
function [31:0] factorial (
//function automatic [31:0] factorial (
input [31:0] iN
);
if (iN == 1)
factorial = 1;
else
factorial = iN * factorial(iN-1);
endfunction |
|