|
|
In pass by reference, functions and tasks directly access the specified variables passed as arguments. In pass by reference, a subroutine operates on all arguments passed to it, but only changes made to arguments declared as var are seen outside the subroutine. Variables of any valid data type can be passed by reference. |
|
|
1 program pass_by_ref {
2 integer flow = 10;
3 bit [7:0] no = 100;
4 print(no, flow);
5 printf("After - Port Number %0d\n",no);
6 printf("After - Flow Number %0d\n",flow);
7 }
8 // var is added infront of each argument to make it
9 // pass by reference
10 task print (var bit [7:0] port_no, var integer flow_no) {
11 printf("Inside Port Number %0d\n",port_no);
12 printf("Insize Number %0d\n",flow_no);
13 flow_no ++;
14 port_no ++;
15 printf("New Flow Number %0d\n",flow_no);
16 printf("New Port Number %0d\n",port_no);
17 }
You could download file pass_by_ref.vr here
|