app.nr 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. .BP
  2. .AP "EM INTERPRETER"
  3. .nf
  4. .ta 8 16 24 32 40 48 56 64 72 80
  5. .so em.i
  6. .fi
  7. .BP
  8. .AP "EM CODE TABLES"
  9. The following table is used by the assembler for EM machine
  10. language.
  11. It specifies the opcodes used for each instruction and
  12. how arguments are mapped to machine language arguments.
  13. The table is presented in three columns,
  14. each line in each column contains three or four fields.
  15. Each line describes a range of interpreter opcodes by
  16. specifying for which instruction the range is used, the type of the
  17. opcodes (mini, shortie, etc..) and range for the instruction
  18. argument.
  19. .A
  20. The first field on each line gives the EM instruction mnemonic,
  21. the second field gives some flags.
  22. If the opcodes are minis or shorties the third field specifies
  23. how many minis/shorties are used.
  24. The last field gives the number of the (first) interpreter
  25. opcode.
  26. .N 1
  27. Flags :
  28. .IS 3
  29. .N 1
  30. Opcode type, only one of the following may be specified.
  31. .PS - 5 " "
  32. .PT -
  33. opcode without argument
  34. .PT m
  35. mini
  36. .PT s
  37. shortie
  38. .PT 2
  39. opcode with 2-byte signed argument
  40. .PT 4
  41. opcode with 4-byte signed argument
  42. .PT 8
  43. opcode with 8-byte signed argument
  44. .PE
  45. Secondary (escaped) opcodes.
  46. .PS - 5 " "
  47. .PT e
  48. The opcode thus marked is in the secondary opcode group instead
  49. of the primary
  50. .PE
  51. restrictions on arguments
  52. .PS - 5 " "
  53. .PT N
  54. Negative arguments only
  55. .PT P
  56. Positive and zero arguments only
  57. .PE
  58. mapping of arguments
  59. .PS - 5 " "
  60. .PT w
  61. argument must be divisible by the wordsize and is divided by the
  62. wordsize before use as opcode argument.
  63. .PT o
  64. argument ( possibly after division ) must be >= 1 and is
  65. decremented before use as opcode argument
  66. .PE
  67. .IE
  68. If the opcode type is 2,4 or 8 the resulting argument is used as
  69. opcode argument (least significant byte first).
  70. .N
  71. If the opcode type is mini, the argument is added
  72. to the first opcode - if in range - .
  73. If the argument is negative, the absolute value minus one is
  74. used in the algorithm above.
  75. .N
  76. For shorties with positive arguments the first opcode is used
  77. for arguments in the range 0..255, the second for the range
  78. 256..511, etc..
  79. For shorties with negative arguments the first opcode is used
  80. for arguments in the range -1..-256, the second for the range
  81. -257..-512, etc..
  82. The byte following the opcode contains the least significant
  83. byte of the argument.
  84. First some examples of these specifications.
  85. .PS - 5
  86. .PT "aar mwPo 1 34"
  87. Indicates that opcode 34 is used as a mini for Positive
  88. instruction arguments only.
  89. The w and o indicate division and decrementing of the
  90. instruction argument.
  91. Because the resulting argument must be zero ( only opcode 34 may be used
  92. ), this mini can only be used for instruction argument 2.
  93. Conclusion: opcode 34 is for "AAR 2".
  94. .PT "adp sP 1 41"
  95. Opcode 41 is used as shortie for ADP with arguments in the range
  96. 0..255.
  97. .PT "bra sN 2 60"
  98. Opcode 60 is used as shortie for BRA with arguments -1..-256,
  99. 61 is used for arguments -257..-512.
  100. .PT "zer e- 145"
  101. Escaped opcode 145 is used for ZER.
  102. .PE
  103. The interpreter opcode table:
  104. .N 1
  105. .IS 3
  106. .DS B
  107. .so itables
  108. .DE 0
  109. .IE
  110. .P
  111. The table above results in the following dispatch tables.
  112. Dispatch tables are used by interpreters to jump to the
  113. routines implementing the EM instructions, indexed by the next opcode.
  114. Each line of the dispatch tables gives the routine names
  115. of eight consecutive opcodes, preceded by the first opcode number
  116. on that line.
  117. Routine names consist of an EM mnemonic followed by a suffix.
  118. The suffices show the encoding used for each opcode.
  119. .N
  120. The following suffices exist:
  121. .N 1
  122. .VS 1 0
  123. .IS 4
  124. .PS - 11
  125. .PT .z
  126. no arguments
  127. .PT .l
  128. 16-bit argument
  129. .PT .lw
  130. 16-bit argument divided by the wordsize
  131. .PT .p
  132. positive 16-bit argument
  133. .PT .pw
  134. positive 16-bit argument divided by the wordsize
  135. .PT .n
  136. negative 16-bit argument
  137. .PT .nw
  138. negative 16-bit argument divided by the wordsize
  139. .PT .s<num>
  140. shortie with <num> as high order argument byte
  141. .PT .sw<num>
  142. shortie with argument divided by the wordsize
  143. .PT .<num>
  144. mini with <num> as argument
  145. .PT .<num>W
  146. mini with <num>*wordsize as argument
  147. .PE 3
  148. <num> is a possibly negative integer.
  149. .VS 1 1
  150. .IE
  151. The dispatch table for the 256 primary opcodes:
  152. .DS B
  153. 0 loc.0 loc.1 loc.2 loc.3 loc.4 loc.5 loc.6 loc.7
  154. 8 loc.8 loc.9 loc.10 loc.11 loc.12 loc.13 loc.14 loc.15
  155. 16 loc.16 loc.17 loc.18 loc.19 loc.20 loc.21 loc.22 loc.23
  156. 24 loc.24 loc.25 loc.26 loc.27 loc.28 loc.29 loc.30 loc.31
  157. 32 loc.32 loc.33 aar.1W adf.s0 adi.1W adi.2W adp.l adp.1
  158. 40 adp.2 adp.s0 adp.s-1 ads.1W and.1W asp.1W asp.2W asp.3W
  159. 48 asp.4W asp.5W asp.w0 beq.l beq.s0 bge.s0 bgt.s0 ble.s0
  160. 56 blm.s0 blt.s0 bne.s0 bra.l bra.s-1 bra.s-2 bra.s0 bra.s1
  161. 64 cal.1 cal.2 cal.3 cal.4 cal.5 cal.6 cal.7 cal.8
  162. 72 cal.9 cal.10 cal.11 cal.12 cal.13 cal.14 cal.15 cal.16
  163. 80 cal.17 cal.18 cal.19 cal.20 cal.21 cal.22 cal.23 cal.24
  164. 88 cal.25 cal.26 cal.27 cal.28 cal.s0 cff.z cif.z cii.z
  165. 96 cmf.s0 cmi.1W cmi.2W cmp.z cms.s0 csa.1W csb.1W dec.z
  166. 104 dee.w0 del.w-1 dup.1W dvf.s0 dvi.1W fil.l inc.z ine.lw
  167. 112 ine.w0 inl.-1W inl.-2W inl.-3W inl.w-1 inn.s0 ior.1W ior.s0
  168. 120 lae.l lae.w0 lae.w1 lae.w2 lae.w3 lae.w4 lae.w5 lae.w6
  169. 128 lal.p lal.n lal.0 lal.-1 lal.w0 lal.w-1 lal.w-2 lar.W
  170. 136 ldc.0 lde.lw lde.w0 ldl.0 ldl.w-1 lfr.1W lfr.2W lfr.s0
  171. 144 lil.w-1 lil.w0 lil.0 lil.1W lin.l lin.s0 lni.z loc.l
  172. 152 loc.-1 loc.s0 loc.s-1 loe.lw loe.w0 loe.w1 loe.w2 loe.w3
  173. 160 loe.w4 lof.l lof.1W lof.2W lof.3W lof.4W lof.s0 loi.l
  174. 168 loi.1 loi.1W loi.2W loi.3W loi.4W loi.s0 lol.pw lol.nw
  175. 176 lol.0 lol.1W lol.2W lol.3W lol.-1W lol.-2W lol.-3W lol.-4W
  176. 184 lol.-5W lol.-6W lol.-7W lol.-8W lol.w0 lol.w-1 lxa.1 lxl.1
  177. 192 lxl.2 mlf.s0 mli.1W mli.2W rck.1W ret.0 ret.1W ret.s0
  178. 200 rmi.1W sar.1W sbf.s0 sbi.1W sbi.2W sdl.w-1 set.s0 sil.w-1
  179. 208 sil.w0 sli.1W ste.lw ste.w0 ste.w1 ste.w2 stf.l stf.W
  180. 216 stf.2W stf.s0 sti.1 sti.1W sti.2W sti.3W sti.4W sti.s0
  181. 224 stl.pw stl.nw stl.0 stl.1W stl.-1W stl.-2W stl.-3W stl.-4W
  182. 232 stl.-5W stl.w-1 teq.z tgt.z tlt.z tne.z zeq.l zeq.s0
  183. 240 zeq.s1 zer.s0 zge.s0 zgt.s0 zle.s0 zlt.s0 zne.s0 zne.s-1
  184. 248 zre.lw zre.w0 zrl.-1W zrl.-2W zrl.w-1 zrl.nw escape1 escape2
  185. .DE 2
  186. The list of secondary opcodes (escape1):
  187. .N 1
  188. .DS B
  189. 0 aar.l aar.z adf.l adf.z adi.l adi.z ads.l ads.z
  190. 8 adu.l adu.z and.l and.z asp.lw ass.l ass.z bge.l
  191. 16 bgt.l ble.l blm.l bls.l bls.z blt.l bne.l cai.z
  192. 24 cal.l cfi.z cfu.z ciu.z cmf.l cmf.z cmi.l cmi.z
  193. 32 cms.l cms.z cmu.l cmu.z com.l com.z csa.l csa.z
  194. 40 csb.l csb.z cuf.z cui.z cuu.z dee.lw del.pw del.nw
  195. 48 dup.l dus.l dus.z dvf.l dvf.z dvi.l dvi.z dvu.l
  196. 56 dvu.z fef.l fef.z fif.l fif.z inl.pw inl.nw inn.l
  197. 64 inn.z ior.l ior.z lar.l lar.z ldc.l ldf.l ldl.pw
  198. 72 ldl.nw lfr.l lil.pw lil.nw lim.z los.l los.z lor.s0
  199. 80 lpi.l lxa.l lxl.l mlf.l mlf.z mli.l mli.z mlu.l
  200. 88 mlu.z mon.z ngf.l ngf.z ngi.l ngi.z nop.z rck.l
  201. 96 rck.z ret.l rmi.l rmi.z rmu.l rmu.z rol.l rol.z
  202. 104 ror.l ror.z rtt.z sar.l sar.z sbf.l sbf.z sbi.l
  203. 112 sbi.z sbs.l sbs.z sbu.l sbu.z sde.l sdf.l sdl.pw
  204. 120 sdl.nw set.l set.z sig.z sil.pw sil.nw sim.z sli.l
  205. 128 sli.z slu.l slu.z sri.l sri.z sru.l sru.z sti.l
  206. 136 sts.l sts.z str.s0 tge.z tle.z trp.z xor.l xor.z
  207. 144 zer.l zer.z zge.l zgt.l zle.l zlt.l zne.l zrf.l
  208. 152 zrf.z zrl.pw dch.z exg.s0 exg.l exg.z lpb.z gto.l
  209. .DE 2
  210. Finally, the list of opcodes with four byte arguments (escape2).
  211. .DS
  212. 0 loc
  213. .DE 0
  214. .BP
  215. .AP "AN EXAMPLE PROGRAM"
  216. .DS B
  217. 1 program example(output);
  218. 2 {This program just demonstrates typical EM code.}
  219. 3 type rec = record r1: integer; r2:real; r3: boolean end;
  220. 4 var mi: integer; mx:real; r:rec;
  221. 5
  222. 6 function sum(a,b:integer):integer;
  223. 7 begin
  224. 8 sum := a + b
  225. 9 end;
  226. 10
  227. 11 procedure test(var r: rec);
  228. 12 label 1;
  229. 13 var i,j: integer;
  230. 14 x,y: real;
  231. 15 b: boolean;
  232. 16 c: char;
  233. 17 a: array[1..100] of integer;
  234. 18
  235. 19 begin
  236. 20 j := 1;
  237. 21 i := 3 * j + 6;
  238. 22 x := 4.8;
  239. 23 y := x/0.5;
  240. 24 b := true;
  241. 25 c := 'z';
  242. 26 for i:= 1 to 100 do a[i] := i * i;
  243. 27 r.r1 := j+27;
  244. 28 r.r3 := b;
  245. 29 r.r2 := x+y;
  246. 30 i := sum(r.r1, a[j]);
  247. 31 while i > 0 do begin j := j + r.r1; i := i - 1 end;
  248. 32 with r do begin r3 := b; r2 := x+y; r1 := 0 end;
  249. 33 goto 1;
  250. 34 1: writeln(j, i:6, x:9:3, b)
  251. 35 end; {test}
  252. 36 begin {main program}
  253. 37 mx := 15.96;
  254. 38 mi := 99;
  255. 39 test(r)
  256. 40 end.
  257. .DE 0
  258. .BP
  259. The EM code as produced by the Pascal-VU compiler is given below. Comments
  260. have been added manually. Note that this code has already been optimized.
  261. .DS B
  262. mes 2,2,2 ; wordsize 2, pointersize 2
  263. .1
  264. rom 't.p\e000' ; the name of the source file
  265. hol 552,-32768,0 ; externals and buf occupy 552 bytes
  266. exp $sum ; sum can be called from other modules
  267. pro $sum,2 ; procedure sum; 2 bytes local storage
  268. lin 8 ; code from source line 8
  269. ldl 0 ; load two locals ( a and b )
  270. adi 2 ; add them
  271. ret 2 ; return the result
  272. end 2 ; end of procedure ( still two bytes local storage )
  273. .2
  274. rom 1,99,2 ; descriptor of array a[]
  275. exp $test ; the compiler exports all level 0 procedures
  276. pro $test,226 ; procedure test, 226 bytes local storage
  277. .3
  278. rom 4.8F8 ; assemble Floating point 4.8 (8 bytes) in
  279. .4 ; global storage
  280. rom 0.5F8 ; same for 0.5
  281. mes 3,-226,2,2 ; compiler temporary not referenced by address
  282. mes 3,-24,2,0 ; the same is true for i, j, b and c in test
  283. mes 3,-22,2,0
  284. mes 3,-4,2,0
  285. mes 3,-2,2,0
  286. mes 3,-20,8,0 ; and for x and y
  287. mes 3,-12,8,0
  288. lin 20 ; maintain source line number
  289. loc 1
  290. stl -4 ; j := 1
  291. lni ; lin 21 prior to optimization
  292. lol -4
  293. loc 3
  294. mli 2
  295. loc 6
  296. adi 2
  297. stl -2 ; i := 3 * j + 6
  298. lni ; lin 22 prior to optimization
  299. lae .3
  300. loi 8
  301. lal -12
  302. sti 8 ; x := 4.8
  303. lni ; lin 23 prior to optimization
  304. lal -12
  305. loi 8
  306. lae .4
  307. loi 8
  308. dvf 8
  309. lal -20
  310. sti 8 ; y := x / 0.5
  311. lni ; lin 24 prior to optimization
  312. loc 1
  313. stl -22 ; b := true
  314. lni ; lin 25 prior to optimization
  315. loc 122
  316. stl -24 ; c := 'z'
  317. lni ; lin 26 prior to optimization
  318. loc 1
  319. stl -2 ; for i:= 1
  320. 2
  321. lol -2
  322. dup 2
  323. mli 2 ; i*i
  324. lal -224
  325. lol -2
  326. lae .2
  327. sar 2 ; a[i] :=
  328. lol -2
  329. loc 100
  330. beq *3 ; to 100 do
  331. inl -2 ; increment i and loop
  332. bra *2
  333. 3
  334. lin 27
  335. lol -4
  336. loc 27
  337. adi 2 ; j + 27
  338. sil 0 ; r.r1 :=
  339. lni ; lin 28 prior to optimization
  340. lol -22 ; b
  341. lol 0
  342. stf 10 ; r.r3 :=
  343. lni ; lin 29 prior to optimization
  344. lal -20
  345. loi 16
  346. adf 8 ; x + y
  347. lol 0
  348. adp 2
  349. sti 8 ; r.r2 :=
  350. lni ; lin 23 prior to optimization
  351. lal -224
  352. lol -4
  353. lae .2
  354. lar 2 ; a[j]
  355. lil 0 ; r.r1
  356. cal $sum ; call now
  357. asp 4 ; remove parameters from stack
  358. lfr 2 ; get function result
  359. stl -2 ; i :=
  360. 4
  361. lin 31
  362. lol -2
  363. zle *5 ; while i > 0 do
  364. lol -4
  365. lil 0
  366. adi 2
  367. stl -4 ; j := j + r.r1
  368. del -2 ; i := i - 1
  369. bra *4 ; loop
  370. 5
  371. lin 32
  372. lol 0
  373. stl -226 ; make copy of address of r
  374. lol -22
  375. lol -226
  376. stf 10 ; r3 := b
  377. lal -20
  378. loi 16
  379. adf 8
  380. lol -226
  381. adp 2
  382. sti 8 ; r2 := x + y
  383. loc 0
  384. sil -226 ; r1 := 0
  385. lin 34 ; note the abscence of the unnecesary jump
  386. lae 22 ; address of output structure
  387. lol -4
  388. cal $_wri ; write integer with default width
  389. asp 4 ; pop parameters
  390. lae 22
  391. lol -2
  392. loc 6
  393. cal $_wsi ; write integer width 6
  394. asp 6
  395. lae 22
  396. lal -12
  397. loi 8
  398. loc 9
  399. loc 3
  400. cal $_wrf ; write fixed format real, width 9, precision 3
  401. asp 14
  402. lae 22
  403. lol -22
  404. cal $_wrb ; write boolean, default width
  405. asp 4
  406. lae 22
  407. cal $_wln ; writeln
  408. asp 2
  409. ret 0 ; return, no result
  410. end 226
  411. exp $_main
  412. pro $_main,0 ; main program
  413. .6
  414. con 2,-1,22 ; description of external files
  415. .5
  416. rom 15.96F8
  417. fil .1 ; maintain source file name
  418. lae .6 ; description of external files
  419. lae 0 ; base of hol area to relocate buffer addresses
  420. cal $_ini ; initialize files, etc...
  421. asp 4
  422. lin 37
  423. lae .5
  424. loi 8
  425. lae 2
  426. sti 8 ; mx := 15.96
  427. lni ; lin 38 prior to optimization
  428. loc 99
  429. ste 0 ; mi := 99
  430. lni ; lin 39 prior to optimization
  431. lae 10 ; address of r
  432. cal $test
  433. asp 2
  434. loc 0 ; normal exit
  435. cal $_hlt ; cleanup and finish
  436. asp 2
  437. end 0
  438. mes 5 ; reals were used
  439. .DE 0
  440. The compact code corresponding to the above program is listed below.
  441. Read it horizontally, line by line, not column by column.
  442. Each number represents a byte of compact code, printed in decimal.
  443. The first two bytes form the magic word.
  444. .N 1
  445. .IS 3
  446. .DS B
  447. 173 0 159 122 122 122 255 242 1 161 250 124 116 46 112 0
  448. 255 156 245 40 2 245 0 128 120 155 249 123 115 117 109 160
  449. 249 123 115 117 109 122 67 128 63 120 3 122 88 122 152 122
  450. 242 2 161 121 219 122 255 155 249 124 116 101 115 116 160 249
  451. 124 116 101 115 116 245 226 0 242 3 161 253 128 123 52 46
  452. 56 255 242 4 161 253 128 123 48 46 53 255 159 123 245 30
  453. 255 122 122 255 159 123 96 122 120 255 159 123 98 122 120 255
  454. 159 123 116 122 120 255 159 123 118 122 120 255 159 123 100 128
  455. 120 255 159 123 108 128 120 255 67 140 69 121 113 116 68 73
  456. 116 69 123 81 122 69 126 3 122 113 118 68 57 242 3 72
  457. 128 58 108 112 128 68 58 108 72 128 57 242 4 72 128 44
  458. 128 58 100 112 128 68 69 121 113 98 68 69 245 122 0 113
  459. 96 68 69 121 113 118 182 73 118 42 122 81 122 58 245 32
  460. 255 73 118 57 242 2 94 122 73 118 69 220 10 123 54 118
  461. 18 122 183 67 147 73 116 69 147 3 122 104 120 68 73 98
  462. 73 120 111 130 68 58 100 72 136 2 128 73 120 4 122 112
  463. 128 68 58 245 32 255 73 116 57 242 2 59 122 65 120 20
  464. 249 123 115 117 109 8 124 64 122 113 118 184 67 151 73 118
  465. 128 125 73 116 65 120 3 122 113 116 41 118 18 124 185 67
  466. 152 73 120 113 245 30 255 73 98 73 245 30 255 111 130 58
  467. 100 72 136 2 128 73 245 30 255 4 122 112 128 69 120 104
  468. 245 30 255 67 154 57 142 73 116 20 249 124 95 119 114 105
  469. 8 124 57 142 73 118 69 126 20 249 124 95 119 115 105 8
  470. 126 57 142 58 108 72 128 69 129 69 123 20 249 124 95 119
  471. 114 102 8 134 57 142 73 98 20 249 124 95 119 114 98 8
  472. 124 57 142 20 249 124 95 119 108 110 8 122 88 120 152 245
  473. 226 0 155 249 125 95 109 97 105 110 160 249 125 95 109 97
  474. 105 110 120 242 6 151 122 119 142 255 242 5 161 253 128 125
  475. 49 53 46 57 54 255 50 242 1 57 242 6 57 120 20 249
  476. 124 95 105 110 105 8 124 67 157 57 242 5 72 128 57 122
  477. 112 128 68 69 219 110 120 68 57 130 20 249 124 116 101 115
  478. 116 8 122 69 120 20 249 124 95 104 108 116 8 122 152 120
  479. 159 124 160 255 159 125 255
  480. .DE 0
  481. .IE
  482. .MS T A 0
  483. .ME
  484. .BP
  485. .MS B A 0
  486. .ME
  487. .CT