app.exam.nr 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. .BP
  2. .AP "AN EXAMPLE PROGRAM"
  3. .DS B
  4. .ta 4n 8n 12n 16n 20n
  5. 1 program example(output);
  6. 2 {This program just demonstrates typical EM code.}
  7. 3 type rec = record r1: integer; r2:real; r3: boolean end;
  8. 4 var mi: integer; mx:real; r:rec;
  9. 5
  10. 6 function sum(a,b:integer):integer;
  11. 7 begin
  12. 8 sum := a + b
  13. 9 end;
  14. 10
  15. 11 procedure test(var r: rec);
  16. 12 label 1;
  17. 13 var i,j: integer;
  18. 14 x,y: real;
  19. 15 b: boolean;
  20. 16 c: char;
  21. 17 a: array[1..100] of integer;
  22. 18
  23. 19 begin
  24. 20 j := 1;
  25. 21 i := 3 * j + 6;
  26. 22 x := 4.8;
  27. 23 y := x/0.5;
  28. 24 b := true;
  29. 25 c := 'z';
  30. 26 for i:= 1 to 100 do a[i] := i * i;
  31. 27 r.r1 := j+27;
  32. 28 r.r3 := b;
  33. 29 r.r2 := x+y;
  34. 30 i := sum(r.r1, a[j]);
  35. 31 while i > 0 do begin j := j + r.r1; i := i - 1 end;
  36. 32 with r do begin r3 := b; r2 := x+y; r1 := 0 end;
  37. 33 goto 1;
  38. 34 1: writeln(j, i:6, x:9:3, b)
  39. 35 end; {test}
  40. 36 begin {main program}
  41. 37 mx := 15.96;
  42. 38 mi := 99;
  43. 39 test(r)
  44. 40 end.
  45. .DE 0
  46. .BP
  47. The EM code as produced by the Pascal-VU compiler is given below. Comments
  48. have been added manually. Note that this code has already been optimized.
  49. .DS B
  50. .ta 1n 24n
  51. mes 2,2,2 ; wordsize 2, pointersize 2
  52. .1
  53. rom 't.p\e000' ; the name of the source file
  54. hol 552,\-32768,0 ; externals and buf occupy 552 bytes
  55. exp $sum ; sum can be called from other modules
  56. pro $sum,2 ; procedure sum ; 2 bytes local storage
  57. lin 8 ; code from source line 8
  58. ldl 0 ; load two locals ( a and b )
  59. adi 2 ; add them
  60. ret 2 ; return the result
  61. end 2 ; end of procedure ( still two bytes local storage )
  62. .2
  63. rom 1,99,2 ; descriptor of array a[]
  64. exp $test ; the compiler exports all level 0 procedures
  65. pro $test,226 ; procedure test, 226 bytes local storage
  66. .3
  67. rom 4.8F8 ; assemble Floating point 4.8 (8 bytes) in
  68. .4 ; global storage
  69. rom 0.5F8 ; same for 0.5
  70. mes 3,\-226,2,2 ; compiler temporary not referenced by address
  71. mes 3,\-24,2,0 ; the same is true for i, j, b and c in test
  72. mes 3,\-22,2,0
  73. mes 3,\-4,2,0
  74. mes 3,\-2,2,0
  75. mes 3,\-20,8,0 ; and for x and y
  76. mes 3,\-12,8,0
  77. lin 20 ; maintain source line number
  78. loc 1
  79. stl \-4 ; j := 1
  80. lni ; lin 21 prior to optimization
  81. lol \-4
  82. loc 3
  83. mli 2
  84. loc 6
  85. adi 2
  86. stl \-2 ; i := 3 * j + 6
  87. lni ; lin 22 prior to optimization
  88. lae .3
  89. loi 8
  90. lal \-12
  91. sti 8 ; x := 4.8
  92. lni ; lin 23 prior to optimization
  93. lal \-12
  94. loi 8
  95. lae .4
  96. loi 8
  97. dvf 8
  98. lal \-20
  99. sti 8 ; y := x / 0.5
  100. lni ; lin 24 prior to optimization
  101. loc 1
  102. stl \-22 ; b := true
  103. lni ; lin 25 prior to optimization
  104. loc 122
  105. stl \-24 ; c := 'z'
  106. lni ; lin 26 prior to optimization
  107. loc 1
  108. stl \-2 ; for i:= 1
  109. 2
  110. lol \-2
  111. dup 2
  112. mli 2 ; i*i
  113. lal \-224
  114. lol \-2
  115. lae .2
  116. sar 2 ; a[i] :=
  117. lol \-2
  118. loc 100
  119. beq *3 ; to 100 do
  120. inl \-2 ; increment i and loop
  121. bra *2
  122. 3
  123. lin 27
  124. lol \-4
  125. loc 27
  126. adi 2 ; j + 27
  127. sil 0 ; r.r1 :=
  128. lni ; lin 28 prior to optimization
  129. lol \-22 ; b
  130. lol 0
  131. stf 10 ; r.r3 :=
  132. lni ; lin 29 prior to optimization
  133. lal \-20
  134. loi 16
  135. adf 8 ; x + y
  136. lol 0
  137. adp 2
  138. sti 8 ; r.r2 :=
  139. lni ; lin 23 prior to optimization
  140. lal \-224
  141. lol \-4
  142. lae .2
  143. lar 2 ; a[j]
  144. lil 0 ; r.r1
  145. cal $sum ; call now
  146. asp 4 ; remove parameters from stack
  147. lfr 2 ; get function result
  148. stl \-2 ; i :=
  149. 4
  150. lin 31
  151. lol \-2
  152. zle *5 ; while i > 0 do
  153. lol \-4
  154. lil 0
  155. adi 2
  156. stl \-4 ; j := j + r.r1
  157. del \-2 ; i := i - 1
  158. bra *4 ; loop
  159. 5
  160. lin 32
  161. lol 0
  162. stl \-226 ; make copy of address of r
  163. lol \-22
  164. lol \-226
  165. stf 10 ; r3 := b
  166. lal \-20
  167. loi 16
  168. adf 8
  169. lol \-226
  170. adp 2
  171. sti 8 ; r2 := x + y
  172. loc 0
  173. sil \-226 ; r1 := 0
  174. lin 34 ; note the abscence of the unnecesary jump
  175. lae 22 ; address of output structure
  176. lol \-4
  177. cal $_wri ; write integer with default width
  178. asp 4 ; pop parameters
  179. lae 22
  180. lol \-2
  181. loc 6
  182. cal $_wsi ; write integer width 6
  183. asp 6
  184. lae 22
  185. lal \-12
  186. loi 8
  187. loc 9
  188. loc 3
  189. cal $_wrf ; write fixed format real, width 9, precision 3
  190. asp 14
  191. lae 22
  192. lol \-22
  193. cal $_wrb ; write boolean, default width
  194. asp 4
  195. lae 22
  196. cal $_wln ; writeln
  197. asp 2
  198. ret 0 ; return, no result
  199. end 226
  200. exp $_main
  201. pro $_main,0 ; main program
  202. .6
  203. con 2,\-1,22 ; description of external files
  204. .5
  205. rom 15.96F8
  206. fil .1 ; maintain source file name
  207. lae .6 ; description of external files
  208. lae 0 ; base of hol area to relocate buffer addresses
  209. cal $_ini ; initialize files, etc...
  210. asp 4
  211. lin 37
  212. lae .5
  213. loi 8
  214. lae 2
  215. sti 8 ; mx := 15.96
  216. lni ; lin 38 prior to optimization
  217. loc 99
  218. ste 0 ; mi := 99
  219. lni ; lin 39 prior to optimization
  220. lae 10 ; address of r
  221. cal $test
  222. asp 2
  223. loc 0 ; normal exit
  224. cal $_hlt ; cleanup and finish
  225. asp 2
  226. end 0
  227. mes 5 ; reals were used
  228. .DE 0
  229. The compact code corresponding to the above program is listed below.
  230. Read it horizontally, line by line, not column by column.
  231. Each number represents a byte of compact code, printed in decimal.
  232. The first two bytes form the magic word.
  233. .N 1
  234. .IS 3
  235. .Dr 33
  236. 173 0 159 122 122 122 255 242 1 161 250 124 116 46 112 0
  237. 255 156 245 40 2 245 0 128 120 155 249 123 115 117 109 160
  238. 249 123 115 117 109 122 67 128 63 120 3 122 88 122 152 122
  239. 242 2 161 121 219 122 255 155 249 124 116 101 115 116 160 249
  240. 124 116 101 115 116 245 226 0 242 3 161 253 128 123 52 46
  241. 56 255 242 4 161 253 128 123 48 46 53 255 159 123 245 30
  242. 255 122 122 255 159 123 96 122 120 255 159 123 98 122 120 255
  243. 159 123 116 122 120 255 159 123 118 122 120 255 159 123 100 128
  244. 120 255 159 123 108 128 120 255 67 140 69 121 113 116 68 73
  245. 116 69 123 81 122 69 126 3 122 113 118 68 57 242 3 72
  246. 128 58 108 112 128 68 58 108 72 128 57 242 4 72 128 44
  247. 128 58 100 112 128 68 69 121 113 98 68 69 245 122 0 113
  248. 96 68 69 121 113 118 182 73 118 42 122 81 122 58 245 32
  249. 255 73 118 57 242 2 94 122 73 118 69 220 10 123 54 118
  250. 18 122 183 67 147 73 116 69 147 3 122 104 120 68 73 98
  251. 73 120 111 130 68 58 100 72 136 2 128 73 120 4 122 112
  252. 128 68 58 245 32 255 73 116 57 242 2 59 122 65 120 20
  253. 249 123 115 117 109 8 124 64 122 113 118 184 67 151 73 118
  254. 128 125 73 116 65 120 3 122 113 116 41 118 18 124 185 67
  255. 152 73 120 113 245 30 255 73 98 73 245 30 255 111 130 58
  256. 100 72 136 2 128 73 245 30 255 4 122 112 128 69 120 104
  257. 245 30 255 67 154 57 142 73 116 20 249 124 95 119 114 105
  258. 8 124 57 142 73 118 69 126 20 249 124 95 119 115 105 8
  259. 126 57 142 58 108 72 128 69 129 69 123 20 249 124 95 119
  260. 114 102 8 134 57 142 73 98 20 249 124 95 119 114 98 8
  261. 124 57 142 20 249 124 95 119 108 110 8 122 88 120 152 245
  262. 226 0 155 249 125 95 109 97 105 110 160 249 125 95 109 97
  263. 105 110 120 242 6 151 122 119 142 255 242 5 161 253 128 125
  264. 49 53 46 57 54 255 50 242 1 57 242 6 57 120 20 249
  265. 124 95 105 110 105 8 124 67 157 57 242 5 72 128 57 122
  266. 112 128 68 69 219 110 120 68 57 130 20 249 124 116 101 115
  267. 116 8 122 69 120 20 249 124 95 104 108 116 8 122 152 120
  268. 159 124 160 255 159 125 255
  269. .De
  270. .IE