-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.sv
More file actions
108 lines (80 loc) · 1.83 KB
/
Copy pathfunction.sv
File metadata and controls
108 lines (80 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module sv_function;
int x;
//function to add two integer numbers.
function int sum(input int a,b);
sum = a+b;
endfunction
initial begin
x=sum(10,5);
$display("Value of x = %d",x);
end
endmodule
// Output: Value of x=15
// function arguments in declarations and mentioning directions
module sv_function;
int x;
//function to add two integer numbers.
function int sum;
input int a,b;
sum = a+b;
endfunction
initial begin
x=sum(10,5);
$display("Value of x = %d",x);
end
endmodule
// Output: Value of x = 15
// function with return value with the return keyword
module sv_function;
int x;
//function to add two integer numbers.
function int sum;
input int a,b;
return a+b;
endfunction
initial begin
x=sum(10,5);
$display("Value of x = %d",x);
end
endmodule
// Output: Value of x = 15
// Void function
module sv_function;
int x;
//void function to display current simulation time
function void current_time;
$display("Current simulation time is %d",$time);
endfunction
initial begin
#10;
current_time();
#20;
current_time();
end
endmodule
// Current simulation time is 10
// Current simulation time is 30
// an argument with default value example
module argument_passing;
int q;
// function to add three integer numbers.
function int sum(int x=5, y=10, z=20);
return x+y+z;
endfunction
initial begin
q = sum( , ,10);
$display("Value of z = %d",q);
end
endmodule
// Value of z = 25
// argument pass by name example
module argument_passing;
int x,y,z;
function void display(int x,string y);
$display("Value of x = %0d, y = %s",x,y);
endfunction
initial begin
display(.y("Hello World"),.x(2016));
end
endmodule
// Value of x = 2016, y = Hello World