em.i 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. .bp
  2. .AP "EM INTERPRETER"
  3. .nf
  4. .ft CW
  5. .lg 0
  6. .nr x \w' '
  7. .ta \nxu +\nxu +\nxu +\nxu +\nxu +\nxu +\nxu +\nxu +\nxu +\nxu
  8. { This is an interpreter for EM. It serves as the official machine
  9. definition. This interpreter must run on a machine which supports
  10. arithmetic with words and memory offsets.
  11. Certain aspects of the definition are over specified. In particular:
  12. 1. The representation of an address on the stack need not be the
  13. numerical value of the memory location.
  14. 2. The state of the stack is not defined after a trap has aborted
  15. an instruction in the middle. For example, it is officially un-
  16. defined whether the second operand of an ADD instruction has
  17. been popped or not if the first one is undefined ( -32768 or
  18. unsigned 32768).
  19. 3. The memory layout is implementation dependent. Only the most
  20. basic checks are performed whenever memory is accessed.
  21. 4. The representation of an integer or set on the stack is not fixed
  22. in bit order.
  23. 5. The format and existence of the procedure descriptors depends on
  24. the implementation.
  25. 6. The result of the compare operators CMI etc. are -1, 0 and 1
  26. here, but other negative and positive values will do and they
  27. need not be the same each time.
  28. 7. The shift count for SHL, SHR, ROL and ROR must be in the range 0
  29. to object size in bits - 1. The effect of a count not in this
  30. range is undefined.
  31. }
  32. .bp
  33. {$i256} {$d+}
  34. program em(tables,prog,input,output);
  35. label 8888,9999;
  36. const
  37. t15 = 32768; { 2**15 }
  38. t15m1 = 32767; { 2**15 -1 }
  39. t16 = 65536; { 2**16 }
  40. t16m1 = 65535; { 2**16 -1 }
  41. t31m1 = 2147483647; { 2**31 -1 }
  42. wsize = 2; { number of bytes in a word }
  43. asize = 2; { number of bytes in an address }
  44. fsize = 4; { number of bytes in a floating point number }
  45. maxret =4; { number of words in the return value area }
  46. signbit = t15; { the power of two indicating the sign bit }
  47. negoff = t16; { the next power of two }
  48. maxsint = t15m1; { the maximum signed integer }
  49. maxuint = t16m1; { the maximum unsigned integer }
  50. maxdbl = t31m1; { the maximum double signed integer }
  51. maxadr = t16m1; { the maximum address }
  52. maxoffs = t15m1; { the maximum offset from an address }
  53. maxbitnr= 15; { the number of the highest bit }
  54. lineadr = 0; { address of the line number }
  55. fileadr = 4; { address of the file name }
  56. maxcode = 8191; { highest byte in code address space }
  57. maxdata = 8191; { highest byte in data address space }
  58. { format of status save area }
  59. statd = 4; { how far is static link from lb }
  60. dynd = 2; { how far is dynamic link from lb }
  61. reta = 0; { how far is the return address from lb }
  62. savsize = 4; { size of save area in bytes }
  63. { procedure descriptor format }
  64. pdlocs = 0; { offset for size of local variables in bytes }
  65. pdbase = asize; { offset for the procedure base }
  66. pdsize = 4; { size of procedure descriptor in bytes = 2*asize }
  67. { header words }
  68. NTEXT = 1;
  69. NDATA = 2;
  70. NPROC = 3;
  71. ENTRY = 4;
  72. NLINE = 5;
  73. SZDATA = 6;
  74. escape1 = 254; { escape to secondary opcodes }
  75. escape2 = 255; { escape to tertiary opcodes }
  76. undef = signbit; { the range of integers is -32767 to +32767 }
  77. { error codes }
  78. EARRAY = 0; ERANGE = 1; ESET = 2; EIOVFL = 3; EFOVFL = 4;
  79. EFUNFL = 5; EIDIVZ = 6; EFDIVZ = 7; EIUND = 8; EFUND = 9;
  80. ECONV = 10; ESTACK = 16; EHEAP = 17; EILLINS = 18; EODDZ = 19;
  81. ECASE = 20; EMEMFLT = 21; EBADPTR = 22; EBADPC = 23; EBADLAE = 24;
  82. EBADMON = 25; EBADLIN = 26; EBADGTO = 27;
  83. .ne 20
  84. .bp
  85. {---------------------------------------------------------------------------}
  86. { Declarations }
  87. {---------------------------------------------------------------------------}
  88. type
  89. bitval= 0..1; { one bit }
  90. bitnr= 0..maxbitnr; { bits in machine words are numbered 0 to 15 }
  91. byte= 0..255; { memory is an array of bytes }
  92. adr= {0..maxadr} long; { the range of addresses }
  93. word= {0..maxuint} long;{ the range of unsigned integers }
  94. offs= -maxoffs..maxoffs; { the range of signed offsets from addresses }
  95. size= 0..maxoffs; { the range of sizes is the positive offsets }
  96. sword= {-signbit..maxsint} long; { the range of signed integers }
  97. full= {-maxuint..maxuint} long; { intermediate results need this range }
  98. double={-maxdbl..maxdbl} long; { double precision range }
  99. bftype= (andf,iorf,xorf); { tells which boolean operator needed }
  100. insclass=(prim,second,tert); { tells which opcode table is in use }
  101. instype=(implic,explic); { does opcode have implicit or explicit operand }
  102. iflags= (mini,short,sbit,wbit,zbit,ibit);
  103. ifset= set of iflags;
  104. mnem = ( NON,
  105. AAR, ADF, ADI, ADP, ADS, ADU,XAND, ASP, ASS, BEQ,
  106. BGE, BGT, BLE, BLM, BLS, BLT, BNE, BRA, CAI, CAL,
  107. CFF, CFI, CFU, CIF, CII, CIU, CMF, CMI, CMP, CMS,
  108. CMU, COM, CSA, CSB, CUF, CUI, CUU, DCH, DEC, DEE,
  109. DEL, DUP, DUS, DVF, DVI, DVU, EXG, FEF, FIF, FIL,
  110. GTO, INC, INE, INL, INN, IOR, LAE, LAL, LAR, LDC,
  111. LDE, LDF, LDL, LFR, LIL, LIM, LIN, LNI, LOC, LOE,
  112. LOF, LOI, LOL, LOR, LOS, LPB, LPI, LXA, LXL, MLF,
  113. MLI, MLU, MON, NGF, NGI, NOP, RCK, RET, RMI, RMU,
  114. ROL, ROR, RTT, SAR, SBF, SBI, SBS, SBU, SDE, SDF,
  115. SDL,XSET, SIG, SIL, SIM, SLI, SLU, SRI, SRU, STE,
  116. STF, STI, STL, STR, STS, TEQ, TGE, TGT, TLE, TLT,
  117. TNE, TRP, XOR, ZEQ, ZER, ZGE, ZGT, ZLE, ZLT, ZNE,
  118. ZRE, ZRF, ZRL);
  119. dispatch = record
  120. iflag: ifset;
  121. instr: mnem;
  122. case instype of
  123. implic: (implicit:sword);
  124. explic: (ilength:byte);
  125. end;
  126. var
  127. code: packed array[0..maxcode] of byte; { code space }
  128. data: packed array[0..maxdata] of byte; { data space }
  129. retarea: array[1..maxret ] of word; { return area }
  130. pc,lb,sp,hp,pd: adr; { internal machine registers }
  131. i: integer; { integer scratch variable }
  132. s,t :word; { scratch variables }
  133. sz:size; { scratch variables }
  134. ss,st: sword; { scratch variables }
  135. k :double; { scratch variables }
  136. j:size; { scratch variable used as index }
  137. a,b:adr; { scratch variable used for addresses }
  138. dt,ds:double; { scratch variables for double precision }
  139. rt,rs,x,y:real; { scratch variables for real }
  140. found:boolean; { scratch }
  141. opcode: byte; { holds the opcode during execution }
  142. iclass: insclass; { true for escaped opcodes }
  143. dispat: array[insclass,byte] of dispatch;
  144. retsize:size; { holds size of last LFR }
  145. insr: mnem; { holds the instruction number }
  146. halted: boolean; { normally false }
  147. exitstatus:word; { parameter of MON 1 }
  148. ignmask:word; { ignore mask for traps }
  149. uerrorproc:adr; { number of user defined error procedure }
  150. intrap:boolean; { Set when executing trap(), to catch recursive calls}
  151. trapval:byte; { Set to number of last trap }
  152. header: array[1..8] of adr;
  153. tables: text; { description of EM instructions }
  154. prog: file of byte; { program and initialized data }
  155. .ne 20
  156. .sp 2
  157. {---------------------------------------------------------------------------}
  158. { Various check routines }
  159. {---------------------------------------------------------------------------}
  160. { Only the most basic checks are performed. These routines are inherently
  161. implementation dependent. }
  162. procedure trap(n:byte); forward;
  163. procedure memadr(a:adr);
  164. begin if (a>maxdata) or ((a<sp) and (a>=hp)) then trap(EMEMFLT) end;
  165. procedure wordadr(a:adr);
  166. begin memadr(a); if (a mod wsize<>0) then trap(EBADPTR) end;
  167. procedure chkadr(a:adr; s:size);
  168. begin memadr(a); memadr(a+s-1); { assumption: size is ok }
  169. if s<wsize
  170. then begin if a mod s<>0 then trap(EBADPTR) end
  171. else if a mod wsize<>0 then trap(EBADPTR)
  172. end;
  173. procedure newpc(a:double);
  174. begin if (a<0) or (a>maxcode) then trap(EBADPC); pc:=a end;
  175. procedure newsp(a:adr);
  176. begin if (a>lb) or (a<hp) or (a mod wsize<>0) then trap(ESTACK); sp:=a end;
  177. procedure newlb(a:adr);
  178. begin if (a<sp) or (a mod wsize<>0) then trap(ESTACK); lb:=a end;
  179. procedure newhp(a:adr);
  180. begin if (a>sp) or (a>maxdata+1) or (a mod wsize<>0)
  181. then trap(EHEAP)
  182. else hp:=a
  183. end;
  184. function argc(a:double):sword;
  185. begin if (a<-signbit) or (a>maxsint) then trap(EILLINS); argc:=a end;
  186. function argd(a:double):double;
  187. begin if (a<-maxdbl) or (a>maxdbl) then trap(EILLINS); argd:=a end;
  188. function argl(a:double):offs;
  189. begin if (a<-maxoffs) or (a>maxoffs) then trap(EILLINS); argl:=a end;
  190. function argg(k:double):adr;
  191. begin if (k<0) or (k>maxadr) then trap(EILLINS); argg:=k end;
  192. function argf(a:double):offs;
  193. begin if (a<-maxoffs) or (a>maxoffs) then trap(EILLINS); argf:=a end;
  194. function argn(a:double):word;
  195. begin if (a<0) or (a>maxuint) then trap(EILLINS); argn:=a end;
  196. function args(a:double):size;
  197. begin if (a<=0) or (a>maxoffs)
  198. then trap(EODDZ)
  199. else if (a mod wsize)<>0 then trap(EODDZ);
  200. args:=a ;
  201. end;
  202. function argz(a:double):size;
  203. begin if (a<0) or (a>maxoffs)
  204. then trap(EODDZ)
  205. else if (a mod wsize)<>0 then trap(EODDZ);
  206. argz:=a ;
  207. end;
  208. function argo(a:double):size;
  209. begin if (a<=0) or (a>maxoffs)
  210. then trap(EODDZ)
  211. else if (a mod wsize<>0) and (wsize mod a<>0) then trap(EODDZ);
  212. argo:=a ;
  213. end;
  214. function argw(a:double):size;
  215. begin if (a<=0) or (a>maxoffs) or (a>maxuint)
  216. then trap(EODDZ)
  217. else if (a mod wsize)<>0 then trap(EODDZ);
  218. argw:=a ;
  219. end;
  220. function argp(a:double):size;
  221. begin if (a<0) or (a>=header[NPROC]) then trap(EILLINS); argp:=a end;
  222. function argr(a:double):word;
  223. begin if (a<0) or (a>2) then trap(EILLINS); argr:=a end;
  224. procedure argwf(s:double);
  225. begin if argw(s)<>fsize then trap(EILLINS) end;
  226. function szindex(s:double):integer;
  227. begin s:=argw(s); if (s mod wsize <> 0) or (s>2*wsize) then trap(EILLINS);
  228. szindex:=s div wsize
  229. end;
  230. function locadr(l:double):adr;
  231. begin l:=argl(l); if l<0 then locadr:=lb+l else locadr:=lb+l+savsize end;
  232. function signwd(w:word):sword;
  233. begin if w = undef then trap(EIUND);
  234. if w >= signbit then signwd:=w-negoff else signwd:=w
  235. end;
  236. function dosign(w:word):sword;
  237. begin if w >= signbit then dosign:=w-negoff else dosign:=w end;
  238. function unsign(w:sword):word;
  239. begin if w<0 then unsign:=w+negoff else unsign:=w end;
  240. function chopw(dw:double):word;
  241. begin chopw:=dw mod negoff end;
  242. function fitsw(w:full;trapno:byte):word;
  243. { checks whether value fits in signed word, returns unsigned representation}
  244. begin
  245. if (w>maxsint) or (w<-signbit) then
  246. begin trap(trapno);
  247. if w<0 then fitsw:=negoff- (-w)mod negoff
  248. else fitsw:=w mod negoff;
  249. end
  250. else fitsw:=unsign(w)
  251. end;
  252. function fitd(w:full):double;
  253. begin
  254. if abs(w) > maxdbl then trap(ECONV);
  255. fitd:=w
  256. end;
  257. .ne 20
  258. .sp 2
  259. {---------------------------------------------------------------------------}
  260. { Memory access routines }
  261. {---------------------------------------------------------------------------}
  262. { memw returns a machine word as an unsigned integer
  263. memb returns a single byte as a positive integer: 0 <= memb <= 255
  264. mems(a,s) fetches an object smaller than a word and returns a word
  265. store(a,v) stores the word v at machine address a
  266. storea(a,v) stores the address v at machine address a
  267. storeb(a,b) stores the byte b at machine address a
  268. stores(a,s,v) stores the s least significant bytes of a word at address a
  269. memi returns an offset from the instruction space
  270. Note that the procedure descriptors are part of instruction space.
  271. nextpc returns the next byte addressed by pc, incrementing pc
  272. lino changes the line number word.
  273. filna changes the pointer to the file name.
  274. All routines check to make sure the address is within range and valid for
  275. the size of the object. If an addressing error is found, a trap occurs.
  276. }
  277. function memw(a:adr):word;
  278. var b:word; i:integer;
  279. begin wordadr(a); b:=0;
  280. for i:=wsize-1 downto 0 do b:=256*b + data[a+i] ;
  281. memw:=b
  282. end;
  283. function memd(a:adr):double; { Always signed }
  284. var b:double; i:integer;
  285. begin wordadr(a); b:=data[a+2*wsize-1];
  286. if b>=128 then b:=b-256;
  287. for i:=2*wsize-2 downto 0 do b:=256*b + data[a+i] ;
  288. memd:=b
  289. end;
  290. function mema(a:adr):adr;
  291. var b:adr; i:integer;
  292. begin wordadr(a); b:=0;
  293. for i:=asize-1 downto 0 do b:=256*b + data[a+i] ;
  294. mema:=b
  295. end;
  296. function mems(a:adr;s:size):word;
  297. var i:integer; b:word;
  298. begin chkadr(a,s); b:=0; for i:=1 to s do b:=b*256+data[a+s-i]; mems:=b end;
  299. function memb(a:adr):byte;
  300. begin memadr(a); memb:=data[a] end;
  301. procedure store(a:adr; x:word);
  302. var i:integer;
  303. begin wordadr(a);
  304. for i:=0 to wsize-1 do
  305. begin data[a+i]:=x mod 256; x:=x div 256 end
  306. end;
  307. procedure storea(a:adr; x:adr);
  308. var i:integer;
  309. begin wordadr(a);
  310. for i:=0 to asize-1 do
  311. begin data[a+i]:=x mod 256; x:=x div 256 end
  312. end;
  313. procedure stores(a:adr;s:size;v:word);
  314. var i:integer;
  315. begin chkadr(a,s);
  316. for i:=0 to s-1 do begin data[a+i]:=v mod 256; v:=v div 256 end;
  317. end;
  318. procedure storeb(a:adr; b:byte);
  319. begin memadr(a); data[a]:=b end;
  320. function memi(a:adr):adr;
  321. var b:adr; i:integer;
  322. begin if (a mod wsize<>0) or (a+asize-1>maxcode) then trap(EBADPTR); b:=0;
  323. for i:=asize-1 downto 0 do b:=256*b + code[a+i] ;
  324. memi:=b
  325. end;
  326. function nextpc:byte;
  327. begin if pc>=pd then trap(EBADPC); nextpc:=code[pc]; newpc(pc+1) end;
  328. procedure lino(w:word);
  329. begin store(lineadr,w) end;
  330. procedure filna(a:adr);
  331. begin storea(fileadr,a) end;
  332. .ne 20
  333. .sp 2
  334. {---------------------------------------------------------------------------}
  335. { Stack Manipulation Routines }
  336. {---------------------------------------------------------------------------}
  337. { push puts a word on the stack
  338. pushsw takes a signed one word integer and pushes it on the stack
  339. pop removes a machine word from the stack and delivers it as a word
  340. popsw removes a machine word from the stack and delivers a signed integer
  341. pusha pushes an address on the stack
  342. popa removes a machine word from the stack and delivers it as an address
  343. pushd pushes a double precision number on the stack
  344. popd removes two machine words and returns a double precision integer
  345. pushr pushes a float (floating point) number on the stack
  346. popr removes several machine words and returns a float number
  347. pushx puts an object of arbitrary size on the stack
  348. popx removes an object of arbitrary size
  349. }
  350. procedure push(x:word);
  351. begin newsp(sp-wsize); store(sp,x) end;
  352. procedure pushsw(x:sword);
  353. begin newsp(sp-wsize); store(sp,unsign(x)) end;
  354. function pop:word;
  355. begin pop:=memw(sp); newsp(sp+wsize) end;
  356. function popsw:sword;
  357. begin popsw:=signwd(pop) end;
  358. procedure pusha(x:adr);
  359. begin newsp(sp-asize); storea(sp,x) end;
  360. function popa:adr;
  361. begin popa:=mema(sp); newsp(sp+asize) end;
  362. procedure pushd(y:double);
  363. begin { push double integer onto the stack } newsp(sp-2*wsize) end;
  364. function popd:double;
  365. begin { pop double integer from the stack } newsp(sp+2*wsize); popd:=0 end;
  366. procedure pushr(z:real);
  367. begin { Push a float onto the stack } newsp(sp-fsize) end;
  368. function popr:real;
  369. begin { pop float from the stack } newsp(sp+fsize); popr:=0.0 end;
  370. procedure pushx(objsize:size; a:adr);
  371. var i:integer;
  372. begin
  373. if objsize<wsize
  374. then push(mems(a,objsize))
  375. else for i:=1 to objsize div wsize do push(memw(a+objsize-wsize*i))
  376. end;
  377. procedure popx(objsize:size; a:adr);
  378. var i:integer;
  379. begin
  380. if objsize<wsize
  381. then stores(a,objsize,pop)
  382. else for i:=1 to objsize div wsize do store(a-wsize+wsize*i,pop)
  383. end;
  384. .ne 20
  385. .sp 2
  386. {---------------------------------------------------------------------------}
  387. { Bit manipulation routines (extract, shift, rotate) }
  388. {---------------------------------------------------------------------------}
  389. procedure sleft(var w:sword); { 1 bit left shift }
  390. begin w:= dosign(fitsw(2*w,EIOVFL)) end;
  391. procedure suleft(var w:word); { 1 bit left shift }
  392. begin w := chopw(2*w) end;
  393. procedure sdleft(var d:double); { 1 bit left shift }
  394. begin { shift two word signed integer } end;
  395. procedure sright(var w:sword); { 1 bit right shift with sign extension }
  396. begin if w >= 0 then w := w div 2 else w := (w-1) div 2 end;
  397. procedure suright(var w:word); { 1 bit right shift without sign extension }
  398. begin w := w div 2 end;
  399. procedure sdright(var d:double); { 1 bit right shift }
  400. begin { shift two word signed integer } end;
  401. procedure rleft(var w:word); { 1 bit left rotate }
  402. begin if w >= t15
  403. then w:=(w-t15)*2 + 1
  404. else w:=w*2
  405. end;
  406. procedure rright(var w:word); { 1 bit right rotate }
  407. begin if w mod 2 = 1
  408. then w:=w div 2 + t15
  409. else w:=w div 2
  410. end;
  411. function sextend(w:word;s:size):word;
  412. var i:size;
  413. begin
  414. for i:=1 to (wsize-s)*8 do rleft(w);
  415. for i:=1 to (wsize-s)*8 do sright(w);
  416. sextend:=w;
  417. end;
  418. function bit(b:bitnr; w:word):bitval; { return bit b of the word w }
  419. var i:bitnr;
  420. begin for i:= 1 to b do rright(w); bit:= w mod 2 end;
  421. function bf(ty:bftype; w1,w2:word):word; { return boolean fcn of 2 words }
  422. var i:bitnr; j:word;
  423. begin j:=0;
  424. for i:= maxbitnr downto 0 do
  425. begin j := 2*j;
  426. case ty of
  427. andf: if bit(i,w1)+bit(i,w2) = 2 then j:=j+1;
  428. iorf: if bit(i,w1)+bit(i,w2) > 0 then j:=j+1;
  429. xorf: if bit(i,w1)+bit(i,w2) = 1 then j:=j+1
  430. end
  431. end;
  432. bf:=j
  433. end;
  434. {---------------------------------------------------------------------------}
  435. { Array indexing }
  436. {---------------------------------------------------------------------------}
  437. function arraycalc(c:adr):adr; { subscript calculation }
  438. var j:full; objsize:size; a:adr;
  439. begin j:= popsw - signwd(memw(c));
  440. if (j<0) or (j>memw(c+wsize)) then trap(EARRAY);
  441. objsize := argo(memw(c+wsize+wsize));
  442. a := j*objsize+popa; chkadr(a,objsize);
  443. arraycalc:=a
  444. end;
  445. .ne 20
  446. .sp 2
  447. {---------------------------------------------------------------------------}
  448. { Double and Real Arithmetic }
  449. {---------------------------------------------------------------------------}
  450. { All routines for doubles and floats are dummy routines, since the format of
  451. doubles and floats is not defined in EM.
  452. }
  453. function doadi(ds,dt:double):double;
  454. begin { add two doubles } doadi:=0 end;
  455. function dosbi(ds,dt:double):double;
  456. begin { subtract two doubles } dosbi:=0 end;
  457. function domli(ds,dt:double):double;
  458. begin { multiply two doubles } domli:=0 end;
  459. function dodvi(ds,dt:double):double;
  460. begin { divide two doubles } dodvi:=0 end;
  461. function dormi(ds,dt:double):double;
  462. begin { modulo of two doubles } dormi:=0 end;
  463. function dongi(ds:double):double;
  464. begin { negative of a double } dongi:=0 end;
  465. function doadf(x,y:real):real;
  466. begin { add two floats } doadf:=0.0 end;
  467. function dosbf(x,y:real):real;
  468. begin { subtract two floats } dosbf:=0.0 end;
  469. function domlf(x,y:real):real;
  470. begin { multiply two floats } domlf:=0.0 end;
  471. function dodvf(x,y:real):real;
  472. begin { divide two floats } dodvf:=0.0 end;
  473. function dongf(x:real):real;
  474. begin { negate a float } dongf:=0.0 end;
  475. procedure dofif(x,y:real;var intpart,fraction:real);
  476. begin { dismember x*y into integer and fractional parts }
  477. intpart:=0.0; { integer part of x*y, same sign as x*y }
  478. fraction:=0.0;
  479. { fractional part of x*y, 0<=abs(fraction)<1 and same sign as x*y }
  480. end;
  481. procedure dofef(x:real;var mantissa:real;var exponent:sword);
  482. begin { dismember x into mantissa and exponent parts }
  483. mantissa:=0.0; { mantissa of x , >= 1/2 and <1 }
  484. exponent:=0; { base 2 exponent of x }
  485. end;
  486. .bp
  487. {---------------------------------------------------------------------------}
  488. { Trap and Call }
  489. {---------------------------------------------------------------------------}
  490. procedure call(p:adr); { Perform the call }
  491. begin
  492. pusha(lb);pusha(pc);
  493. newlb(sp);newsp(sp - memi(pd + pdsize*p + pdlocs));
  494. newpc(memi(pd + pdsize*p+ pdbase))
  495. end;
  496. procedure dotrap(n:byte);
  497. var i:size;
  498. begin
  499. if (uerrorproc=0) or intrap then
  500. begin
  501. if intrap then
  502. writeln('Recursive trap, first trap number was ', trapval:1);
  503. writeln('Error ', n:1);
  504. writeln('With',ord(insr):4,' arg ',k:1);
  505. goto 9999
  506. end;
  507. { Deposit all interpreter variables that need to be saved on
  508. the stack. This includes all scratch variables that can
  509. be in use at the moment and ( not possible in this interpreter )
  510. the internal address of the interpreter where the error occurred.
  511. This would make it possible to execute an RTT instruction totally
  512. transparent to the user program.
  513. It can, for example, occur within an ADD instruction that both
  514. operands are undefined and that the result overflows.
  515. Although this will generate 3 error traps it must be possible
  516. to ignore them all.
  517. }
  518. intrap:=true; trapval:=n;
  519. for i:=retsize div wsize downto 1 do push(retarea[i]);
  520. push(retsize); { saved return area }
  521. pusha(mema(fileadr)); { saved current file name pointer }
  522. push(memw(lineadr)); { saved line number }
  523. push(n); { push error number }
  524. a:=argp(uerrorproc);
  525. uerrorproc:=0; { reset signal }
  526. call(a); { call the routine }
  527. intrap:=false; { Don't catch recursive traps anymore }
  528. goto 8888; { reenter main loop }
  529. end;
  530. procedure trap;
  531. { This routine is invoked for overflow, and other run time errors.
  532. For non-fatal errors, trap returns to the calling routine
  533. }
  534. begin
  535. if n>=16 then dotrap(n) else if bit(n,ignmask)=0 then dotrap(n);
  536. end;
  537. procedure dortt;
  538. { The restoration of file address and line number is not essential.
  539. The restoration of the return save area is.
  540. }
  541. var i:size;
  542. n:word;
  543. begin
  544. newsp(lb); lb:=maxdata+1 ; { to circumvent ESTACK for the popa + pop }
  545. newpc(popa); newlb(popa); { So far a plain RET 0 }
  546. n:=pop; if (n>=16) and (n<64) then goto 9999 ;
  547. lino(pop); filna(popa); retsize:=pop;
  548. for i:=1 to retsize div wsize do retarea[i]:=pop ;
  549. end;
  550. .sp 2
  551. {---------------------------------------------------------------------------}
  552. { monitor calls }
  553. {---------------------------------------------------------------------------}
  554. procedure domon(entry:word);
  555. var index: 1..63;
  556. dummy: double;
  557. count,rwptr: adr;
  558. token: byte;
  559. i: integer;
  560. begin
  561. if (entry<=0) or (entry>63) then entry:=63 ;
  562. index:=entry;
  563. case index of
  564. 1: begin { exit } exitstatus:=pop; halted:=true end;
  565. 3: begin { read } dummy:=pop; { All input is from stdin }
  566. rwptr:=popa; count:=popa;
  567. i:=0 ;
  568. while (not eof(input)) and (i<count) do
  569. begin
  570. if eoln(input) then begin storeb(rwptr,10) ; count:=i end
  571. else storeb(rwptr,ord(input^)) ;
  572. get(input); rwptr:=rwptr+1 ; i:=i+1 ;
  573. end;
  574. pusha(i); push(0)
  575. end;
  576. 4: begin { write } dummy:=pop; { All output is to stdout }
  577. rwptr:=popa; count:=popa;
  578. for i:=1 to count do
  579. begin token:=memb(rwptr); rwptr:=rwptr+1 ;
  580. if token=10 then writeln else write(chr(token))
  581. end ;
  582. pusha(count);
  583. push(0)
  584. end;
  585. 54: begin { ioctl, faked } dummy:=popa;dummy:=popa;dummy:=pop;push(0) end ;
  586. 2, 5, 6, 7, 8, 9, 10,
  587. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  588. 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  589. 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  590. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
  591. 51, 52, 53, 55, 56, 57, 58, 59, 60,
  592. 61, 62:
  593. begin push(22); push(22) end;
  594. 63: { exists only for the trap }
  595. trap(EBADMON)
  596. end
  597. end;
  598. .bp
  599. {---------------------------------------------------------------------------}
  600. { Initialization and debugging }
  601. {---------------------------------------------------------------------------}
  602. procedure doident; { print line number and file name }
  603. var a:adr; i,c:integer; found:boolean;
  604. begin
  605. write('at line ',memw(lineadr):1,' ');
  606. a:=mema(fileadr); if a<>0 then
  607. begin i:=20; found:=false;
  608. while (i<>0) and not found do
  609. begin c:=memb(a); a:=a+1; found:=true; i:=i-1;
  610. if (c>=48) and (c<=57) then
  611. begin found:=false; write(chr(ord('0')+c-48)) end;
  612. if (c>=65) and (c<=90) then
  613. begin found:=false; write(chr(ord('A')+c-65)) end;
  614. if (c>=97) and (c<=122) then
  615. begin found:=false; write(chr(ord('a')+c-97)) end;
  616. end;
  617. end;
  618. writeln;
  619. end;
  620. procedure initialize; { start the ball rolling }
  621. { This is not part of the machine definition }
  622. var cset:set of char;
  623. f:ifset;
  624. iclass:insclass;
  625. insno:byte;
  626. nops:integer;
  627. opcode:byte;
  628. i,j,n:integer;
  629. wtemp:sword;
  630. count:integer;
  631. repc:adr;
  632. nexta,firsta:adr;
  633. elem:byte;
  634. amount,ofst:size;
  635. c:char;
  636. function readb(n:integer):double;
  637. var b:byte;
  638. begin read(prog,b); if n>1 then readb:=readb(n-1)*256+b else readb:=b end;
  639. function readbyte:byte;
  640. begin readbyte:=readb(1) end;
  641. function readword:word;
  642. begin readword:=readb(wsize) end;
  643. function readadr:adr;
  644. begin readadr:=readb(asize) end;
  645. function ifind(ordinal:byte):mnem;
  646. var loopvar:mnem;
  647. found:boolean;
  648. begin ifind:=NON;
  649. loopvar:=insr; found:=false;
  650. repeat
  651. if ordinal=ord(loopvar) then
  652. begin found:=true; ifind:=loopvar end;
  653. if loopvar<>ZRL then loopvar:=succ(loopvar) else loopvar:=NON;
  654. until found or (loopvar=insr) ;
  655. end;
  656. procedure readhdr;
  657. type hdrw=0..32767 ; { 16 bit header words }
  658. var hdr: hdrw;
  659. i: integer;
  660. begin
  661. for i:=0 to 7 do
  662. begin hdr:=readb(2);
  663. case i of
  664. 0: if hdr<>3757 then { 07255 }
  665. begin writeln('Not an em load file'); halt end;
  666. 2: if hdr<>0 then
  667. begin writeln('Unsolved references'); halt end;
  668. 3: if hdr<>3 then
  669. begin writeln('Incorrect load file version'); halt end;
  670. 4: if hdr<>wsize then
  671. begin writeln('Incorrect word size'); halt end;
  672. 5: if hdr<>asize then
  673. begin writeln('Incorrect pointer size'); halt end;
  674. 1,6,7:;
  675. end
  676. end
  677. end;
  678. procedure noinit;
  679. begin writeln('Illegal initialization'); halt end;
  680. procedure readint(a:adr;s:size);
  681. var i:size;
  682. begin { construct integer out of byte sequence }
  683. for i:=1 to s do { construct the value and initialize at a }
  684. begin storeb(a,readbyte); a:=a+1 end
  685. end;
  686. procedure readuns(a:adr;s:size);
  687. begin { construct unsigned out of byte sequence }
  688. readint(a,s) { identical to readint }
  689. end;
  690. procedure readfloat(a:adr;s:size);
  691. var i:size; b:byte;
  692. begin { construct float out of string}
  693. if (s<>4) and (s<>8) then noinit; i:=0;
  694. repeat { eat the bytes, construct the value and intialize at a }
  695. b:=readbyte; i:=i+1;
  696. until b=0 ;
  697. end;
  698. begin
  699. halted:=false;
  700. exitstatus:=undef;
  701. uerrorproc:=0; intrap:=false;
  702. { initialize tables }
  703. for i:=0 to maxcode do code[i]:=0;
  704. for i:=0 to maxdata do data[i]:=0;
  705. for iclass:=prim to tert do
  706. for i:=0 to 255 do
  707. with dispat[iclass][i] do
  708. begin instr:=NON; iflag:=[zbit] end;
  709. { read instruction table file. see appendix B }
  710. { The table read here is a simple transformation of the table on page xx }
  711. { - instruction names were transformed to numbers }
  712. { - the '-' flag was transformed to an 'i' flag for 'w' type instructions }
  713. { - the 'S' flag was added for instructions having signed operands }
  714. reset(tables);
  715. insr:=NON;
  716. repeat
  717. read(tables,insno) ; cset:=[]; f:=[];
  718. insr:=ifind(insno);
  719. if insr=NON then begin writeln('Incorrect table'); halt end;
  720. repeat read(tables,c) until c<>' ' ;
  721. repeat
  722. cset:=cset+[c];
  723. read(tables,c)
  724. until c=' ' ;
  725. if 'm' in cset then f:=f+[mini];
  726. if 's' in cset then f:=f+[short];
  727. if '-' in cset then f:=f+[zbit];
  728. if 'i' in cset then f:=f+[ibit];
  729. if 'S' in cset then f:=f+[sbit];
  730. if 'w' in cset then f:=f+[wbit];
  731. if (mini in f) or (short in f) then read(tables,nops) else nops:=1 ;
  732. readln(tables,opcode);
  733. if ('4' in cset) or ('8' in cset) then
  734. begin iclass:=tert end
  735. else if 'e' in cset then
  736. begin iclass:=second end
  737. else iclass:=prim;
  738. for i:=0 to nops-1 do
  739. begin
  740. with dispat[iclass,opcode+i] do
  741. begin
  742. iflag:=f; instr:=insr;
  743. if '2' in cset then ilength:=2
  744. else if 'u' in cset then ilength:=2
  745. else if '4' in cset then ilength:=4
  746. else if '8' in cset then ilength:=8
  747. else if (mini in f) or (short in f) then
  748. begin
  749. if 'N' in cset then wtemp:=-1-i else wtemp:=i ;
  750. if 'o' in cset then wtemp:=wtemp+1 ;
  751. if short in f then wtemp:=wtemp*256 ;
  752. implicit:=wtemp
  753. end
  754. end
  755. end
  756. until eof(tables);
  757. { read in program text, data and procedure descriptors }
  758. reset(prog);
  759. readhdr; { verify first header }
  760. for i:=1 to 8 do header[i]:=readadr; { read second header }
  761. hp:=maxdata+1; sp:=maxdata+1; lino(0);
  762. { read program text }
  763. if header[NTEXT]+header[NPROC]*pdsize>maxcode then
  764. begin writeln('Text size too large'); halt end;
  765. if header[SZDATA]>maxdata then
  766. begin writeln('Data size too large'); halt end;
  767. for i:=0 to header[NTEXT]-1 do code[i]:=readbyte;
  768. { read data blocks }
  769. nexta:=0;
  770. for i:=1 to header[NDATA] do
  771. begin
  772. n:=readbyte;
  773. if n<>0 then
  774. begin
  775. elem:=readbyte; firsta:=nexta;
  776. case n of
  777. 1: { uninitialized words }
  778. for j:=1 to elem do
  779. begin store(nexta,undef); nexta:=nexta+wsize end;
  780. 2: { initialized bytes }
  781. for j:=1 to elem do
  782. begin storeb(nexta,readbyte); nexta:=nexta+1 end;
  783. 3: { initialized words }
  784. for j:=1 to elem do
  785. begin store(nexta,readword); nexta:=nexta+wsize end;
  786. 4,5: { instruction and data pointers }
  787. for j:=1 to elem do
  788. begin storea(nexta,readadr); nexta:=nexta+asize end;
  789. 6: { signed integers }
  790. begin readint(nexta,elem); nexta:=nexta+elem end;
  791. 7: { unsigned integers }
  792. begin readuns(nexta,elem); nexta:=nexta+elem end;
  793. 8: { floating point numbers }
  794. begin readfloat(nexta,elem); nexta:=nexta+elem end;
  795. end
  796. end
  797. else
  798. begin
  799. repc:=readadr; amount:=nexta-firsta;
  800. for count:=1 to repc do
  801. begin
  802. for ofst:=0 to amount-1 do data[nexta+ofst]:=data[firsta+ofst];
  803. nexta:=nexta+amount;
  804. end
  805. end
  806. end;
  807. if header[SZDATA]<>nexta then writeln('Data initialization error');
  808. hp:=nexta;
  809. { read descriptor table }
  810. pd:=header[NTEXT];
  811. for i:=1 to header[NPROC]*pdsize do code[pd+i-1]:=readbyte;
  812. { call the entry point routine }
  813. ignmask:=0; { catch all traps, higher numbered traps cannot be ignored}
  814. retsize:=0;
  815. lb:=maxdata; { illegal dynamic link }
  816. pc:=maxcode; { illegal return address }
  817. push(0); a:=sp; { No environment }
  818. push(0); b:=sp; { No args }
  819. pusha(a); { envp }
  820. pusha(b); { argv }
  821. push(0); { argc }
  822. call(argp(header[ENTRY]));
  823. end;
  824. .bp
  825. {---------------------------------------------------------------------------}
  826. { MAIN LOOP OF THE INTERPRETER }
  827. {---------------------------------------------------------------------------}
  828. { It should be noted that the interpreter (microprogram) for an EM
  829. machine can be written in two fundamentally different ways: (1) the
  830. instruction operands are fetched in the main loop, or (2) the in-
  831. struction operands are fetched after the 256 way branch, by the exe-
  832. cution routines themselves. In this interpreter, method (1) is used
  833. to simplify the description of execution routines. The dispatch
  834. table dispat is used to determine how the operand is encoded. There
  835. are 4 possibilities:
  836. 0. There is no operand
  837. 1. The operand and instruction are together in 1 byte (mini)
  838. 2. The operand is one byte long and follows the opcode byte(s)
  839. 3. The operand is two bytes long and follows the opcode byte(s)
  840. 4. The operand is four bytes long and follows the opcode byte(s)
  841. In this interpreter, the main loop determines the operand type,
  842. fetches it, and leaves it in the global variable k for the execution
  843. routines to use. Consequently, instructions such as LOL, which use
  844. three different formats, need only be described once in the body of
  845. the interpreter.
  846. However, for a production interpreter, or a hardware EM
  847. machine, it is probably better to use method (2), i.e. to let the
  848. execution routines themselves fetch their own operands. The reason
  849. for this is that each opcode uniquely determines the operand format,
  850. so no table lookup in the dispatch table is needed. The whole table
  851. is not needed. Method (2) therefore executes much faster.
  852. However, separate execution routines will be needed for LOL with
  853. a one byte offset, and LOL with a two byte offset. It is to avoid
  854. this additional clutter that method (1) is used here. In a produc-
  855. tion interpreter, it is envisioned that the main loop will fetch the
  856. next instruction byte, and use it as an index into a 256 word table
  857. to find the address of the interpreter routine to jump to. The
  858. routine jumped to will begin by fetching its operand, if any,
  859. without any table lookup, since it knows which format to expect.
  860. After doing the work, it returns to the main loop by jumping in-
  861. directly to a register that contains the address of the main loop.
  862. A slight variation on this idea is to have the register contain
  863. the address of the branch table, rather than the address of the main
  864. loop.
  865. Another issue is whether the execution routines for LOL 0, LOL
  866. 2, LOL 4, etc. should all be have distinct execution routines. Doing
  867. so provides for the maximum speed, since the operand is implicit in
  868. the routine itself. The disadvantage is that many nearly identical
  869. execution routines will then be needed. Another way of doing it is
  870. to keep the instruction byte fetched from memory (LOL 0, LOL 2, LOL
  871. 4, etc.) in some register, and have all the LOL mini format instruc-
  872. tions branch to a common routine. This routine can then determine
  873. the operand by subtracting the code for LOL 0 from the register,
  874. leaving the true operand in the register (as a word quantity of
  875. course). This method makes the interpreter smaller, but is a bit
  876. slower.
  877. .bp
  878. To make this important point a little clearer, consider how a
  879. production interpreter for the PDP-11 might appear. Let us assume the
  880. following opcodes have been assigned:
  881. 31: LOL -2 (2 bytes, i.e. next word)
  882. 32: LOL -4
  883. 33: LOL -6
  884. 34: LOL b (format with a one byte offset)
  885. 35: LOL w (format with a one word, i.e. two byte offset)
  886. Further assume that each of the 5 opcodes will have its own execution
  887. routine, i.e. we are making a tradeoff in favor of fast execution and
  888. a slightly larger interpreter.
  889. Register r5 is the em program counter.
  890. Register r4 is the em LB register
  891. Register r3 is the em SP register (the stack grows toward low core)
  892. Register r2 contains the interpreter address of the main loop
  893. The main loop looks like this:
  894. movb (r5)+,r0 /fetch the opcode into r0 and increment r5
  895. asl r0 /shift r0 left 1 bit. Now: -256<=r0<=+254
  896. jmp *table(r0) /jump to execution routine
  897. Notice that no operand fetching has been done. The execution routines for
  898. the 5 sample instructions given above might be as follows:
  899. lol2: mov -2(r4),-(sp) /push local -2 onto stack
  900. jmp (r2) /go back to main loop
  901. lol4: mov -4(r4),-(sp) /push local -4 onto stack
  902. jmp (r2) /go back to main loop
  903. lol6: mov -6(r4),-(sp) /push local -6 onto stack
  904. jmp (r2) /go back to main loop
  905. lolb: mov $177400,r0 /prepare to fetch the 1 byte operand
  906. bisb (r5)+,r0 /operand is now in r0
  907. asl r0 /r0 is now offset from LB in bytes, not words
  908. add r4,r0 /r0 is now address of the needed local
  909. mov (r0),-(sp) /push the local onto the stack
  910. jmp (r2)
  911. lolw: clr r0 /prepare to fetch the 2 byte operand
  912. bisb (r5)+,r0 /fetch high order byte first !!!
  913. swab r0 /insert high order byte in place
  914. bisb (r5)+,r0 /insert low order byte in place
  915. asl r0 /convert offset to bytes, from words
  916. add r4,r0 /r0 is now address of needed local
  917. mov (r0),-(sp) /stack the local
  918. jmp (r2) /done
  919. The important thing to notice is where and how the operand fetch occurred:
  920. lol2, lol4, and lol6, (the mini's) have implicit operands
  921. lolb knew it had to fetch one byte, and did so without any table lookup
  922. lolw knew it had to fetch a word, and did so, high order byte first }
  923. .bp
  924. .sp 4
  925. {---------------------------------------------------------------------------}
  926. { Routines for the individual instructions }
  927. {---------------------------------------------------------------------------}
  928. procedure loadops;
  929. var j:integer;
  930. begin
  931. case insr of
  932. { LOAD GROUP }
  933. LDC: pushd(argd(k));
  934. LOC: pushsw(argc(k));
  935. LOL: push(memw(locadr(k)));
  936. LOE: push(memw(argg(k)));
  937. LIL: push(memw(mema(locadr(k))));
  938. LOF: push(memw(popa+argf(k)));
  939. LAL: pusha(locadr(k));
  940. LAE: pusha(argg(k));
  941. LXL: begin a:=lb; for j:=1 to argn(k) do a:=mema(a+savsize); pusha(a) end;
  942. LXA: begin a:=lb;
  943. for j:=1 to argn(k) do a:= mema(a+savsize);
  944. pusha(a+savsize)
  945. end;
  946. LOI: pushx(argo(k),popa);
  947. LOS: begin k:=argw(k); if k<>wsize then trap(EILLINS);
  948. k:=pop; pushx(argo(k),popa)
  949. end;
  950. LDL: begin a:=locadr(k); push(memw(a+wsize)); push(memw(a)) end;
  951. LDE: begin k:=argg(k); push(memw(k+wsize)); push(memw(k)) end;
  952. LDF: begin k:=argf(k);
  953. a:=popa; push(memw(a+k+wsize)); push(memw(a+k))
  954. end;
  955. LPI: push(argp(k))
  956. end
  957. end;
  958. procedure storeops;
  959. begin
  960. case insr of
  961. { STORE GROUP }
  962. STL: store(locadr(k),pop);
  963. STE: store(argg(k),pop);
  964. SIL: store(mema(locadr(k)),pop);
  965. STF: begin a:=popa; store(a+argf(k),pop) end;
  966. STI: popx(argo(k),popa);
  967. STS: begin k:=argw(k); if k<>wsize then trap(EILLINS);
  968. k:=popa; popx(argo(k),popa)
  969. end;
  970. SDL: begin a:=locadr(k); store(a,pop); store(a+wsize,pop) end;
  971. SDE: begin k:=argg(k); store(k,pop); store(k+wsize,pop) end;
  972. SDF: begin k:=argf(k); a:=popa; store(a+k,pop); store(a+k+wsize,pop) end
  973. end
  974. end;
  975. procedure intarith;
  976. var i:integer;
  977. begin
  978. case insr of
  979. { SIGNED INTEGER ARITHMETIC }
  980. ADI: case szindex(argw(k)) of
  981. 1: begin st:=popsw; ss:=popsw; push(fitsw(ss+st,EIOVFL)) end;
  982. 2: begin dt:=popd; ds:=popd; pushd(doadi(ds,dt)) end;
  983. end ;
  984. SBI: case szindex(argw(k)) of
  985. 1: begin st:=popsw; ss:= popsw; push(fitsw(ss-st,EIOVFL)) end;
  986. 2: begin dt:=popd; ds:=popd; pushd(dosbi(ds,dt)) end;
  987. end ;
  988. MLI: case szindex(argw(k)) of
  989. 1: begin st:=popsw; ss:= popsw; push(fitsw(ss*st,EIOVFL)) end;
  990. 2: begin dt:=popd; ds:=popd; pushd(domli(ds,dt)) end;
  991. end ;
  992. DVI: case szindex(argw(k)) of
  993. 1: begin st:= popsw; ss:= popsw;
  994. if st=0 then trap(EIDIVZ) else pushsw(ss div st)
  995. end;
  996. 2: begin dt:=popd; ds:=popd; pushd(dodvi(ds,dt)) end;
  997. end;
  998. RMI: case szindex(argw(k)) of
  999. 1: begin st:= popsw; ss:=popsw;
  1000. if st=0 then trap(EIDIVZ) else pushsw(ss - (ss div st)*st)
  1001. end;
  1002. 2: begin dt:=popd; ds:=popd; pushd(dormi(ds,dt)) end
  1003. end;
  1004. NGI: case szindex(argw(k)) of
  1005. 1: begin st:=popsw; pushsw(-st) end;
  1006. 2: begin ds:=popd; pushd(dongi(ds)) end
  1007. end;
  1008. SLI: begin t:=pop;
  1009. case szindex(argw(k)) of
  1010. 1: begin ss:=popsw;
  1011. for i:= 1 to t do sleft(ss); pushsw(ss)
  1012. end
  1013. end
  1014. end;
  1015. SRI: begin t:=pop;
  1016. case szindex(argw(k)) of
  1017. 1: begin ss:=popsw;
  1018. for i:= 1 to t do sright(ss); pushsw(ss)
  1019. end;
  1020. 2: begin ds:=popd;
  1021. for i:= 1 to t do sdright(ss); pushd(ss)
  1022. end
  1023. end
  1024. end
  1025. end
  1026. end;
  1027. procedure unsarith;
  1028. var i:integer;
  1029. begin
  1030. case insr of
  1031. { UNSIGNED INTEGER ARITHMETIC }
  1032. ADU: case szindex(argw(k)) of
  1033. 1: begin t:=pop; s:= pop; push(chopw(s+t)) end;
  1034. 2: trap(EILLINS);
  1035. end ;
  1036. SBU: case szindex(argw(k)) of
  1037. 1: begin t:=pop; s:= pop; push(chopw(s-t)) end;
  1038. 2: trap(EILLINS);
  1039. end ;
  1040. MLU: case szindex(argw(k)) of
  1041. 1: begin t:=pop; s:= pop; push(chopw(s*t)) end;
  1042. 2: trap(EILLINS);
  1043. end ;
  1044. DVU: case szindex(argw(k)) of
  1045. 1: begin t:= pop; s:= pop;
  1046. if t=0 then trap(EIDIVZ) else push(s div t)
  1047. end;
  1048. 2: trap(EILLINS);
  1049. end;
  1050. RMU: case szindex(argw(k)) of
  1051. 1: begin t:= pop; s:=pop;
  1052. if t=0 then trap(EIDIVZ) else push(s - (s div t)*t)
  1053. end;
  1054. 2: trap(EILLINS);
  1055. end;
  1056. SLU: case szindex(argw(k)) of
  1057. 1: begin t:=pop; s:=pop;
  1058. for i:= 1 to t do suleft(s); push(s)
  1059. end;
  1060. 2: trap(EILLINS);
  1061. end;
  1062. SRU: case szindex(argw(k)) of
  1063. 1: begin t:=pop; s:=pop;
  1064. for i:= 1 to t do suright(s); push(s)
  1065. end;
  1066. 2: trap(EILLINS);
  1067. end
  1068. end
  1069. end;
  1070. procedure fltarith;
  1071. begin
  1072. case insr of
  1073. { FLOATING POINT ARITHMETIC }
  1074. ADF: begin argwf(k); rt:=popr; rs:=popr; pushr(doadf(rs,rt)) end;
  1075. SBF: begin argwf(k); rt:=popr; rs:=popr; pushr(dosbf(rs,rt)) end;
  1076. MLF: begin argwf(k); rt:=popr; rs:=popr; pushr(domlf(rs,rt)) end;
  1077. DVF: begin argwf(k); rt:=popr; rs:=popr; pushr(dodvf(rs,rt)) end;
  1078. NGF: begin argwf(k); rt:=popr; pushr(dongf(rt)) end;
  1079. FIF: begin argwf(k); rt:=popr; rs:=popr;
  1080. dofif(rt,rs,x,y); pushr(y); pushr(x)
  1081. end;
  1082. FEF: begin argwf(k); rt:=popr; dofef(rt,x,ss); pushr(x); pushsw(ss) end
  1083. end
  1084. end;
  1085. procedure ptrarith;
  1086. begin
  1087. case insr of
  1088. { POINTER ARITHMETIC }
  1089. ADP: pusha(popa+argf(k));
  1090. ADS: case szindex(argw(k)) of
  1091. 1: begin st:=popsw; pusha(popa+st) end;
  1092. 2: begin dt:=popd; pusha(popa+dt) end;
  1093. end;
  1094. SBS: begin
  1095. a:=popa; b:=popa;
  1096. case szindex(argw(k)) of
  1097. 1: push(fitsw(b-a,EIOVFL));
  1098. 2: pushd(b-a)
  1099. end
  1100. end
  1101. end
  1102. end;
  1103. procedure incops;
  1104. var j:integer;
  1105. begin
  1106. case insr of
  1107. { INCREMENT/DECREMENT/ZERO }
  1108. INC: push(fitsw(popsw+1,EIOVFL));
  1109. INL: begin a:=locadr(k); store(a,fitsw(signwd(memw(a))+1,EIOVFL)) end;
  1110. INE: begin a:=argg(k); store(a,fitsw(signwd(memw(a))+1,EIOVFL)) end;
  1111. DEC: push(fitsw(popsw-1,EIOVFL));
  1112. DEL: begin a:=locadr(k); store(a,fitsw(signwd(memw(a))-1,EIOVFL)) end;
  1113. DEE: begin a:=argg(k); store(a,fitsw(signwd(memw(a))-1,EIOVFL)) end;
  1114. ZRL: store(locadr(k),0);
  1115. ZRE: store(argg(k),0);
  1116. ZER: for j:=1 to argw(k) div wsize do push(0);
  1117. ZRF: pushr(0);
  1118. end
  1119. end;
  1120. procedure convops;
  1121. begin
  1122. case insr of
  1123. { CONVERT GROUP }
  1124. CII: begin s:=pop; t:=pop;
  1125. if t<wsize then begin push(sextend(pop,t)); t:=wsize end;
  1126. case szindex(argw(t)) of
  1127. 1: if szindex(argw(s))=2 then pushd(popsw);
  1128. 2: if szindex(argw(s))=1 then push(fitsw(popd,ECONV))
  1129. end
  1130. end;
  1131. CIU: case szindex(argw(pop)) of
  1132. 1: if szindex(argw(pop))=2 then push(unsign(popd mod negoff));
  1133. 2: trap(EILLINS);
  1134. end;
  1135. CIF: begin argwf(pop);
  1136. case szindex(argw(pop)) of 1:pushr(popsw); 2:pushr(popd) end
  1137. end;
  1138. CUI: case szindex(argw(pop)) of
  1139. 1: case szindex(argw(pop)) of
  1140. 1: begin s:=pop; if s>maxsint then trap(ECONV); push(s) end;
  1141. 2: trap(EILLINS);
  1142. end;
  1143. 2: case szindex(argw(pop)) of
  1144. 1: pushd(pop);
  1145. 2: trap(EILLINS);
  1146. end;
  1147. end;
  1148. CUU: case szindex(argw(pop)) of
  1149. 1: if szindex(argw(pop))=2 then trap(EILLINS);
  1150. 2: trap(EILLINS);
  1151. end;
  1152. CUF: begin argwf(pop);
  1153. if szindex(argw(pop))=1 then pushr(pop) else trap(EILLINS)
  1154. end;
  1155. CFI: begin sz:=argw(pop); argwf(pop); rt:=popr;
  1156. case szindex(sz) of
  1157. 1: push(fitsw(trunc(rt),ECONV));
  1158. 2: pushd(fitd(trunc(rt)));
  1159. end
  1160. end;
  1161. CFU: begin sz:=argw(pop); argwf(pop); rt:=popr;
  1162. case szindex(sz) of
  1163. 1: push( chopw(trunc(abs(rt)-0.5)) );
  1164. 2: trap(EILLINS);
  1165. end
  1166. end;
  1167. CFF: begin argwf(pop); argwf(pop) end
  1168. end
  1169. end;
  1170. procedure logops;
  1171. var i,j:integer;
  1172. begin
  1173. case insr of
  1174. { LOGICAL GROUP }
  1175. XAND:
  1176. begin k:=argw(k);
  1177. for j:= 1 to k div wsize do
  1178. begin a:=sp+k; t:=pop; store(a,bf(andf,memw(a),t)) end;
  1179. end;
  1180. IOR:
  1181. begin k:=argw(k);
  1182. for j:= 1 to k div wsize do
  1183. begin a:=sp+k; t:=pop; store(a,bf(iorf,memw(a),t)) end;
  1184. end;
  1185. XOR:
  1186. begin k:=argw(k);
  1187. for j:= 1 to k div wsize do
  1188. begin a:=sp+k; t:=pop; store(a,bf(xorf,memw(a),t)) end;
  1189. end;
  1190. COM:
  1191. begin k:=argw(k);
  1192. for j:= 1 to k div wsize do
  1193. begin
  1194. store(sp+k-wsize*j, bf(xorf,memw(sp+k-wsize*j), negoff-1))
  1195. end
  1196. end;
  1197. ROL: begin k:=argw(k); if k<>wsize then trap(EILLINS);
  1198. t:=pop; s:=pop; for i:= 1 to t do rleft(s); push(s)
  1199. end;
  1200. ROR: begin k:=argw(k); if k<>wsize then trap(EILLINS);
  1201. t:=pop; s:=pop; for i:= 1 to t do rright(s); push(s)
  1202. end
  1203. end
  1204. end;
  1205. procedure setops;
  1206. var i,j:integer;
  1207. begin
  1208. case insr of
  1209. { SET GROUP }
  1210. INN:
  1211. begin k:=argw(k);
  1212. t:=pop;
  1213. i:= t mod 8; t:= t div 8;
  1214. if t>=k then
  1215. begin trap(ESET); s:=0 end
  1216. else
  1217. begin s:=memb(sp+t) end;
  1218. newsp(sp+k); push(bit(i,s));
  1219. end;
  1220. XSET:
  1221. begin k:=argw(k);
  1222. t:=pop;
  1223. i:= t mod 8; t:= t div 8;
  1224. for j:= 1 to k div wsize do push(0);
  1225. if t>=k then
  1226. trap(ESET)
  1227. else
  1228. begin s:=1; for j:= 1 to i do rleft(s); storeb(sp+t,s) end
  1229. end
  1230. end
  1231. end;
  1232. procedure arrops;
  1233. begin
  1234. case insr of
  1235. { ARRAY GROUP }
  1236. LAR:
  1237. begin k:=argw(k); if k<>wsize then trap(EILLINS); a:=popa;
  1238. pushx(argo(memw(a+2*k)),arraycalc(a))
  1239. end;
  1240. SAR:
  1241. begin k:=argw(k); if k<>wsize then trap(EILLINS); a:=popa;
  1242. popx(argo(memw(a+2*k)),arraycalc(a))
  1243. end;
  1244. AAR:
  1245. begin k:=argw(k); if k<>wsize then trap(EILLINS); a:=popa;
  1246. push(arraycalc(a))
  1247. end
  1248. end
  1249. end;
  1250. procedure cmpops;
  1251. begin
  1252. case insr of
  1253. { COMPARE GROUP }
  1254. CMI: case szindex(argw(k)) of
  1255. 1: begin st:=popsw; ss:=popsw;
  1256. if ss<st then pushsw(-1) else if ss=st then push(0) else push(1)
  1257. end;
  1258. 2: begin dt:=popd; ds:=popd;
  1259. if ds<dt then pushsw(-1) else if ds=dt then push(0) else push(1)
  1260. end;
  1261. end;
  1262. CMU: case szindex(argw(k)) of
  1263. 1: begin t:=pop; s:=pop;
  1264. if s<t then pushsw(-1) else if s=t then push(0) else push(1)
  1265. end;
  1266. 2: trap(EILLINS);
  1267. end;
  1268. CMP: begin a:=popa; b:=popa;
  1269. if b<a then pushsw(-1) else if b=a then push(0) else push(1)
  1270. end;
  1271. CMF: begin argwf(k); rt:=popr; rs:=popr;
  1272. if rs<rt then pushsw(-1) else if rs=rt then push(0) else push(1)
  1273. end;
  1274. CMS: begin k:=argw(k);
  1275. t:= 0; j:= 0;
  1276. while (j < k) and (t=0) do
  1277. begin if memw(sp+j) <> memw(sp+k+j) then t:=1;
  1278. j:=j+wsize
  1279. end;
  1280. newsp(sp+wsize*k); push(t);
  1281. end;
  1282. TLT: if popsw < 0 then push(1) else push(0);
  1283. TLE: if popsw <= 0 then push(1) else push(0);
  1284. TEQ: if pop = 0 then push(1) else push(0);
  1285. TNE: if pop <> 0 then push(1) else push(0);
  1286. TGE: if popsw >= 0 then push(1) else push(0);
  1287. TGT: if popsw > 0 then push(1) else push(0);
  1288. end
  1289. end;
  1290. procedure branchops;
  1291. begin
  1292. case insr of
  1293. { BRANCH GROUP }
  1294. BRA: newpc(pc+k);
  1295. BLT: begin st:=popsw; if popsw < st then newpc(pc+k) end;
  1296. BLE: begin st:=popsw; if popsw <= st then newpc(pc+k) end;
  1297. BEQ: begin t :=pop ; if pop = t then newpc(pc+k) end;
  1298. BNE: begin t :=pop ; if pop <> t then newpc(pc+k) end;
  1299. BGE: begin st:=popsw; if popsw >= st then newpc(pc+k) end;
  1300. BGT: begin st:=popsw; if popsw > st then newpc(pc+k) end;
  1301. ZLT: if popsw < 0 then newpc(pc+k);
  1302. ZLE: if popsw <= 0 then newpc(pc+k);
  1303. ZEQ: if pop = 0 then newpc(pc+k);
  1304. ZNE: if pop <> 0 then newpc(pc+k);
  1305. ZGE: if popsw >= 0 then newpc(pc+k);
  1306. ZGT: if popsw > 0 then newpc(pc+k)
  1307. end
  1308. end;
  1309. procedure callops;
  1310. var j:integer;
  1311. begin
  1312. case insr of
  1313. { PROCEDURE CALL GROUP }
  1314. CAL: call(argp(k));
  1315. CAI: begin call(argp(popa)) end;
  1316. RET: begin k:=argz(k); if k div wsize>maxret then trap(EILLINS);
  1317. for j:= 1 to k div wsize do retarea[j]:=pop; retsize:=k;
  1318. newsp(lb); lb:=maxdata+1; { To circumvent stack overflow error }
  1319. newpc(popa);
  1320. if pc=maxcode then
  1321. begin
  1322. halted:=true;
  1323. if retsize=wsize then exitstatus:=retarea[1]
  1324. else exitstatus:=undef
  1325. end
  1326. else
  1327. newlb(popa);
  1328. end;
  1329. LFR: begin k:=args(k); if k<>retsize then trap(EILLINS);
  1330. for j:=k div wsize downto 1 do push(retarea[j]);
  1331. end
  1332. end
  1333. end;
  1334. procedure miscops;
  1335. var i,j:integer;
  1336. begin
  1337. case insr of
  1338. { MISCELLANEOUS GROUP }
  1339. ASP,ASS:
  1340. begin if insr=ASS then
  1341. begin k:=argw(k); if k<>wsize then trap(EILLINS); k:=popsw end;
  1342. k:=argf(k);
  1343. if k<0
  1344. then for j:= 1 to -k div wsize do push(undef)
  1345. else newsp(sp+k);
  1346. end;
  1347. BLM,BLS:
  1348. begin if insr=BLS then
  1349. begin k:=argw(k); if k<>wsize then trap(EILLINS); k:=pop end;
  1350. k:=argz(k);
  1351. b:=popa; a:=popa;
  1352. for j := 1 to k div wsize do
  1353. store(b-wsize+wsize*j,memw(a-wsize+wsize*j))
  1354. end;
  1355. CSA: begin k:=argw(k); if k<>wsize then trap(EILLINS);
  1356. a:=popa;
  1357. st:= popsw - signwd(memw(a+asize));
  1358. if (st>=0) and (st<=memw(a+wsize+asize)) then
  1359. b:=mema(a+2*wsize+asize+asize*st) else b:=mema(a);
  1360. if b=0 then trap(ECASE) else newpc(b)
  1361. end;
  1362. CSB: begin k:=argw(k); if k<>wsize then trap(EILLINS); a:=popa;
  1363. t:=pop; i:=1; found:=false;
  1364. while (i<=memw(a+asize)) and not found do
  1365. if t=memw(a+(asize+wsize)*i) then found:=true else i:=i+1;
  1366. if found then b:=memw(a+(asize+wsize)*i+wsize) else b:=memw(a);
  1367. if b=0 then trap(ECASE) else newpc(b);
  1368. end;
  1369. DCH: begin pusha(mema(popa+dynd)) end;
  1370. DUP,DUS:
  1371. begin if insr=DUS then
  1372. begin k:=argw(k); if k<>wsize then trap(EILLINS); k:=pop end;
  1373. k:=args(k);
  1374. for i:=1 to k div wsize do push(memw(sp+k-wsize));
  1375. end;
  1376. EXG: begin
  1377. k:=argw(k);
  1378. for i:=1 to k div wsize do push(memw(sp+k-wsize));
  1379. for i:=0 to k div wsize - 1 do
  1380. store(sp+k+i*wsize,memw(sp+k+k+i*wsize));
  1381. for i:=1 to k div wsize do
  1382. begin t:=pop ; store(sp+k+k-wsize,t) end;
  1383. end;
  1384. FIL: filna(argg(k));
  1385. GTO: begin k:=argg(k);
  1386. newlb(mema(k+2*asize)); newsp(mema(k+asize)); newpc(mema(k))
  1387. end;
  1388. LIM: push(ignmask);
  1389. LIN: lino(argn(k));
  1390. LNI: lino(memw(0)+1);
  1391. LOR: begin i:=argr(k);
  1392. case i of 0:pusha(lb); 1:pusha(sp); 2:pusha(hp) end;
  1393. end;
  1394. LPB: pusha(popa+statd);
  1395. MON: domon(pop);
  1396. NOP: writeln('NOP at line ',memw(0):5) ;
  1397. RCK: begin a:=popa;
  1398. case szindex(argw(k)) of
  1399. 1: if (signwd(memw(sp))<signwd(memw(a))) or
  1400. (signwd(memw(sp))>signwd(memw(a+wsize))) then trap(ERANGE);
  1401. 2: if (memd(sp)<memd(a)) or
  1402. (memd(sp)>memd(a+2*wsize)) then trap(ERANGE);
  1403. end
  1404. end;
  1405. RTT: dortt;
  1406. SIG: begin a:=popa; pusha(uerrorproc); uerrorproc:=a end;
  1407. SIM: ignmask:=pop;
  1408. STR: begin i:=argr(k);
  1409. case i of 0: newlb(popa); 1: newsp(popa); 2: newhp(popa) end;
  1410. end;
  1411. TRP: trap(pop)
  1412. end
  1413. end;
  1414. .bp
  1415. {---------------------------------------------------------------------------}
  1416. { Main Loop }
  1417. {---------------------------------------------------------------------------}
  1418. begin initialize;
  1419. 8888:
  1420. repeat
  1421. opcode := nextpc; { fetch the first byte of the instruction }
  1422. if opcode=escape1 then iclass:=second
  1423. else if opcode=escape2 then iclass:=tert
  1424. else iclass:=prim;
  1425. if iclass<>prim then opcode := nextpc;
  1426. with dispat[iclass][opcode] do
  1427. begin insr:=instr;
  1428. if not (zbit in iflag) then
  1429. if ibit in iflag then k:=pop else
  1430. begin
  1431. if mini in iflag then k:=implicit else
  1432. begin
  1433. if short in iflag then k:=implicit+nextpc else
  1434. begin k:=nextpc;
  1435. if (sbit in iflag) and (k>=128) then k:=k-256;
  1436. for i:=2 to ilength do k:=256*k + nextpc
  1437. end
  1438. end;
  1439. if wbit in iflag then k:=k*wsize;
  1440. end
  1441. end;
  1442. case insr of
  1443. NON: trap(EILLINS);
  1444. { LOAD GROUP }
  1445. LDC,LOC,LOL,LOE,LIL,LOF,LAL,LAE,LXL,LXA,LOI,LOS,LDL,LDE,LDF,LPI:
  1446. loadops;
  1447. { STORE GROUP }
  1448. STL,STE,SIL,STF,STI,STS,SDL,SDE,SDF:
  1449. storeops;
  1450. { SIGNED INTEGER ARITHMETIC }
  1451. ADI,SBI,MLI,DVI,RMI,NGI,SLI,SRI:
  1452. intarith;
  1453. { UNSIGNED INTEGER ARITHMETIC }
  1454. ADU,SBU,MLU,DVU,RMU,SLU,SRU:
  1455. unsarith;
  1456. { FLOATING POINT ARITHMETIC }
  1457. ADF,SBF,MLF,DVF,NGF,FIF,FEF:
  1458. fltarith;
  1459. { POINTER ARITHMETIC }
  1460. ADP,ADS,SBS:
  1461. ptrarith;
  1462. { INCREMENT/DECREMENT/ZERO }
  1463. INC,INL,INE,DEC,DEL,DEE,ZRL,ZRE,ZER,ZRF:
  1464. incops;
  1465. { CONVERT GROUP }
  1466. CII,CIU,CIF,CUI,CUU,CUF,CFI,CFU,CFF:
  1467. convops;
  1468. { LOGICAL GROUP }
  1469. XAND,IOR,XOR,COM,ROL,ROR:
  1470. logops;
  1471. { SET GROUP }
  1472. INN,XSET:
  1473. setops;
  1474. { ARRAY GROUP }
  1475. LAR,SAR,AAR:
  1476. arrops;
  1477. { COMPARE GROUP }
  1478. CMI,CMU,CMP,CMF,CMS, TLT,TLE,TEQ,TNE,TGE,TGT:
  1479. cmpops;
  1480. { BRANCH GROUP }
  1481. BRA, BLT,BLE,BEQ,BNE,BGE,BGT, ZLT,ZLE,ZEQ,ZNE,ZGE,ZGT:
  1482. branchops;
  1483. { PROCEDURE CALL GROUP }
  1484. CAL,CAI,RET,LFR:
  1485. callops;
  1486. { MISCELLANEOUS GROUP }
  1487. ASP,ASS,BLM,BLS,CSA,CSB,DCH,DUP,DUS,EXG,FIL,GTO,LIM,
  1488. LIN,LNI,LOR,LPB,MON,NOP,RCK,RTT,SIG,SIM,STR,TRP:
  1489. miscops;
  1490. end; { end of case statement }
  1491. if not ( (insr=RET) or (insr=ASP) or (insr=BRA) or (insr=GTO) ) then
  1492. retsize:=0 ;
  1493. until halted;
  1494. 9999:
  1495. writeln('halt with exit status: ',exitstatus:1);
  1496. doident;
  1497. end.
  1498. .ft P
  1499. .lg 1
  1500. .fi