-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc11_corrected.txt
168 lines (153 loc) · 4.64 KB
/
c11_corrected.txt
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
**Code Generation test case 11: Function call implementation using array parameters- usage of both static and dynamic
Multiple modules with the driver module with single level of nesting
**
<<module array_parameter_demo>>
takes input[ B: array[10..14] of integer, C:array[low..high] of integer];
returns [sum1:integer, sum2: integer, sum3:integer];
start
print(B);
print(C);
declare k, i, p, q: integer;
get_value(p);
get_value(q);
declare A, D: array[10..14] of integer;
declare E: array[p..q] of integer;
get_value(A);
get_value(E);
**Using local variable A - static array**
print(A);
sum1:= 0;
for(k in 10..14)
start
print(A[k]); **requires dynamic bound checking- value of k is available at run time**
sum1:= sum1+A[k];
print(sum1);
end
print(A); **printing A again to verify that the data of its elements in corresponding locations is intact**
print(sum1);
**using local variable E - dynamic array**
E[5]:= E[6]+E[7]; **requires dynamic bound checking - ranges of E are available at run time**
print(E);
**using parameter B - static array**
sum2:=0;
D:=B;
print(D);
for(i in 10..14)
start
print(D[i]); **requires dynamic bound checking- value of i is available at run time**
sum2:= sum2+D[i];
print(sum2);
end
print(D);
print(sum2);
**using parameter C - dynamic array**
sum3:=0;
print(C);
declare j,index:integer;
for(j in 1..4)
start
get_value(index);
sum3:= sum3 + C[index]; **runtime bound checking required**
print(sum3);
end
print(sum3);
end
<<<driver program>>>
start
declare m, n :integer;
declare s1, s2, s3:integer;
get_value(m);
get_value(n);
declare array_A: array[10..14] of integer;
declare array_B: array[m..n] of integer;
get_value(array_A);
get_value(array_B);
[s1, s2, s3]:= use module array_parameter_demo with parameters array_A, array_B;
**formal parameter C of the callee function array_parameter_demo receives the range values from the actual parameter array_B**
print(s1);
print(s2);
print(s3);
end
** On the console Following Notes are for reference and are not supposed be printed on the console
Input: Enter an integer value [Note: Reading values of m and n in driver as 3 and 8 respectively]
3
Input: Enter an integer value
8
Input: Enter 5 array elements of integer type for range 10 to 14
-10
16
12
-8
4
Input: Enter 6 array elements of integer type for range 3 to 8
55
-17
12
105
-87
10
Output: -10 16 12 -8 4
Output: 55 -17 12 105 -87 10
Input: Enter an integer value [Note: Reading values of p and q in array_parameter_demo as 3 and 8 respectively]
3
Input: Enter an integer value
8
Input: Enter 5 array elements of integer type for range 10 to 14 [reading array A]
2
6
8
-15
12
Input: Enter 6 array elements of integer type for range 3 to 8 [reading array E]
1
2
3
4
5
6
Output: 2 6 8 -15 12 [printing A]
Output: 2 [printing values while in for loop of scope 28-32]
Output: 2
Output: 6
Output: 8
Output: 8
Output: 16
Output: -15
Output: 1
Output: 12
Output: 13
Output: 2 6 8 -15 12 [printing A]
Output: 13
Output: 1 2 9 4 5 6 [printing E after an element was modified at line 37]
Output: -10 16 12 -8 4 [printing D after D:=B at line 42]
Output: 10 [printing values while in for loop of scope 45-49]
Output: -10
Output: 16
Output: 6
Output: 12
Output: 18
Output: -8
Output: 10
Output: 4
Output: 14
Output: -10 16 12 -8 4 [printing D]
Output: 14
Output: 55 -17 12 105 -87 10 [printing C at line 55 - input formal parameter receiving values of actual parameter array_B]
Input: Enter an integer value [Note: Reading values of index in 4 iterations and computing sum3]
4
Output: -17 [sum3 computed as sum3+C[4]]
Input: Enter an integer value
8
Output: -7 [sum3 computed as sum3+C[8]]
Input: Enter an integer value
6
Output: 98 [sum3 computed as sum3+C[6]]
Input: Enter an integer value
7
Output: 11 [sum3 computed as sum3+C[7]]
Output: 11
Output: 13 [in driver printing values of return parameters s1, s2, s3]
Output: 14
Output: 11
Similarly run the generated assembly code for other input values and verify.
**