2 .AP "AN EXAMPLE PROGRAM"
7 1 program example(output);
8 2 {This program just demonstrates typical EM code.}
9 3 type rec = record r1: integer; r2:real; r3: boolean end;
10 4 var mi: integer; mx:real; r:rec;
12 6 function sum(a,b:integer):integer;
17 11 procedure test(var r: rec);
23 17 a: array[1..100] of integer;
32 26 for i:= 1 to 100 do a[i] := i * i;
36 30 i := sum(r.r1, a[j]);
37 31 while i > 0 do begin j := j + r.r1; i := i - 1 end;
38 32 with r do begin r3 := b; r2 := x+y; r1 := 0 end;
40 34 1: writeln(j, i:6, x:9:3, b)
42 36 begin {main program}
50 The EM code as produced by the Pascal-VU compiler is given below. Comments
51 have been added manually. Note that this code has already been optimized.
56 mes 2,2,2 ; wordsize 2, pointersize 2
58 rom 't.p\e000' ; the name of the source file
59 hol 552,\-32768,0 ; externals and buf occupy 552 bytes
60 exp $sum ; sum can be called from other modules
61 pro $sum,2 ; procedure sum ; 2 bytes local storage
62 lin 8 ; code from source line 8
63 ldl 0 ; load two locals ( a and b )
65 ret 2 ; return the result
66 end 2 ; end of procedure ( still two bytes local storage )
68 rom 1,99,2 ; descriptor of array a[]
69 exp $test ; the compiler exports all level 0 procedures
70 pro $test,226 ; procedure test, 226 bytes local storage
72 rom 4.8F8 ; assemble Floating point 4.8 (8 bytes) in
74 rom 0.5F8 ; same for 0.5
75 mes 3,\-226,2,2 ; compiler temporary not referenced by address
76 mes 3,\-24,2,0 ; the same is true for i, j, b and c in test
80 mes 3,\-20,8,0 ; and for x and y
82 lin 20 ; maintain source line number
85 lni ; lin 21 prior to optimization
91 stl \-2 ; i := 3 * j + 6
92 lni ; lin 22 prior to optimization
97 lni ; lin 23 prior to optimization
105 lni ; lin 24 prior to optimization
108 lni ; lin 25 prior to optimization
111 lni ; lin 26 prior to optimization
125 inl \-2 ; increment i and loop
133 lni ; lin 28 prior to optimization
137 lni ; lin 29 prior to optimization
144 lni ; lin 30 prior to optimization
151 asp 4 ; remove parameters from stack
152 lfr 2 ; get function result
157 zle *5 ; while i > 0 do
161 stl \-4 ; j := j + r.r1
167 stl \-226 ; make copy of address of r
179 lin 34 ; note the absence of the unnecessary jump
180 lae 22 ; address of output structure
182 cal $_wri ; write integer with default width
183 asp 4 ; pop parameters
187 cal $_wsi ; write integer width 6
194 cal $_wrf ; write fixed format real, width 9, precision 3
198 cal $_wrb ; write boolean, default width
203 ret 0 ; return, no result
206 pro $_main,0 ; main program
208 con 2,\-1,22 ; description of external files
211 fil .1 ; maintain source file name
212 lae .6 ; description of external files
213 lae 0 ; base of hol area to relocate buffer addresses
214 cal $_ini ; initialize files, etc...
221 lni ; lin 38 prior to optimization
224 lni ; lin 39 prior to optimization
225 lae 10 ; address of r
229 cal $_hlt ; cleanup and finish
232 mes 5 ; reals were used
236 The compact code corresponding to the above program is listed below.
237 Read it horizontally, line by line, not column by column.
238 Each number represents a byte of compact code, printed in decimal.
239 The first two bytes form the magic word.
242 173 0 159 122 122 122 255 242 1 161 250 124 116 46 112 0
243 255 156 245 40 2 245 0 128 120 155 249 123 115 117 109 160
244 249 123 115 117 109 122 67 128 63 120 3 122 88 122 152 122
245 242 2 161 121 219 122 255 155 249 124 116 101 115 116 160 249
246 124 116 101 115 116 245 226 0 242 3 161 253 128 123 52 46
247 56 255 242 4 161 253 128 123 48 46 53 255 159 123 245 30
248 255 122 122 255 159 123 96 122 120 255 159 123 98 122 120 255
249 159 123 116 122 120 255 159 123 118 122 120 255 159 123 100 128
250 120 255 159 123 108 128 120 255 67 140 69 121 113 116 68 73
251 116 69 123 81 122 69 126 3 122 113 118 68 57 242 3 72
252 128 58 108 112 128 68 58 108 72 128 57 242 4 72 128 44
253 128 58 100 112 128 68 69 121 113 98 68 69 245 122 0 113
254 96 68 69 121 113 118 182 73 118 42 122 81 122 58 245 32
255 255 73 118 57 242 2 94 122 73 118 69 220 10 123 54 118
256 18 122 183 67 147 73 116 69 147 3 122 104 120 68 73 98
257 73 120 111 130 68 58 100 72 136 2 128 73 120 4 122 112
258 128 68 58 245 32 255 73 116 57 242 2 59 122 65 120 20
259 249 123 115 117 109 8 124 64 122 113 118 184 67 151 73 118
260 128 125 73 116 65 120 3 122 113 116 41 118 18 124 185 67
261 152 73 120 113 245 30 255 73 98 73 245 30 255 111 130 58
262 100 72 136 2 128 73 245 30 255 4 122 112 128 69 120 104
263 245 30 255 67 154 57 142 73 116 20 249 124 95 119 114 105
264 8 124 57 142 73 118 69 126 20 249 124 95 119 115 105 8
265 126 57 142 58 108 72 128 69 129 69 123 20 249 124 95 119
266 114 102 8 134 57 142 73 98 20 249 124 95 119 114 98 8
267 124 57 142 20 249 124 95 119 108 110 8 122 88 120 152 245
268 226 0 155 249 125 95 109 97 105 110 160 249 125 95 109 97
269 105 110 120 242 6 151 122 119 142 255 242 5 161 253 128 125
270 49 53 46 57 54 255 50 242 1 57 242 6 57 120 20 249
271 124 95 105 110 105 8 124 67 157 57 242 5 72 128 57 122
272 112 128 68 69 219 110 120 68 57 130 20 249 124 116 101 115
273 116 8 122 69 120 20 249 124 95 104 108 116 8 122 152 120
274 159 124 160 255 159 125 255