em.p 54 KB

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