In asxlat, translate ! to ~ (not operator; used with bic instruction)
[pdp11_as.git] / as0.c
1 /* as0.c */
2
3 #include <stdio.h> /* temp */
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <signal.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #ifdef pdp11
11 typedef int intptr_t;
12 #endif
13 #include "as0.h"
14 #include "as2.h"
15
16 /*      .globl  _main, _write, _close, _execl, __exit, _brk */
17 /*      .globl  _read, _signal, _stat, _open, _mkstemp, _calloc, _realloc */
18
19 /*      .globl  error, errore, errora, checkeos, pass1, aexit, argb */
20 /*      .globl  overlaid, defund, a.outp, errflg, passno, filerr, outmod */
21 /*      .globl  wrterr, argb, hshsiz, dot, dotdot, savdot, ch, outbuf */
22 /*      .globl  line, savop, inbuf, fbptr, fbtbl, symnum, hshtab, symblk */
23 /*      .globl  symleft, dotrel, symtab, fin, fout, curfb, nxtfb, ibufp */
24 /*      .globl  ibufc, a.tmp1, usymtab, SYMENTSZ, SYMBLKSZ, PSTENTSZ */
25 /*      .globl  obufp, Newsym, symbol,csv */
26
27 /* This assembler supports _both_ the old style object files (with */
28 /* fixed 8 character symbols) and the new style (with a strings table). */
29 /* The variable 'Newsym' defined below specifies which format will be */
30 /* emitted, if the value is '0' the old style is output, if non-zero */
31 /* then the new 'string table' format is output. */
32
33 /* The old style on disc symbol table entries looked like this: */
34 /*   struct symbol */
35 /*      { */
36 /*      char name[8]; */
37 /*      short type; */
38 /*      short value; */
39 /*      }; */
40
41 /* The new style of on disc symbol table entry looks like: */
42 /*   struct symbol */
43 /*      { */
44 /*      off_t offset_in_string_table; */
45 /*      short type; */
46 /*      short value; */
47 /*      }; */
48
49 /*      .data */
50 /* Newsym:      1 */
51 /*      .text */
52
53 char Newsym = 1;
54
55 struct symbol *pdot = symtab;
56 struct symbol *pdotdot = symtab + 1;
57 intptr_t numbertoken; /* r0 */
58 int numbervalue; /* r0 */
59 int endflag; /* r1 */
60 int indirect; /* r0 */
61 int optoken; /* (sp) */
62 int rightflags; /* r0 */
63 int rightvalue; /* r1 */
64 int leftvalue; /* r2 */
65 int leftflags; /* r3 */
66 intptr_t token; /* r4 */
67
68 #ifdef TRANSLATE
69 static char xbuf[0x1000];
70 static char *xbufp = xbuf, *xwhitep, *xstartp;
71 static char *xstartpsave, *xbufpsave;
72 static size_t xsavestartn, xsavebufn;
73 static char xsave[0x1000];
74 static size_t xrestn;
75 static char xrest[0x1000];
76 static int xlab, xlabnext;
77 static int xlabb[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
78 static int xlabf[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
79 #endif
80
81 /* PDP-11 assembler */
82 /* _main: */
83 /*      jsr     r5,csv */
84
85 int main(argc, argv) int argc; char **argv; {
86         sig_t oldsig;
87         char *p;
88         struct symbol *psymbol;
89         int hash, c;
90         struct symbol **ppsymbol;
91
92 /*      mov     $1,-(sp)                / signal(SIGINT, SIG_IGN) */
93 /*      mov     $2,-(sp) */
94 /*      jsr     pc,_signal */
95 /*      cmp     (sp)+,(sp)+ */
96 /*      ror     r0 */
97 /*      bcs     1f */
98
99 /*      mov     $aexit,-(sp)            / signal(SIGINT, aexit) */
100 /*      mov     $2,-(sp) */
101 /*      jsr     pc,_signal */
102 /*      cmp     (sp)+,(sp)+ */
103
104         oldsig = signal(SIGINT, SIG_IGN);
105         if (oldsig != SIG_IGN) /*((int)oldsig & 1) == 0)*/
106                 signal(SIGINT, (sig_t)aexit);
107
108 /* 1: */
109 /*      mov     4(r5),r0                / argc */
110 /*      mov     6(r5),curarg            / argv */
111
112         curarg = argv;
113         nargs = argc;
114         while (nargs) {
115
116 /* 9: */
117 /*      dec     r0                      / argc-- */
118 /*      add     $2,curarg               / argv++ */
119
120                 curarg++;
121                 nargs--;
122                 if (nargs == 0)
123                         break;
124
125 /* 1: */
126 /*      mov     *curarg,r1 */
127
128                 p = *curarg;
129
130 /*      cmpb    (r1)+,$'- */
131 /*      bne     1f */
132
133                 if (*p++ != '-')
134                         break;
135
136 /*      cmpb    (r1),$'-                / is this "--"? */
137 /*      bne     8f                      / no - br */
138 /*      tstb    1(r1)                   / check for null terminator */
139 /*      beq     1f                      / got it, the "--" means read 'stdin' */
140
141                 if (*p == '-' && p[1] == 0)
142                         break;
143
144 /* 8: */
145 /*      add     $2,curarg               / argv++ */
146 /*      dec     r0                      / argc-- */
147 /*      cmpb    (r1),$'u */
148 /*      beq     3f */
149 /*      cmpb    (r1), $'V */
150 /*      bne     2f */
151 /*      inc     overlaid */
152 /*      br      1b */
153 /* 2: */
154
155                 if (*p == 'V') {
156                         overlaid = 1;
157                         continue;
158                 }
159
160 /*      tstb    (r1) */
161 /*      bne     2f */
162 /* 3: */
163 /*      mov     $40,defund */
164 /*      br      1b */
165 /* 2: */
166
167                 if (*p == 'u' || *p == 0) {
168                         defund = FGLOBAL;
169                         continue;
170                 }
171
172 /*      cmpb    (r1),$'o */
173 /*      bne     1f */
174 /*      mov     *curarg,a.outp */
175 /*      br      9b */
176 /* 1: */
177
178                 if (*p == 'o') {
179                         curarg++;
180                         a_outp = *curarg;
181                         nargs--;
182                         continue;
183                 }
184                 break;
185         }
186
187 /* The new object file format puts a ceiling of 32 characters on symbols. */
188 /* If it is desired to raise this limit all that need be done is increase */
189 /* the same ceiling in the C compiler and linker (ld). */
190
191 /*      tst     Newsym */
192 /*      beq     1f */
193 /*      movb    $32.,Ncps */
194 /* 1: */
195
196         if (Newsym)
197                 Ncps = 32;
198
199 /*      mov     r0,nargs                / # of remaining args */
200 /*      bne     8f                      / br if any left */
201 /*      inc     nargs                   / fake at least one arg */
202 /*      mov     $dash, curarg           / of '-' so we read stdin */
203 /* 8: */
204
205         if (nargs == 0) {
206                 nargs = 1;
207                 curarg = &dash;
208         }
209
210 /*      mov     $a.tmp1,-(sp) */
211 /*      jsr     pc,_mkstemp             / fout = mkstemp(a.tmp1); */
212 /*      tst     (sp)+ */
213 /*      mov     r0,fout */
214 /*      bmi     oops */
215
216         fout = mkstemp(a_tmp1);
217         if (fout < 0)
218                 oops();
219
220 /* the symbol table is a single linked list of dynamically allocated */
221 /* 'SYMBLKSZ' byte blocks.  Allocate the first one now. */
222 /*      mov     $SYMBLKSZ+2,-(sp)       / symblk = calloc(1, SYMBLKSZ+2) */
223 /*      mov     $1,-(sp) */
224 /*      jsr     pc,_calloc */
225 /*      cmp     (sp)+,(sp)+ */
226 /*      mov     r0,symblk */
227 /*      mov     r0,usymtab              / pointer to first block */
228 /*      tst     (r0)+                   / skip link word */
229 /*      mov     r0,symend               / current end in block */
230 /*      mov     $SYMBLKSZ,symleft       / number of bytes left in block */
231
232         symblk = (struct symblk *)calloc(1, sizeof(struct symblk));
233         if (symblk == NULL)
234                 nomem(); /* don't use oops(), want to delete temp file */
235         usymtab = symblk;
236         symend = symblk->data;
237         symleft = SYMBLKSZ;
238
239 /* The string portion of symbol table entries is now allocated dynamically. */
240 /* We allocate the strings in 1kb chunks to cut down the number of times */
241 /* the string table needs to be extended (besides, long variable names are */
242 /* coming real soon now). */
243
244 /* NOTE: the string blocks are linked together for debugging purposes only, */
245 /* nothing depends on the link. */
246
247 /*      mov     $STRBLKSZ+2,-(sp) */
248 /*      mov     $1,-(sp) */
249 /*      jsr     pc,_calloc              / strblk = calloc(1, STRBLKSZ+2) */
250 /*      / check for failure??? */
251 /*      cmp     (sp)+,(sp)+ */
252 /*      mov     r0,strblk               / save pointer to string block */
253 /*      tst     (r0)+                   / skip link word */
254 /*      mov     r0,strend               / set available string pointer */
255 /*      mov     $STRBLKSZ,strleft       / set amount left in block */
256
257         strblk = (struct strblk *)calloc(1, sizeof(struct strblk));
258         if (strblk == NULL)
259                 nomem(); /* don't use oops(), want to delete temp file */
260         strend = strblk->data;
261         strleft = STRBLKSZ;
262
263 /* the hash table is now dynamically allocated so that it can be */
264 /* reused in pass 2 and re-alloced if necessary. */
265 /*      mov     $2,-(sp)                / hshtab = calloc($hshsiz, sizeof(int)) */
266 /*      mov     $hshsiz,-(sp) */
267 /*      jsr     pc,_calloc */
268 /*      cmp     (sp)+,(sp)+ */
269 /*      mov     r0, hshtab */
270
271         hshtab = (struct symbol **)calloc(hshsiz, sizeof(struct symbol *));
272         if (hshtab == NULL)
273                 nomem(); /* don't use oops(), want to delete temp file */
274
275 /*      mov     $symtab,r1 */
276
277         psymbol = symtab;
278         do {
279
280 /* 1: */
281 /*      clr     r3 */
282 /*      mov     (r1),r2                 / pointer to PST symbol's string */
283
284                 hash = 0;
285                 p = psymbol->name;
286
287 /* 2: */
288 /*      movb    (r2)+,r4 */
289 /*      beq     2f */
290 /*      add     r4,r3 */
291 /*      swab    r3 */
292 /*      br      2b */
293 /* 2: */
294
295                 while (1) {
296                         c = *p++;
297                         if (c == 0)
298                                 break;
299                         hash += c;
300                         hash = ((hash >> 8) & 0377) | ((hash & 0377) << 8);
301                 }
302
303 /*      clr     r2 */
304 /*      div     $hshsiz,r2 */
305 /*      ashc    $1,r2 */
306 /*      add     hshtab,r3 */
307
308                 ppsymbol = hshtab + (hash % hshsiz);
309                 hash /= hshsiz;
310
311 /* 4: */
312 /*      sub     r2,r3 */
313 /*      cmp     r3,hshtab */
314 /*      bhi     3f */
315 /*      add     $2*hshsiz,r3 */
316 /* 3: */
317 /*      tst     -(r3) */
318 /*      bne     4b */
319 /*      mov     r1,(r3) */
320 /*      add     $PSTENTSZ,r1 */
321 /*      cmp     r1,$ebsymtab */
322 /*      blo     1b */
323
324                 do {
325                         ppsymbol -= hash;
326                         if (ppsymbol <= hshtab)
327                                 ppsymbol += hshsiz;
328                 } while (*--ppsymbol);
329                 *ppsymbol = psymbol++;
330         } while (psymbol < symtab + ebsymtab);
331
332 /* perform pass 0 processing */
333 /*      jsr     pc,pass0 */
334
335 #ifdef LISTING
336         printf("pass 0\n");
337 #endif
338         pass0();
339 #ifdef TRANSLATE
340  write(1, xbuf, xbufp - xbuf);
341 #endif
342
343 /* flush the intermediate object file */
344 /*      mov     $1024.,-(sp)            / write(fout, outbuf, 1024) */
345 /*      mov     $outbuf,-(sp) */
346 /*      mov     fout,-(sp) */
347 /*      jsr     pc,_write */
348 /*      add     $6,sp */
349
350         write(fout, outbuf, 512 * sizeof(short));
351
352 /*      tst     errflg                  / any errors? */
353 /*      beq     1f                      / yes - br */
354 /*      jsr     pc,aexit */
355 /* not reached */
356 /* 1: */
357
358         if (errflg)
359                 aexit();
360
361 /*      inc     passno                  / go from -1 to 0 */
362 /*      clr     line                    / reset line number */
363 /*      jmp     pass1                   / pass1 does both passes 1, 2, exit */
364
365 #ifdef LISTING
366         printf("pass 1\n");
367 #endif
368         passno++;
369         line = 0;
370         pass1();
371 }
372
373 /* oops: */
374 /*      mov     $9f-8f,-(sp)            / write(fileno(stderr),8f,strlen()) */
375 /*      mov     $8f,-(sp) */
376 /*      mov     $2,-(sp) */
377 /*      jsr     pc,_write */
378 /*      mov     $2,(sp) */
379 /*      jsr     pc,__exit */
380 /*      .data */
381 /* 8: */
382 /*      <as: can't create tmpfile\n> */
383 /* 9: */
384 /*      .even */
385 /*      .text */
386
387 int oops() {
388         write(2, "as: can't create tmpfile\n", 25);
389         exit(2);
390 }
391
392 void nomem() {
393         write(2, "as: out of memory\n", 18);
394         aexit();
395 }
396
397 /* error: */
398
399 void error(code) int code; {
400         int i, j;
401         static char report[] = "f xxxx\n";
402
403 /*      tst     passno                  / on pass1,2 ? */
404 /*      bpl     errorp2 */
405
406 /* putchar('\n'); */
407  fflush(stdout);
408         if (passno < 0) {
409
410 /*      inc     errflg */
411
412                 errflg = 1;
413
414 /*      mov     r0,-(sp) */
415 /*      mov     r1,-(sp) */
416 /*      mov     r5,r0 */
417 /*      tst     *curarg */
418 /*      beq     1f */
419 /*      mov     r0,-(sp) */
420 /*      mov     *curarg,-(sp) */
421 /*      clr     *curarg */
422 /*      jsr     pc,filerr */
423 /*      tst     (sp)+ */
424 /*      mov     (sp)+,r0 */
425 /* 1: */
426
427                 if (*curarg) {
428                         filerr(*curarg);
429                         *curarg = NULL;
430                 }
431
432 /*      mov     r2,-(sp) */
433 /*      mov     r3,-(sp) */
434 /*      jsr     pc,errcmn */
435 /*      mov     (sp)+,r3 */
436 /*      mov     (sp)+,r2 */
437 /*      mov     (sp)+,r1 */
438 /*      mov     (sp)+,r0 */
439 /*      rts     pc */
440
441         }
442         else {
443
444 /* errorp2: */
445 /*      mov     pc,errflg */
446 /*      mov     $666,outmod             / make nonexecutable */
447
448                 errflg = 2;
449                 outmod = 0666;
450
451 /*      mov     r3,-(sp) */
452 /*      mov     r2,-(sp) */
453 /*      mov     r1,-(sp) */
454 /*      mov     r0,-(sp) */
455 /*      tst     -(sp)                   / write(1, argb, strlen(argb)) */
456 /*      mov     $argb,-(sp) */
457 /*      mov     $1,-(sp) */
458 /*      mov     $argb,r1 */
459 /*      clr     r0 */
460 /* 1: */
461 /*      tstb    (r1)+ */
462 /*      beq     2f */
463 /*      inc     r0 */
464 /*      br      1b */
465 /* 2: */
466 /*      mov     r0,4(sp) */
467 /*      jsr     pc,_write */
468 /*      add     $6,sp */
469
470                 if (*argb) {
471                         write(1, argb, strlen(argb));
472                         *argb = 0; /* a nick innovation */
473                 }
474
475 /*      movb    12(sp),r0 */
476 /*      jsr     pc,errcmn */
477 /*      mov     (sp)+,r0 */
478 /*      mov     (sp)+,r1 */
479 /*      mov     (sp)+,r2 */
480 /*      mov     (sp)+,r3 */
481 /*      mov     (sp)+,(sp) */
482 /*      rts     pc */
483
484         }
485
486 /* errcmn: */
487 /*      mov     line,r3 */
488 /*      movb    r0,9f */
489
490         j = line;
491         *report = code;
492
493 /*      mov     $9f+6,r0 */
494 /*      mov     $4,r1 */
495 /* 2: */
496 /*      clr     r2 */
497 /*      div     $10.,r2 */
498 /*      add     $'0,r3 */
499 /*      movb    r3,-(r0) */
500 /*      mov     r2,r3 */
501 /*      sob     r1,2b */
502
503         for (i = 0; i < 4; i++) {
504                 report[5 - i] = (j % 10) + '0';
505                 j /= 10;
506         }
507
508 /*      mov     $7,-(sp)                / write(1, 9f, 7) */
509 /*      mov     $9f,-(sp) */
510 /*      mov     $1,-(sp) */
511 /*      jsr     pc,_write */
512 /*      add     $6,sp */
513
514         write (1, report, 7);
515
516 /*      rts     pc */
517
518 }
519
520 /*      .data */
521 /* 9:   <f xxxx\n> */
522 /*      .even */
523 /*      .text */
524
525 /* p0putw: */
526
527 void p0putw(word) int word; {
528
529 /*      tst     ifflg */
530 /*      beq     1f */
531 /*      cmp     r4,$'\n */
532 /*      bne     2f */
533 /* 1: */
534
535 /* printf("p0putw(0%o)\n", word); */
536         if (ifflg == 0 || word == TNEWLINE)
537                 {
538
539 /*      mov     r4,*obufp */
540 /*      add     $2,obufp */
541 /*      cmp     obufp,$outbuf+1024. */
542 /*      blo     2f */
543 /*      mov     $outbuf,obufp */
544
545                 *obufp++ = word;
546                 if (obufp >= outbuf + 512) {
547                         obufp = outbuf;
548
549 /*      mov     r1,-(sp)                / protect r1 from library */
550 /*      mov     $1024.,-(sp)            / write(fout, outbuf, 1024) */
551 /*      mov     $outbuf,-(sp) */
552 /*      mov     fout,-(sp) */
553 /*      jsr     pc,_write */
554 /*      add     $6,sp */
555 /*      mov     (sp)+,r1 */
556 /*      tst     r0 */
557 /*      bpl     2f */
558 /*      jmp     wrterr */
559
560                         if (write(fout, outbuf, 512 * sizeof(short)) < 0)
561                                 wrterr();
562                 }
563         }
564
565 /* 2: */
566 /*      rts     pc */
567
568 }
569
570 /* Pass 0. */
571
572 /* pass0: */
573 /*      jsr     pc,p0readop */
574 /*      jsr     pc,checkeos */
575 /*              br 7f */
576
577 void pass0() {
578         intptr_t tokensave;
579         struct symbol *psymbol;
580         int label;
581
582         while (1) {
583                 p0readop();
584                 if (checkeos())
585                         goto ealoop;
586
587 /*      tst     ifflg */
588 /*      beq     3f */
589 /*      cmp     r4,$200 */
590 /*      blos    pass0 */
591 /*      cmpb    (r4),$21                /if */
592 /*      bne     2f */
593 /*      inc     ifflg */
594 /* 2: */
595 /*      cmpb    (r4),$22                /endif */
596 /*      bne     pass0 */
597 /*      dec     ifflg */
598 /*      br      pass0 */
599 /* 3: */
600
601                 if (ifflg) {
602                         if (token < 0 || token >= TASCII) {
603                                 psymbol = (struct symbol *)token;
604                                 switch (psymbol->flags) {
605                                 case FDOTIF:
606                                         ifflg++;
607                                         break;
608                                 case FDOTENDIF:
609                                         ifflg--;
610                                         break;
611                                 }
612                         }
613                         continue;
614                 }
615
616 /*      mov     r4,-(sp) */
617 /*      jsr     pc,p0readop */
618 /*      cmp     r4,$'= */
619 /*      beq     4f */
620 /*      cmp     r4,$': */
621 /*      beq     1f */
622 /*      mov     r4,savop */
623 /*      mov     (sp)+,r4 */
624 /*      jsr     pc,opline */
625 /*      br      ealoop */
626
627                 tokensave = token;
628 #ifdef TRANSLATE
629  xstartpsave = xstartp;
630  xbufpsave = xbufp;
631 #endif
632                 p0readop();
633                 if (token == TEQUAL)
634                         goto equal;
635                 if (token == TCOLON)
636                         goto colon;
637                 savop = token;
638 #ifdef TRANSLATE
639  xsavestartn = xstartp - xbufpsave;
640  xsavebufn = xbufp - xbufpsave;
641  memcpy(xsave, xbufpsave, xsavebufn);
642 #endif
643                 token = tokensave;
644 #ifdef TRANSLATE
645  xstartp = xstartpsave;
646  xbufp = xbufpsave;
647 #endif
648                 p0opline();
649                 goto ealoop;
650
651 /* 1: */
652 /*      mov     (sp)+,r4 */
653 /*      cmp     r4,$200 */
654 /*      bhis    1f */
655 /*      cmp     r4,$1                   / digit */
656 /*      beq     3f */
657 /*      mov     $'x,r5 */
658 /*      jsr     pc,error */
659 /*      br      pass0 */
660 /* 1: */
661
662         colon:
663                 if (tokensave >= 0 && tokensave < TASCII) {
664                         if (tokensave != TABS) {
665                                 error('x');
666                                 continue;
667                         }
668                         goto digit;
669                 }
670
671 /*      bitb    $37,(r4) */
672 /*      beq     1f */
673 /*      mov     $'m,r5 */
674 /*      jsr     pc,error */
675 /* 1: */
676
677                 psymbol = (struct symbol *)tokensave;
678                 if (psymbol->flags & 037)
679                         error('m');
680
681 /*      bisb    dot-2,(r4) */
682 /*      mov     dot,2(r4) */
683 /*      br      pass0 */
684
685                 psymbol->flags |= pdot->flags;
686                 psymbol->value = pdot->value;
687 #ifdef TRANSLATE
688  // reset locals
689  // for asxlat, -u means local labels will be changed to ordinary labels
690  // (use this when there is an inconvenient ordinary label within locals)
691  if (defund != FGLOBAL) {
692   xlabnext = 0;
693   memset(xlabb, 0xff, 10 * sizeof(int));
694   memset(xlabf, 0xff, 10 * sizeof(int));
695  }
696 #endif
697                 continue;
698
699 /* 3: */
700 /*      mov     numval,r0 */
701 /*      jsr     pc,fbcheck */
702 /*      movb    dotrel,curfbr(r0) */
703 /*      asl     r0 */
704 /*      movb    dotrel,nxtfb */
705 /*      mov     dot,nxtfb+2 */
706 /*      movb    r0,nxtfb+1 */
707 /*      mov     dot,curfb(r0) */
708
709         digit:
710                 label = fbcheck(numval);
711                 curfbr[label] = pdot->flags;
712                 curfb[label] = pdot->value;
713 #ifdef TRANSLATE
714  if (xlabf[label] == -1)
715   xlab = xlabnext++;
716  else {
717   xlab = xlabf[label];
718   xlabf[label] = -1;
719  }
720  xlabb[label] = xlab;
721  if (xstartpsave >= xbuf + 0xff0)
722   abort();
723  // for asxlat, -u means local labels will be changed to ordinary labels
724  // (use this when there is an inconvenient ordinary label within locals)
725  if (defund == FGLOBAL)
726   xbufp = xstartpsave + sprintf(xstartpsave, "_%d:", xlab);
727  else
728   xbufp = xstartpsave + sprintf(xstartpsave, "%d$:", xlab);
729 #endif
730
731 /*      cmp     fbfree,$4               / room for another fb entry? */
732 /*      bge     5f                      / yes - br */
733 /*      jsr     pc,growfb               / no - grow the table */
734 /* 5: */
735                 if (fbfree == 0)
736                         growfb();
737
738 /*      sub     $4,fbfree               / four bytes less available */
739 /*      mov     nxtfb,*fbptr            / store first word */
740 /*      add     $2,fbptr                / advance to next */
741 /*      mov     nxtfb+2,*fbptr          / store second word */
742 /*      add     $2,fbptr                / point to next entry */
743 /*      br      pass0 */
744
745                 fbfree--;
746                 fbptr->name = NULL;
747                 fbptr->flags = pdot->flags;
748                 fbptr->value = pdot->value;
749                 fbptr->number = label;
750                 fbptr++;
751                 continue;
752
753 /* 4: */
754 /*      jsr     pc,p0readop */
755 /*      jsr     pc,expres */
756 /*      mov     (sp)+,r1 */
757 /*      cmp     r1,$200 */
758 /*      bhis    1f */
759 /*      mov     $'x,r5 */
760 /*      jsr     pc,error */
761 /* 7: */
762 /*      br      ealoop */
763
764         equal:
765                 p0readop();
766                 p0expres();
767                 if (tokensave >= 0 && tokensave < TASCII) {
768                         error('x');
769                         goto ealoop;
770                 }
771
772 /* 1: */
773 /*      cmp     r1,$dotrel */
774 /*      bne     2f */
775 /*      bic     $40,r3 */
776 /*      cmp     r3,dotrel */
777 /*      bne     1f */
778 /* 2: */
779
780                 psymbol = (struct symbol *)tokensave;
781                 if (psymbol == pdot) {
782                         leftflags &= ~FGLOBAL;
783 /* printf("leftflags 0%o pdot->flags 0%o\n", leftflags, pdot->flags); */
784                         if (leftflags != pdot->flags)
785                                 goto doterr;
786 #ifdef TRANSLATE
787  xrestn = xbufp - xwhitep;
788  memcpy(xrest, xwhitep, xrestn);
789  if (xstartpsave + xrestn >= xbuf + 0xff0)
790   abort();
791  xbufp = xstartpsave + sprintf(xstartpsave, ".ds\t%d", leftvalue);
792  memcpy(xbufp, xrest, xrestn);
793  xbufp += xrestn;
794 #endif
795                 }
796
797 /*      bicb    $37,(r1) */
798 /*      bic     $!37,r3 */
799 /*      bne     2f */
800 /*      clr     r2 */
801 /* 2: */
802
803                 psymbol->flags &= ~037;
804                 leftflags &= 037;
805                 if (leftflags == 0)
806                         leftvalue = 0;
807
808 /*      bisb    r3,(r1) */
809 /*      mov     r2,2(r1) */
810 /*      br      ealoop */
811
812                 psymbol->flags |= leftflags;
813                 psymbol->value = leftvalue;
814                 goto ealoop;
815
816 /* 1: */
817 /*      mov     $'.,r5 */
818 /*      jsr     pc,error */
819 /*      movb    $2,dotrel */
820
821         doterr:
822                 error('.');
823                 pdot->flags = FTEXT;
824
825 /* ealoop: */
826 /*      cmp     r4,$'; */
827 /*      beq     9f */
828 /*      cmp     r4,$'\n */
829 /*      bne     1f */
830 /*      inc     line */
831 /*      br      9f */
832 /* 1: */
833
834         ealoop:
835 /* printf("ealoop token = 0x%08x\n", token); */
836                 if (token == TSEMICOLON)
837  {
838 #ifdef TRANSLATE
839  xbufp[-1] = '\n';
840
841  // read and ignore whitespace after ;
842  xstartp = xbufp;
843  while (1) {
844   label = rch();
845   if (label != '\t' && label != ' ')
846    break;
847  }
848  ch = label;
849  xbufp = xstartp;
850 #endif
851                         continue;
852  }
853                 if (token == TNEWLINE) {
854                         line++;
855                         continue;
856                 }
857
858 /*      cmp     r4,$'\e */
859 /*      bne     2f */
860 /*      tst     ifflg */
861 /*      beq     1f */
862 /*      mov     $'x,r5 */
863 /*      jsr     pc,error */
864 /* 1: */
865 /*      rts     pc */
866 /* 2: */
867 /*      mov     $'x,r5 */
868 /*      jsr     pc,error */
869
870                 if (token == TENDFILE) {
871                         if (ifflg)
872                                 error('x');
873                         break;
874                 }
875                 error('x');
876
877 /* 2: */
878 /*      jsr     pc,checkeos */
879 /*              br 9f */
880 /*      jsr     pc,p0readop */
881 /*      br      2b */
882 /* 9: */
883 /*      jmp     pass0 */
884
885                 while (checkeos() == 0)
886                         p0readop();
887         }
888 }
889
890 /* fbcheck: */
891 /*      cmp     r0,$9. */
892 /*      bhi     1f */
893 /*      rts     pc */
894 /* 1: */
895 /*      mov     $'f,r5 */
896 /*      jsr     pc,error */
897 /*      clr     r0 */
898 /*      rts     pc */
899
900 int fbcheck(label) int label; {
901         if (label < 10)
902                 return label;
903         error('f');
904         return 0;
905 }
906
907 /* the 'fb' table never grows to be large.  In fact all of the assemblies */
908 /* of C compiler generated code which were processed by 'c2' never */
909 /* produced a table larger than 0 bytes.  So we 'realloc' because */
910 /* this is not done enough to matter. */
911
912 /* growfb: */
913 /*      mov     r1,-(sp)                / save r1 from library */
914 /*      add     $256.,fbtblsz           / new size of fb table */
915 /*      mov     $256.,fbfree            / number available now */
916
917 void growfb() {
918         fbtblsz += 64;
919         fbfree = 64;
920
921 /*      mov     fbtblsz,-(sp)           / fbtbl = realloc(fbtbl, fbtblsz); */
922 /*      mov     fbtbl,-(sp) */
923 /*      bne     1f                      / extending table - br */
924 /*      mov     $1,(sp)                 / r0 = calloc(1, fbtblsz); */
925 /*      jsr     pc,_calloc */
926 /*      br      2f */
927 /* 1: */
928 /*      jsr     pc,_realloc */
929 /* 2: */
930 /*      cmp     (sp)+,(sp)+ */
931 /*      mov     r0,fbtbl */
932
933         if (fbtbl == NULL)
934                 fbtbl = (struct symbol *)calloc(fbtblsz, sizeof(struct symbol));
935         else
936                 fbtbl = (struct symbol *)realloc(fbtbl, fbtblsz * sizeof(struct symbol));
937
938 /*      bne     1f */
939 /*      iot                             / Can never happen (I hope) */
940 /* 1: */
941
942         if (fbtbl == NULL)
943                 nomem();
944
945 /*      add     fbtblsz,r0              / fbptr starts 256 bytes from */
946 /*      sub     $256.,r0                / end of new region */
947 /*      mov     r0,fbptr */
948 /*      mov     (sp)+,r1                / restore register */
949 /*      rts     pc */
950
951         fbptr = fbtbl + fbtblsz - 64;
952 }
953
954 /* Symbol table lookup and hashtable maintenance. */
955
956 /* rname: */
957 /*      mov     r1,-(sp) */
958 /*      mov     r2,-(sp) */
959 /*      mov     r3,-(sp) */
960
961 void rname() {
962         int count;
963         char *p;
964         int local;
965         int hash, c;
966         int timesaround;
967         struct symbol *psymbol;
968         struct symbol **ppsymbol;
969         int len;
970
971 /*      movb    Ncps,r5                 / Max num of chars to accept */
972 /*      mov     $symbol,r2 */
973 /*      clr     (r2) */
974
975 /* printf("rname()\n"); */
976         count = Ncps;
977         p = symbol;
978         *p = 0;
979
980 /*      clr     -(sp) */
981 /*      clr     -(sp) */
982
983         local = 0;
984         hash = 0;
985
986 /*      cmp     r0,$'~                  / symbol not for hash table? */
987 /*      bne     1f                      / no - br */
988 /*      inc     2(sp) */
989 /*      clr     ch */
990
991         if (ch == '~') {
992                 local = 1;
993                 ch = 0;
994 #ifdef TRANSLATE
995  // in C compiler output, local symbols are debugging information
996  // and are only defined not referenced, comment the definitions
997  if (xbufp >= xbuf + 0x1000)
998   abort();
999  *xbufp++ = ';';
1000 #endif
1001         }
1002
1003 /* 1: */
1004 /*      jsr     pc,rch */
1005 /*      movb    chartab(r0),r3 */
1006 /*      ble     1f */
1007 /*      add     r3,(sp) */
1008 /*      swab    (sp) */
1009 /*      dec     r5 */
1010 /*      blt     1b */
1011 /*      movb    r3,(r2)+ */
1012 /*      br      1b */
1013 /* 1: */
1014
1015         while (1) {
1016                 c = rch();
1017                 if (chartab[c] <= 0)
1018                         break;
1019                 hash += c;
1020                 hash = ((hash >> 8) & 0377) | ((hash & 0377) << 8);
1021                 if (count) {
1022                         count--;
1023                         *p++ = c;
1024                 }
1025  /* bug!! should stop accumulating hash when count == 0 */
1026         }
1027
1028 /*      clrb    (r2)+                   / null terminate string */
1029 /*      movb    r0,ch */
1030
1031         *p++ = 0;
1032 /* printf("symbol = \"%s\"\n", symbol); */
1033         ch = c;
1034 #ifdef TRANSLATE
1035  if (xbufp <= xbuf)
1036   abort();
1037  --xbufp;
1038 #endif
1039 /* if (ch) printf("a push 0x%02x\n", ch); */
1040
1041 /*      mov     (sp)+,r1 */
1042 /*      clr     r0 */
1043 /*      tst     (sp)+ */
1044 /*      beq     1f */
1045 /*      mov     symend,r4 */
1046 /*      br      4f                      / go insert into symtable (!hashtbl) */
1047 /* 1: */
1048
1049         if (local) {
1050                 psymbol = isroom(symend); /* symend; */
1051                 goto insert;
1052         }
1053
1054 /*      div     $hshsiz,r0 */
1055 /*      ashc    $1,r0 */
1056 /*      add     hshtab,r1 */
1057 /*      clr     timesaround */
1058
1059         ppsymbol = hshtab + (hash % hshsiz);
1060         hash /= hshsiz;
1061         timesaround = 0;
1062
1063 /* 1: */
1064 /*      sub     r0,r1 */
1065 /*      cmp     r1,hshtab */
1066 /*      bhi     2f */
1067 /*      add     $2*hshsiz,r1 */
1068
1069         while (1) {
1070                 ppsymbol -= hash;
1071                 if (ppsymbol <= hshtab) {
1072                         ppsymbol += hshsiz;
1073
1074 /*      tst     timesaround */
1075 /*      beq     3f */
1076 /*      mov     $8f-9f,-(sp)            / write(fileno(stdout),9f,8f-9f); */
1077 /*      mov     $9f,-(sp) */
1078 /*      mov     $1,-(sp) */
1079 /*      jsr     pc,_write */
1080 /*      add     $6,sp */
1081 /*      jsr     pc,aexit */
1082 /* not reached */
1083
1084                         if (timesaround) {
1085                                 write(2, "as: symbol table overflow\n", 26);
1086                                 aexit();
1087                         }
1088
1089 /*      .data */
1090 /* timesaround: 0 */
1091 /* 9: */
1092 /*      <as: symbol table overflow\n> */
1093 /* 8: */
1094 /*      .even */
1095 /*      .text */
1096 /* 3: */
1097 /*      inc     timesaround */
1098
1099                         timesaround = 1;
1100                 }
1101
1102 /* 2: */
1103 /*      mov     $symbol,r2 */
1104 /*      mov     -(r1),r4 */
1105 /*      beq     3f */
1106 /*      mov     (r4)+,r3                / ptr to symbol's name */
1107 /* 9: */
1108 /*      cmpb    (r2),(r3)+ */
1109 /*      bne     1b                      / not the right symbol - br */
1110 /*      tstb    (r2)+                   / at end of symbol? */
1111 /*      bne     9b                      / nope - keep looking */
1112 /*      br      1f                      / yep - br */
1113
1114                 psymbol = *--ppsymbol;
1115                 if (psymbol == NULL)
1116                         break;
1117                 if (!strcmp(symbol, psymbol->name))
1118                         goto found;
1119         }
1120
1121 /* 3: */
1122 /*      mov     symend,r4 */
1123 /*      jsr     pc,isroom               / make sure there's room in block */
1124 /*      mov     r4,(r1) */
1125 /* 4: */
1126 /*      jsr     pc,isroom               / check for room in current block */
1127
1128         psymbol = isroom(symend);
1129         *ppsymbol = psymbol;
1130 insert:
1131         /* isroom(psymbol); */
1132
1133 /*      mov     $symbol,r2              / length of string (including null) */
1134 /* 8 : */
1135 /*      tstb    (r2)+ */
1136 /*      bne     8b */
1137 /*      sub     $symbol,r2 */
1138 /*      jsr     pc,astring              / allocate string space */
1139 /*      mov     r0,(r4)+                / save string pointer in symtab entry */
1140 /*      mov     $symbol,r1 */
1141 /* 9: */
1142 /*      movb    (r1)+,(r0)+             / copy symbol name to string block */
1143 /*      bne     9b */
1144 /*      sub     $SYMENTSZ,symleft */
1145
1146         len = strlen(symbol) + 1;
1147         p = astring(len);
1148         psymbol->name = p;
1149         memcpy(p, symbol, len);
1150         symleft--;
1151
1152 /* each new symbol is assigned a unique one up number.  This is done because */
1153 /* the user symbol table is no longer contiguous - the symbol number can */
1154 /* not be calculated by subtracting a base address and dividing by the */
1155 /* size of a symbol. */
1156
1157 /*      clr     (r4)+                   / flags word */
1158 /*      clr     (r4)+                   / value word */
1159 /*      mov     symnum,(r4)+ */
1160 /*      inc     symnum */
1161 /*      mov     r4,symend */
1162 /*      sub     $6,r4                   / point to flags word */
1163
1164         psymbol->flags = 0; /* redundant */
1165         psymbol->value = 0; /* redundant */
1166         psymbol->number = symnum++;
1167         symend = psymbol + 1;
1168
1169 /* 1: */
1170 /*      mov     r4,-(sp) */
1171 /*      mov     r4,r3 */
1172 /*      tst     -(r3)                   / back to beginning of entry */
1173 /*      cmp     r3,$ebsymtab            / Permanent Symbol Table(opcode, etc)? */
1174 /*      blo     1f                      / yes - br */
1175 /*      mov     6(r3),r4                / get symbol number */
1176 /*      add     $4000,r4                / user symbol flag */
1177 /*      br      2f */
1178 /* 1: */
1179
1180 /* PST entries are PSTENTSZ bytes each because they do not have a 'symnum' */
1181 /* entry associated with them. */
1182
1183 /*      sub     $symtab,r3 */
1184 /*      clr     r2 */
1185 /*      div     $PSTENTSZ,r2 */
1186 /*      mov     r2,r4 */
1187 /*      add     $1000,r4                / builtin symbol */
1188
1189 /* 2: */
1190 /*      jsr     pc,p0putw */
1191
1192 found:
1193         if (psymbol >= symtab + ebsymtab)
1194                 p0putw(04000 + psymbol->number);
1195         else
1196                 p0putw(01000 + (psymbol - symtab));
1197
1198 /*      mov     (sp)+,r4 */
1199 /*      mov     (sp)+,r3 */
1200 /*      mov     (sp)+,r2 */
1201 /*      mov     (sp)+,r1 */
1202 /*      tst     (sp)+ */
1203 /*      rts     pc */
1204
1205         token = (intptr_t)psymbol;
1206 }
1207
1208 /* isroom: */
1209 /*      cmp     symleft,$SYMENTSZ       / room for another symbol? */
1210 /*      bge     1f                      / yes - br */
1211
1212 struct symbol *isroom(psymbol) struct symbol *psymbol; {
1213         struct symblk *psymblk;
1214
1215 /* printf("isroom(0x%08x) symleft = %d\n", psymbol, symleft); */
1216         if (symleft == 0) {
1217
1218 /*      mov     r1,-(sp)                / save from library */
1219 /*      mov     $SYMBLKSZ+2,-(sp)       / size of sym block plus link word */
1220 /*      mov     $1,-(sp)                / number of blocks to allocate */
1221 /*      jsr     pc,_calloc              / calloc(1, SYMBLKSZ+2); */
1222 /*      cmp     (sp)+,(sp)+ */
1223 /*      / check for failure? */
1224
1225                 psymblk = (struct symblk *)calloc(1, sizeof(struct symblk));
1226                 if (psymblk == NULL)
1227                         nomem();
1228
1229 /*      mov     r0,*symblk              / link new block to old */
1230 /*      mov     r0,symblk               / this is now the current block */
1231 /*      tst     (r0)+                   / skip link word */
1232 /*      mov     $SYMBLKSZ,symleft       / number of bytes available */
1233 /*      mov     r0,r4                   / put where it's expected */
1234
1235                 symblk->next = psymblk;
1236                 symblk = psymblk;
1237                 symleft = SYMBLKSZ;
1238                 return psymblk->data;
1239
1240 /*      mov     (sp)+,r1                / restore saved register */
1241 /* 1: */
1242 /*      rts     pc                      / return */
1243
1244         }
1245         return psymbol;
1246 }
1247
1248 /* allocate room for a string, the length is in R2 and includes room for */
1249 /* a terminating null byte. */
1250
1251 /* astring: */
1252 /*      cmp     r2,strleft              / room in current block? */
1253 /*      ble     1f                      / yes - go carve out a chunk */
1254
1255 char *astring(len) int len; {
1256         struct strblk *pstrblk;
1257         char *p;
1258
1259 /* printf("astring(%d) strleft = %d\n", len, strleft); */
1260         if (len > strleft) {
1261
1262 /*      mov     $STRBLKSZ+2,-(sp) */
1263 /*      mov     $1,-(sp) */
1264 /*      jsr     pc,_calloc              / symblk = calloc(1,STRBLKSZ+2) */
1265 /*      / check for failure? */
1266 /*      cmp     (sp)+,(sp)+ */
1267
1268                 pstrblk = (struct strblk *)calloc(1, sizeof(struct strblk));
1269                 if (pstrblk == NULL)
1270                         nomem();
1271
1272 /*      mov     r0,*strblk              / update forward link between blocks */
1273 /*      mov     r0,strblk               / update current string block pointer */
1274 /*      tst     (r0)+                   / skip link word */
1275 /*      mov     r0,strend               / current data pointer */
1276 /*      mov     $STRBLKSZ,strleft       / amount of space left */
1277
1278                 strblk->next = pstrblk;
1279                 strblk = pstrblk;
1280                 strleft = STRBLKSZ;
1281                 strend = strblk->data;
1282
1283 /* 1: */
1284 /*      mov     strend,r0               / string address */
1285 /*      add     r2,strend               / update current end point */
1286 /*      sub     r2,strleft              / update amount of space left */
1287 /*      rts     pc */
1288
1289         }
1290         p = strend;
1291         strend += len;
1292         strleft -= len;
1293         return p;
1294 }
1295
1296 /* number: */
1297 /*      mov     r2,-(sp) */
1298 /*      mov     r3,-(sp) */
1299 /*      mov     r5,-(sp) */
1300 /*      clr     r1 */
1301 /*      clr     r5 */
1302
1303 int number() {
1304         int octal;
1305         int decimal;
1306         int c;
1307
1308         octal = 0;
1309         decimal = 0;
1310
1311 /* 1: */
1312 /*      jsr     pc,rch */
1313 /*      cmp     r0,$'0 */
1314 /*      blt     1f */
1315 /*      cmp     r0,$'9 */
1316 /*      bgt     1f */
1317 /*      sub     $'0,r0 */
1318 /*      mul     $10.,r5 */
1319 /*      add     r0,r5 */
1320 /*      ash     $3,r1 */
1321 /*      add     r0,r1 */
1322 /*      br      1b */
1323
1324 #ifdef TRANSLATE
1325  xstartp = xbufp;
1326 #endif
1327         while (1) {
1328                 c = rch();
1329                 if (c < '0' || c > '9')
1330                         break;
1331                 c -= '0';
1332                 decimal = decimal * 10 + c;
1333                 octal = octal * 8 + c;
1334         }
1335
1336 /* 1: */
1337 /*      cmp     r0,$'b */
1338 /*      beq     1f */
1339 /*      cmp     r0,$'f */
1340 /*      beq     1f */
1341 /*      cmp     r0,$'. */
1342 /*      bne     2f */
1343 /*      mov     r5,r1 */
1344 /*      clr     r0 */
1345 /* 2: */
1346
1347         if (c == 'b' || c == 'f')
1348                 goto label;
1349         if (c == '.') {
1350 #ifdef TRANSLATE
1351  if (xstartp >= xbuf + 0xff0)
1352   abort();
1353  xbufp = xstartp + sprintf(xstartp, "%d", decimal);
1354 #endif
1355                 octal = decimal;
1356                 c = 0;
1357         }
1358 #ifdef TRANSLATE
1359  else {
1360   if (xstartp >= xbuf + 0xff0)
1361    abort();
1362   xbufp = xstartp + sprintf(xstartp, "%s%o", (octal & ~7) ? "0o" : "", octal);
1363  }
1364 #endif
1365
1366 /*      movb    r0,ch */
1367 /*      mov     r1,r0 */
1368
1369         ch = c;
1370 #if 0 //def TRANSLATE
1371  if (c) {
1372   if (xbufp <= xbuf)
1373    abort();
1374   --xbufp;
1375  }
1376 #endif
1377 /* if (ch) printf("b push 0x%02x\n", ch); */
1378         numbervalue = octal;
1379
1380 /*      mov     (sp)+,r5 */
1381 /*      mov     (sp)+,r3 */
1382 /*      mov     (sp)+,r2 */
1383 /*      rts     pc */
1384
1385         return 1;
1386
1387 /* 1: */
1388 /*      mov     r0,r3 */
1389 /*      mov     r5,r0 */
1390 /*      jsr     pc,fbcheck */
1391 /*      add     $141,r0 */
1392 /*      cmp     r3,$'b */
1393 /*      beq     1f */
1394 /*      add     $10.,r0 */
1395 /* 1: */
1396
1397 label:
1398         numbertoken = fbcheck(decimal) + TLABEL;
1399         if (c != 'b')
1400                 numbertoken += 10;
1401
1402 /*      mov     r0,r4 */
1403 /*      mov     (sp)+,r5 */
1404 /*      mov     (sp)+,r3 */
1405 /*      mov     (sp)+,r2 */
1406 /*      add     $2,(sp) */
1407 /*      rts     pc */
1408
1409         return 0;
1410 }
1411
1412 /* rch: */
1413 /*      movb    ch,r0 */
1414 /*      beq     1f */
1415 /*      clrb    ch */
1416 /*      rts     pc */
1417
1418 int rch() {
1419         int c;
1420         char *p;
1421
1422 /* printf("rch() ch = 0x%02x\n", ch); */
1423         if (ch) {
1424                 c = ch;
1425                 ch = 0;
1426 #ifdef TRANSLATE
1427  //if (xbufp > xbuf && xbufp[-1] == '\n') {
1428  // write(1, xbuf, xbufp - xbuf);
1429  // xbufp = xbuf;
1430  //}
1431  //else
1432  if (xbufp >= xbuf + 0x1000)
1433   abort();
1434  *xbufp++ = c;
1435 #endif
1436                 return c;
1437         }
1438
1439 /* 1: */
1440 /*      dec     ibufc */
1441 /*      blt     2f */
1442 /*      movb    *ibufp,r0 */
1443 /*      inc     ibufp */
1444 /*      bic     $!177,r0 */
1445 /*      beq     1b */
1446 /*      rts     pc */
1447
1448         while (1) {
1449                 ibufc--;
1450                 if (ibufc < 0)
1451                         goto refill;
1452                 c = *p0ibufp++ & 0177;
1453 /* putchar(c); */
1454                 if (c == 0)
1455                         continue;
1456 #ifdef TRANSLATE
1457  //if (xbufp > xbuf && xbufp[-1] == '\n') {
1458  // write(1, xbuf, xbufp - xbuf);
1459  // xbufp = xbuf;
1460  //}
1461  //else
1462  if (xbufp >= xbuf + 0x1000)
1463   abort();
1464  *xbufp++ = c;
1465 #endif
1466                 return c;
1467
1468 /* 2: */
1469 /*      mov     fin,r0 */
1470 /*      bmi     3f */
1471
1472         refill:
1473                 if (fin >= 0) {
1474
1475 /*      mov     r1,-(sp)                / protect r1 from library */
1476 /*      mov     $1024.,-(sp)            / read(fin, inbuf, 1024) */
1477 /*      mov     $inbuf,-(sp) */
1478 /*      mov     r0,-(sp) */
1479 /*      jsr     pc,_read */
1480 /*      add     $6,sp */
1481 /*      mov     (sp)+,r1 */
1482
1483                         ibufc = read(fin, inbuf, 1024);
1484
1485 /*      tst     r0 */
1486 /*      ble     2f */
1487 /*      mov     r0,ibufc */
1488 /*      mov     $inbuf,ibufp */
1489 /*      br      1b */
1490 /* 2: */
1491
1492                         if (ibufc > 0) {
1493                                 p0ibufp = inbuf;
1494                                 continue;
1495                         }
1496
1497 /*      mov     r1,-(sp)                / protect r1 from library */
1498 /*      mov     fin,-(sp)               / close(r0) */
1499 /*      jsr     pc,_close */
1500 /*      tst     (sp)+ */
1501 /*      mov     $-1,fin */
1502 /*      mov     (sp)+,r1 */
1503
1504                         close(fin);
1505                         fin = -1;
1506                 }
1507
1508 /* 3: */
1509 /*      dec     nargs */
1510 /*      bge     2f */
1511 /*      mov     $'\e,r0 */
1512 /*      rts     pc */
1513 /* 2: */
1514
1515                 if (nargs == 0)
1516                         return 004;
1517                 nargs--;
1518
1519 /*      tst     ifflg */
1520 /*      beq     2f */
1521 /*      mov     $'i,r5 */
1522 /*      jsr     pc,error */
1523 /*      jsr     pc,aexit */
1524 /* not reached */
1525 /* 2: */
1526
1527                 if (ifflg) {
1528                         error('i');
1529                         aexit();
1530                 }
1531
1532 /* check for the filename arguments of "-" or "--", these mean to read 'stdin'. */
1533 /* Additional filenames are permitted and will be processed when EOF */
1534 /* is detected on stdin. */
1535 /*      mov     *curarg,r0 */
1536 /*      cmpb    (r0)+,$'- */
1537 /*      bne     5f                      / not the special case - br */
1538 /*      tstb    (r0)                    / must be '-' by itself */
1539 /*      beq     4f */
1540 /*      cmpb    (r0)+,$'-               / check for "--" */
1541 /*      bne     5f                      / not a double -, must be a filename */
1542 /*      tstb    (r0)                    / null terminated? */
1543 /*      bne     5f                      / no - must be a filename */
1544 /* 4: */
1545 /*      clr     fin                     / file descriptor is 0 for stdin */
1546 /*      br      2f */
1547 /* 5: */
1548
1549                 p = *curarg;
1550                 if (*p++ == '-' && (*p == 0 || (*p++ == '-' && *p == 0))) {
1551                         fin = 0;
1552                         goto reset;
1553                 }
1554
1555 /*      mov     r1,-(sp)                / protect r1 from library */
1556 /*      clr     -(sp)                   / open((r0), O_RDONLY, 0) */
1557 /*      clr     -(sp) */
1558 /*      mov     *curarg,-(sp) */
1559 /*      jsr     pc,_open */
1560 /*      add     $6,sp */
1561 /*      mov     (sp)+,r1 */
1562
1563                 fin = open(*curarg, O_RDONLY);
1564
1565 /*      mov     r0,fin */
1566 /*      bpl     2f */
1567 /*      mov     *curarg,-(sp) */
1568 /*      jsr     pc,filerr */
1569 /*      tst     (sp)+ */
1570 /*      jsr     pc,aexit */
1571 /*not reached */
1572
1573                 if (fin < 0) {
1574                         filerr(*curarg);
1575                         aexit();
1576                 }
1577
1578 /* 2: */
1579 /*      mov     $1,line */
1580 /*      mov     r4,-(sp) */
1581 /*      mov     r1,-(sp) */
1582 /*      mov     $5,r4 */
1583 /*      jsr     pc,p0putw */
1584
1585         reset:
1586                 line = 1;
1587                 token = TNEWFILE;
1588                 p0putw(token);
1589
1590 /*      mov     *curarg,r1 */
1591 /* 2: */
1592 /*      movb    (r1)+,r4 */
1593 /*      beq     2f */
1594 /*      jsr     pc,p0putw */
1595 /*      br      2b */
1596 /* 2: */
1597 /*      add     $2,curarg */
1598 /*      mov     $-1,r4 */
1599 /*      jsr     pc,p0putw */
1600
1601                 p = *curarg++;
1602                 while (1) {
1603                         c = *p++;
1604                         if (c == 0)
1605                                 break;
1606                         p0putw(c);
1607                 }
1608                 p0putw(-1);
1609
1610 /*      mov     (sp)+,r1 */
1611 /*      mov     (sp)+,r4 */
1612 /*      br      1b */
1613
1614         }
1615 }
1616
1617 /* p0readop: */
1618 /*      mov     savop,r4 */
1619 /*      beq     1f */
1620 /*      clr     savop */
1621 /*      rts     pc */
1622 /* 1: */
1623 /*      jsr     pc,8f */
1624 /*      jsr     pc,p0putw */
1625 /*      rts     pc */
1626
1627 void p0readop() {
1628         int c;
1629
1630 /* printf("p0readop() savop = 0x%08x\n", savop); */
1631 #ifdef TRANSLATE
1632  xwhitep = xbufp;
1633 #endif
1634         if (savop) {
1635                 token = savop;
1636                 savop = 0;
1637 #ifdef TRANSLATE
1638  if (xbufp + xsavebufn >= xbuf + 0x1000)
1639   abort();
1640  memcpy(xbufp, xsave, xsavebufn);
1641  xstartp = xbufp + xsavestartn;
1642  xbufp = xbufp + xsavebufn;
1643 #endif
1644                 return;
1645         }
1646
1647 /* 8: */
1648 /*      jsr     pc,rch */
1649 /*      mov     r0,r4 */
1650 /*      movb    chartab(r0),r1 */
1651 /*      bgt     rdname */
1652 /*      jmp     *1f-2(r1) */
1653
1654         while (1) {
1655 #ifdef TRANSLATE
1656  xstartp = xbufp;
1657 #endif
1658                 c = rch();
1659                 switch (chartab[c]) {
1660                 default:
1661                         rdname(c);
1662                         return;
1663
1664
1665 /*      .data */
1666 /*      fixor */
1667
1668                 case -026:
1669 #if 1 /* modifications for dec syntax */
1670                         if (c == '#')
1671                                 retread(TDOLL);
1672                         else if (c == '@')
1673                                 retread(TSTAR);
1674                         else
1675 #endif
1676                         fixor();
1677                         return;
1678
1679 /*      escp */
1680
1681                 case -024:
1682                         escp();
1683                         return;
1684
1685 /*      8b */
1686
1687                 case -022:
1688                         break;
1689
1690 /*      retread */
1691
1692                 case -020:
1693                         retread(c);
1694                         return;
1695
1696 /*      dquote */
1697
1698                 case -016:
1699                         dquote();
1700                         return;
1701
1702 /*      garb */
1703
1704                 case -014:
1705                         garb();
1706                         break;
1707
1708 /*      squote */
1709
1710                 case -012:
1711                         squote();
1712                         return;
1713
1714 /*      rdname */
1715
1716                 case -010:
1717                         rdname(c);
1718                         return;
1719
1720 /*      skip */
1721
1722                 case -006:
1723 #ifdef TRANSLATE
1724  xbufp[-1] = ';';
1725 #endif
1726                         skip();
1727                         return;
1728
1729 /*      rdnum */
1730
1731                 case -004: /* can never get here */
1732                         rdnum();
1733                         return;
1734
1735 /*      retread */
1736
1737                 case -002:
1738                         retread(c);
1739                         return;
1740
1741 /*      string */
1742
1743                 case -000:
1744                         string();
1745                         return;
1746
1747 /* 1: */
1748 /*      .text */
1749
1750                 }
1751         }
1752 }
1753
1754 /* escp: */
1755 /*      jsr     pc,rch */
1756 /*      mov     $esctab,r1 */
1757 /* 1: */
1758 /*      cmpb    r0,(r1)+ */
1759 /*      beq     1f */
1760 /*      tstb    (r1)+ */
1761 /*      bne     1b */
1762 /*      rts     pc */
1763 /* 1: */
1764 /*      movb    (r1),r4 */
1765 /*      rts     pc */
1766
1767 void escp() {
1768         int c;
1769
1770         c = rch();
1771         switch (c) {
1772
1773 /*      .data */
1774 /* esctab: */
1775 /*      .byte '/, '/ */
1776 /*      .byte '\<, 035 */
1777
1778         case '<':
1779                 retread(TLSH);
1780                 return;
1781
1782 /*      .byte '>, 036 */
1783
1784         case '>':
1785                 retread(TRSH);
1786                 return;
1787
1788 /*      .byte '%, 037 */
1789
1790         case '%':
1791                 retread(TOR);
1792                 return;
1793
1794 /*      .byte 0, 0 */
1795 /*      .text */
1796
1797         }
1798         retread(c);
1799 }
1800
1801 /* fixor: */
1802 /*      mov     $037,r4 */
1803 /* retread: */
1804 /*      rts     pc */
1805
1806 void fixor() {
1807         retread(TOR);
1808 }
1809
1810 void retread(c) int c; {
1811         token = c;
1812         p0putw(token);
1813 }
1814
1815 /* rdname: */
1816 /*      movb    r0,ch */
1817 /*      cmp     r1,$'0 */
1818 /*      blo     1f */
1819 /*      cmp     r1,$'9 */
1820 /*      blos    rdnum */
1821 /* 1: */
1822 /*      jmp     rname */
1823
1824 void rdname(c) int c; {
1825         ch = c;
1826 #ifdef TRANSLATE
1827  if (xbufp <= xbuf)
1828   abort();
1829  --xbufp;
1830 #endif
1831 /* if (ch) printf("c push 0x%02x\n", ch); */
1832         if (c >= '0' && c <= '9')
1833                 rdnum();
1834         else
1835                 rname();
1836 }
1837
1838 /* rdnum: */
1839 /*      jsr     pc,number */
1840 /*              br 1f */
1841 /*      rts     pc */
1842
1843 void rdnum() {
1844         if (number())
1845                 retnum(numbervalue);
1846         else
1847                 retread(numbertoken);
1848 }
1849
1850 /* squote: */
1851 /*      jsr     pc,rsch */
1852 /*      br      1f */
1853
1854 void squote() {
1855         retnum(rsch());
1856 }
1857
1858 /* dquote: */
1859 /*      jsr     pc,rsch */
1860 /*      mov     r0,-(sp) */
1861 /*      jsr     pc,rsch */
1862 /*      swab    r0 */
1863 /*      bis     (sp)+,r0 */
1864
1865 void dquote() {
1866         int c;
1867
1868         c = rsch();
1869         retnum(rsch() | (c << 8));
1870 }
1871
1872 /* 1: */
1873 /*      mov     r0,numval */
1874 /*      mov     $1,r4 */
1875 /*      jsr     pc,p0putw */
1876 /*      mov     numval,r4 */
1877 /*      jsr     pc,p0putw */
1878 /*      mov     $1,r4 */
1879 /*      tst     (sp)+ */
1880 /*      rts     pc */
1881
1882 void retnum(value) int value; {
1883         numval = value;
1884         token = TABS;
1885         p0putw(token);
1886         p0putw(numval);
1887 }
1888
1889 /* skip: */
1890 /*      jsr     pc,rch */
1891 /*      mov     r0,r4 */
1892 /*      cmp     r0,$'\e */
1893 /*      beq     1f */
1894 /*      cmp     r0,$'\n */
1895 /*      bne     skip */
1896 /* 1: */
1897 /*      rts     pc */
1898
1899 void skip() {
1900         int c;
1901
1902         do {
1903                 c = rch();
1904                 if (c == '\e') {
1905                         retread(TENDFILE);
1906                         return;
1907                 }
1908         } while (c != '\n');
1909         retread(TNEWLINE);
1910 }
1911
1912 /* garb: */
1913 /*      mov     $'g,r5 */
1914 /*      jsr     pc,error */
1915 /*      br      8b */
1916
1917 void garb() {
1918         error('g');
1919 }
1920
1921 /* string: */
1922 /*      mov     $'<,r4 */
1923 /*      jsr     pc,p0putw */
1924
1925 void string() {
1926         int c;
1927
1928         token = TSTRING;
1929         p0putw(token);
1930
1931 /*      clr     numval */
1932 /* 1: */
1933 /*      jsr     pc,rsch */
1934 /*      tst     r1 */
1935 /*      bne     1f */
1936 /*      mov     r0,r4 */
1937 /*      bis     $400,r4 */
1938 /*      jsr     pc,p0putw */
1939 /*      inc     numval */
1940 /*      br      1b */
1941 /* 1: */
1942
1943         numval = 0;
1944         while (1) {
1945                 c = rsch();
1946                 if (endflag)
1947                         break;
1948                 p0putw(0400 | c);
1949                 numval++;
1950         }
1951
1952 /*      mov     $-1,r4 */
1953 /*      jsr     pc,p0putw */
1954 /*      mov     $'<,r4 */
1955 /*      tst     (sp)+ */
1956 /*      rts     pc */
1957
1958         p0putw(-1);
1959 }
1960
1961 /* rsch: */
1962 /*      jsr     pc,rch */
1963
1964 int rsch() {
1965         int c;
1966
1967         c = rch();
1968
1969 /*      cmp     r0,$'\e */
1970 /*      beq     4f */
1971 /*      cmp     r0,$'\n */
1972 /*      beq     4f */
1973
1974         endflag = 0;
1975         if (c != 004 && c != '\n') {
1976
1977 /*      clr     r1 */
1978 /*      cmp     r0,$'\\ */
1979 /*      bne     3f */
1980 /*      jsr     pc,rch */
1981
1982                 if (c == '\\') {
1983                         c = rch();
1984
1985 /*      mov     $schar,r2 */
1986 /* 1: */
1987 /*      cmpb    (r2)+,r0 */
1988 /*      beq     2f */
1989 /*      tstb    (r2)+ */
1990 /*      bpl     1b */
1991 /*      rts     pc */
1992 /* 2: */
1993 /*      movb    (r2)+,r0 */
1994 /*      clr     r1 */
1995 /*      rts     pc */
1996
1997                         switch (c) {
1998                         case 'n':
1999                                 return 012;
2000                         case 's':
2001                                 return 040;
2002                         case 't':
2003                                 return 011;
2004                         case 'e':
2005                                 return 004;
2006                         case '0':
2007                                 return 000;
2008                         case 'r':
2009                                 return 015;
2010                         case 'a':
2011                                 return 006;
2012                         case 'p':
2013                                 return 033;
2014                         }
2015                         return c;
2016
2017 /* 3: */
2018 /*      cmp     r0,$'> */
2019 /*      bne     1f */
2020 /*      inc     r1 */
2021 /* 1: */
2022 /*      rts     pc */
2023
2024                 }
2025                 if (c == '>')
2026                         endflag = 1;
2027                 return c;
2028
2029 /* 4: */
2030 /*      mov     $'<,r5 */
2031 /*      jsr     pc,error */
2032 /*      jsr     pc,aexit */
2033 /* not reached */
2034
2035         }
2036         error('<');
2037         aexit();
2038         return 0; /* keep compiler happy */
2039 }
2040
2041 /*      .data */
2042 /* schar: */
2043 /*      .byte 'n, 012 */
2044 /*      .byte 's, 040 */
2045 /*      .byte 't, 011 */
2046 /*      .byte 'e, 004 */
2047 /*      .byte '0, 000 */
2048 /*      .byte 'r, 015 */
2049 /*      .byte 'a, 006 */
2050 /*      .byte 'p, 033 */
2051 /*      .byte 0,  -1 */
2052 /*      .text */
2053
2054 /* opline: */
2055 /*      mov     r4,r0 */
2056 /*      bmi     1f */
2057 /*      cmp     r0,$200 */
2058 /*      bgt     1f */
2059 /*      cmp     r0,$'< */
2060 /*      bne     xpr */
2061 /*      jmp     opl17 */
2062 /* xpr: */
2063 /*      jsr     pc,expres */
2064 /*      add     $2,dot */
2065 /*      rts     pc */
2066 /* 1: */
2067
2068 void p0xpr() {
2069         p0expres();
2070         pdot->value += 2;
2071 }
2072
2073 void p0opline() {
2074         struct symbol *psymbol;
2075         int flags;
2076
2077 /* printf("p0opline() token 0x%08x\n", token); */
2078 #if 0 //def TRANSLATE
2079  *xbufp = 0;
2080  printf("p0opline() token 0x%08x xstartp \"%s\"\n", token, xstartp);
2081  fflush(stdout);
2082 #endif
2083
2084         if (token >= 0 && token < TASCII) {
2085                 if (token == TSTRING)
2086  {
2087 #ifdef TRANSLATE
2088   xrestn = xbufp - xstartp;
2089   memcpy(xrest, xstartp, xrestn);
2090   xrest[0] = '/';
2091   xrest[xrestn - 1] = '/';
2092   if (xstartp + xrestn >= xbuf + 0xff0)
2093    abort();
2094   xbufp = xstartp + sprintf(xstartp, ".ascii    ");
2095   memcpy(xbufp, xrest, xrestn);
2096   xbufp += xrestn;
2097 #endif
2098                         p0opl17();
2099  }
2100                 else
2101  {
2102 #ifdef TRANSLATE
2103   xrestn = xbufp - xstartp;
2104   memcpy(xrest, xstartp, xrestn);
2105   if (xstartp + xrestn >= xbuf + 0xff0)
2106    abort();
2107   xbufp = xstartp + sprintf(xstartp, ".dw       ");
2108   xstartp = xbufp; // for local labels
2109   memcpy(xbufp, xrest, xrestn);
2110   xbufp += xrestn;
2111 #endif
2112                         p0xpr();
2113  }
2114                 return;
2115         }
2116
2117 /*      movb    (r4),r0 */
2118 /*      cmp     r0,$24 */
2119 /*      beq     xpr */
2120 /*      cmp     r0,$5 */
2121 /*      blt     xpr */
2122 /*      cmp     r0,$36 */
2123 /*      bgt     xpr */
2124
2125         psymbol = (struct symbol *)token;
2126         flags = psymbol->flags;
2127         if (flags <= FBSS || flags == FREGISTER || flags > FJCOND) {
2128 #ifdef TRANSLATE
2129  if (flags != FABS) { // assume for now that ABS symbol can only be an opcode
2130   xrestn = xbufp - xstartp;
2131   memcpy(xrest, xstartp, xrestn);
2132   if (xstartp + xrestn >= xbuf + 0xff0)
2133    abort();
2134   xbufp = xstartp + sprintf(xstartp, ".dw       ");
2135   xstartp = xbufp; // for local labels
2136   memcpy(xbufp, xrest, xrestn);
2137   xbufp += xrestn;
2138  }
2139 #endif
2140                 p0xpr();
2141                 return;
2142         }
2143 #ifdef TRANSLATE
2144  if (xstartp >= xbuf + 0xff0)
2145   abort();
2146  switch (flags) {
2147  case FDOTTEXT:
2148   xbufp = xstartp + sprintf(xstartp, ".area     text");
2149   break;
2150  case FDOTDATA:
2151   xbufp = xstartp + sprintf(xstartp, ".area     data");
2152   break;
2153  case FDOTBSS:
2154   xbufp = xstartp + sprintf(xstartp, ".area     bss");
2155   break;
2156  }
2157 #endif
2158
2159
2160 /*      mov     r0,-(sp) */
2161 /*      jsr     pc,p0readop */
2162 /*      mov     (sp)+,r0 */
2163 /*      asl     r0 */
2164 /*      jmp     *1f-12(r0) */
2165
2166         p0readop();
2167         switch (flags) {
2168
2169 /*      .data */
2170 /* 1: */
2171 /*      opl13                   / map fop freg,fdst to double */
2172
2173         case FMOVFO:
2174                 p0opl13();
2175                 return;
2176
2177 /*      opl6 */
2178
2179         case FBRANCH:
2180                 p0opl6();
2181                 return;
2182
2183 /*      opl7 */
2184
2185         case FJSR:
2186                 p0opl7();
2187                 return;
2188
2189 /*      opl10 */
2190
2191         case FRTS:
2192                 p0opl10();
2193                 return;
2194
2195 /*      opl11 */
2196
2197         case FSYSTRAP:
2198                 p0opl11();
2199                 return;
2200
2201 /*      opl13                   / map fld/fst to double */
2202 /*      opl13 */
2203 /*      opl13                   / map fop fsrc,freg to double */
2204
2205         case FMOVF:
2206         case FDOUBLE:
2207         case FFLOP:
2208                 p0opl13();
2209                 return;
2210
2211 /*      opl15 */
2212
2213         case FSINGLE:
2214                 p0opl15();
2215                 return;
2216
2217 /*      opl16 */
2218
2219         case FDOTBYTE:
2220 #ifdef TRANSLATE
2221  if (xstartp >= xbuf + 0xff0)
2222   abort();
2223  xbufp = xstartp + sprintf(xstartp, ".db");
2224 #endif
2225                 p0opl16();
2226                 return;
2227
2228 #if 1 /* modifications for dec syntax */
2229         case FDOTWORD:
2230 #ifdef TRANSLATE
2231  if (xstartp >= xbuf + 0xff0)
2232   abort();
2233  xbufp = xstartp + sprintf(xstartp, ".dw");
2234 #endif
2235                 p0opldotword();
2236                 return;
2237 #endif
2238
2239 /*      opl17 */
2240
2241         case FSTRING:
2242                 p0opl17();
2243                 return;
2244
2245 /*      opl20 */
2246
2247         case FDOTEVEN:
2248                 p0opl20();
2249                 return;
2250
2251 /*      opl21 */
2252
2253         case FDOTIF:
2254                 p0opl21();
2255                 return;
2256
2257 /*      opl22 */
2258
2259         case FDOTENDIF:
2260                 p0opl22();
2261                 return;
2262
2263 /*      opl23 */
2264
2265         case FDOTGLOBL:
2266                 p0opl23();
2267                 return;
2268
2269 /*      xpr */
2270
2271         case FREGISTER: /* can never get here */
2272                 p0xpr();
2273                 return;
2274
2275 /*      opl25 */
2276
2277         case FDOTTEXT:
2278                 p0opl25();
2279                 return;
2280
2281 /*      opl26 */
2282
2283         case FDOTDATA:
2284                 p0opl26();
2285                 return;
2286
2287 /*      opl27 */
2288
2289         case FDOTBSS:
2290                 p0opl27();
2291                 return;
2292
2293 /*      opl13                   / map mul s,r to double */
2294
2295         case FMULDIV:
2296                 p0opl13();
2297                 return;
2298
2299 /*      opl31 */
2300
2301         case FSOB:
2302                 p0opl31();
2303                 return;
2304
2305 /*      opl32 */
2306
2307         case FDOTCOMM:
2308                 p0opl32();
2309                 return;
2310
2311 /*      xpr */
2312 /*      xpr */
2313
2314         case FESTTEXT:
2315         case FESTDATA:
2316                 p0xpr();
2317                 return;
2318
2319 /*      opl35 */
2320
2321         case FJBR:
2322                 p0opl35();
2323                 return;
2324
2325 /*      opl36 */
2326
2327         case FJCOND:
2328                 p0opl36();
2329                 return;
2330
2331 /*      .text */
2332
2333         }
2334 }
2335
2336 /* opl35:                                       / jbr */
2337 /*      mov     $4,-(sp) */
2338 /*      br      1f */
2339
2340 void p0opl35() {
2341         relative(4);
2342 }
2343
2344 /* opl36:                                       / jeq, etc */
2345 /*      mov     $6,-(sp) */
2346
2347 void p0opl36() {
2348         relative(6);
2349 }
2350
2351 /* 1: */
2352 /*      jsr     pc,expres */
2353 /*      cmp     r3,dotrel */
2354 /*      bne     1f */
2355 /*      sub     dot,r2 */
2356 /*      bge     1f */
2357 /*      cmp     r2,$-376 */
2358 /*      blt     1f */
2359 /*      mov     $2,(sp) */
2360 /* 1: */
2361 /*      add     (sp)+,dot */
2362 /*      rts     pc */
2363
2364 void relative(size) int size; {
2365         p0expres();
2366         if (leftflags == pdot->flags) {
2367                 leftvalue -= pdot->value;
2368                 if (leftvalue < 0 && leftvalue >= -0376)
2369                         size = 2;
2370         }
2371         pdot->value += size;
2372 }
2373
2374 /* opl13: */
2375
2376 void p0opl13() {
2377         p0opl7();
2378 }
2379
2380 /* opl7:                                        /double */
2381 /*      jsr     pc,addres */
2382
2383 void p0opl7() {
2384         p0addres();
2385
2386 /* op2: */
2387 /*      cmp     r4,$', */
2388 /*      beq     1f */
2389 /*      jsr     pc,errora */
2390 /*      rts     pc */
2391 /* 1: */
2392 /*      jsr     pc,p0readop */
2393
2394         if (token != TCOMMA) {
2395                 error('a');
2396                 return;
2397         }
2398         p0readop();
2399         p0opl15();
2400 }
2401
2402 /* opl15:                               / single operand */
2403 /*      jsr     pc,addres */
2404 /*      add     $2,dot */
2405 /*      rts     pc */
2406
2407 void p0opl15() {
2408         p0addres();
2409         pdot->value += 2;
2410 }
2411
2412 /* opl31:                                       / sob */
2413 /*      jsr     pc,expres */
2414 /*      cmp     r4,$', */
2415 /*      beq     1f */
2416 /*      jsr     pc,errora */
2417 /* 1: */
2418 /*      jsr     pc,p0readop */
2419
2420 void p0opl31() {
2421         p0expres();
2422         if (token != TCOMMA) {
2423                 error('a');
2424                 return;
2425         }
2426         p0readop();
2427         p0opl11();
2428 }
2429
2430 /* opl6: */
2431
2432 void p0opl6() {
2433         p0opl11();
2434 }
2435
2436 /* opl10: */
2437
2438 void p0opl10() {
2439         p0opl11();
2440 }
2441
2442 /* opl11:                                       /branch */
2443 /*      jsr     pc,expres */
2444 /*      add     $2,dot */
2445 /*      rts     pc */
2446
2447 void p0opl11() {
2448         p0expres();
2449         pdot->value += 2;
2450 }
2451
2452 /* opl16:                                       / .byte */
2453 /*      jsr     pc,expres */
2454 /*      inc     dot */
2455 /*      cmp     r4,$', */
2456 /*      bne     1f */
2457 /*      jsr     pc,p0readop */
2458 /*      br      opl16 */
2459 /* 1: */
2460 /*      rts     pc */
2461
2462 void p0opl16() {
2463         while (1) {
2464                 p0expres();
2465                 pdot->value++;
2466                 if (token != TCOMMA)
2467                         break;
2468                 p0readop();
2469         }
2470 }
2471
2472 #if 1 /* modifications for dec syntax */
2473 void p0opldotword() {
2474         while (1) {
2475                 p0expres();
2476                 pdot->value += 2;
2477                 if (token != TCOMMA)
2478                         break;
2479                 p0readop();
2480         }
2481 }
2482 #endif
2483
2484 /* opl17:                                       / < (.ascii) */
2485 /*      add     numval,dot */
2486 /*      jsr     pc,p0readop */
2487 /*      rts     pc */
2488
2489 void p0opl17() {
2490         pdot->value += numval;
2491         p0readop();
2492 }
2493
2494 /* opl20:                                       /.even */
2495 /*      inc     dot */
2496 /*      bic     $1,dot */
2497 /*      rts     pc */
2498
2499 void p0opl20() {
2500         pdot->value = (pdot->value + 1) & ~1;
2501 }
2502
2503 /* opl21:                                       /.if */
2504 /*      jsr     pc,expres */
2505 /*      tst     r3 */
2506 /*      bne     1f */
2507 /*      mov     $'U,r5 */
2508 /*      jsr     pc,error */
2509 /* 1: */
2510 /*      tst     r2 */
2511 /*      bne     opl22 */
2512 /*      inc     ifflg */
2513 /* opl22:                                       /endif */
2514 /*      rts     pc */
2515
2516 void p0opl21() {
2517         p0expres();
2518         if (leftflags == 0)
2519                 error('U');
2520         if (leftvalue == 0)
2521                 ifflg++;
2522 }
2523
2524 void p0opl22() {
2525 }
2526
2527 /* opl23:                                       /.globl */
2528 /*      cmp     r4,$200 */
2529 /*      blo     1f */
2530 /*      bisb    $40,(r4) */
2531 /*      jsr     pc,p0readop */
2532 /*      cmp     r4,$', */
2533 /*      bne     1f */
2534 /*      jsr     pc,p0readop */
2535 /*      br      opl23 */
2536 /* 1: */
2537 /*      rts     pc */
2538
2539 void p0opl23() {
2540         struct symbol *psymbol;
2541
2542         while (1) {
2543                 if (token >= 0 && token < TASCII)
2544                         break;
2545                 psymbol = (struct symbol *)token;
2546                 psymbol->flags |= FGLOBAL;
2547                 p0readop();
2548                 if (token != TCOMMA)
2549                         break;
2550                 p0readop();
2551         }
2552 }
2553
2554 /* opl25: */
2555 /* opl26: */
2556 /* opl27: */
2557 /*      mov     dotrel,r1 */
2558 /*      asl     r1 */
2559 /*      mov     dot,savdot-4(r1) */
2560 /*      mov     savdot-[2*25](r0),dot */
2561 /*      asr     r0 */
2562 /*      sub     $25-2,r0 */
2563 /*      mov     r0,dotrel */
2564 /*      rts     pc */
2565
2566 void p0opl25() {
2567         savdot[pdot->flags - FTEXT] = pdot->value;
2568         pdot->value = savdot[0];
2569         pdot->flags = FTEXT;
2570 }
2571
2572 void p0opl26() {
2573         savdot[pdot->flags - FTEXT] = pdot->value;
2574         pdot->value = savdot[1];
2575         pdot->flags = FDATA;
2576 }
2577
2578 void p0opl27() {
2579         savdot[pdot->flags - FTEXT] = pdot->value;
2580         pdot->value = savdot[2];
2581         pdot->flags = FBSS;
2582 }
2583
2584 /* opl32:                                       / .common */
2585 /*      cmp     r4,$200 */
2586 /*      blo     1f */
2587 /*      bis     $40,(r4) */
2588 /*      jsr     pc,p0readop */
2589 /*      cmp     r4,$', */
2590 /*      bne     1f */
2591 /*      jsr     pc,p0readop */
2592 /*      jsr     pc,expres */
2593 /*      rts     pc */
2594 /* 1: */
2595 /*      mov     $'x,r5 */
2596 /*      jsr     pc,error */
2597 /*      rts     pc */
2598
2599 void p0opl32() {
2600         struct symbol *psymbol;
2601
2602         if (token >= 0 && token < TASCII) {
2603                 error('x');
2604                 return;
2605         }
2606         psymbol = (struct symbol *)token;
2607         psymbol->flags |= FGLOBAL;
2608         p0readop();
2609         if (token != TCOMMA) {
2610                 error('x');
2611                 return;
2612         }
2613         p0readop();
2614         p0expres();
2615 }
2616
2617 /* addres: */
2618 /*      cmp     r4,$'( */
2619 /*      beq     alp */
2620 /*      cmp     r4,$'- */
2621 /*      beq     amin */
2622 /*      cmp     r4,$'$ */
2623 /*      beq     adoll */
2624 /*      cmp     r4,$'* */
2625 /*      beq     astar */
2626
2627 void p0addres() {
2628 /* printf("p0addres() token = 0x%08x\n", token); */
2629         switch (token) {
2630         case TLPAREN:
2631                 p0alp();
2632                 return;
2633         case TMIN:
2634                 p0amin();
2635                 return;
2636         case TDOLL:
2637 #ifdef TRANSLATE
2638  xbufp[-1] = '#';
2639 #endif
2640                 p0adoll();
2641                 return;
2642         case TSTAR:
2643                 p0astar();
2644                 return;
2645         }
2646         p0getx();
2647 }
2648
2649 /* getx: */
2650 /*      jsr     pc,expres */
2651 /*      cmp     r4,$'( */
2652 /*      bne     2f */
2653 /*      jsr     pc,p0readop */
2654 /*      jsr     pc,expres */
2655 /*      jsr     pc,checkreg */
2656 /*      jsr     pc,checkrp */
2657 /* 1: */
2658 /*      add     $2,dot */
2659 /*      clr     r0 */
2660 /*      rts     pc */
2661 /* 2: */
2662 /*      cmp     r3,$24                  / register type */
2663 /*      bne     1b */
2664 /*      jsr     pc,checkreg */
2665 /*      clr     r0 */
2666 /*      rts     pc */
2667
2668 void p0getx() {
2669         p0expres();
2670         if (token == TLPAREN) {
2671                 p0readop();
2672                 p0expres();
2673                 p0checkreg();
2674                 p0checkrp();
2675                 pdot->value += 2;
2676         }
2677         else if (leftflags == FREGISTER)
2678                 p0checkreg();
2679         else
2680                 pdot->value += 2;
2681         indirect = 0;
2682 }
2683
2684 /* alp: */
2685 /*      jsr     pc,p0readop */
2686 /*      jsr     pc,expres */
2687 /*      jsr     pc,checkrp */
2688 /*      jsr     pc,checkreg */
2689 /*      cmp     r4,$'+ */
2690 /*      bne     1f */
2691 /*      jsr     pc,p0readop */
2692 /*      clr     r0 */
2693 /*      rts     pc */
2694 /* 1: */
2695 /*      mov     $2,r0 */
2696 /*      rts     pc */
2697
2698 void p0alp() {
2699         p0readop();
2700         p0expres();
2701         p0checkrp();
2702         p0checkreg();
2703         if (token == TPLUS) {
2704                 p0readop();
2705                 indirect = 0;
2706         }
2707         else
2708                 indirect = 2;
2709 }
2710
2711 /* amin: */
2712 /*      jsr     pc,p0readop */
2713 /*      cmp     r4,$'( */
2714 /*      beq     1f */
2715 /*      mov     r4,savop */
2716 /*      mov     $'-,r4 */
2717 /*      br      getx */
2718 /* 1: */
2719 /*      jsr     pc,p0readop */
2720 /*      jsr     pc,expres */
2721 /*      jsr     pc,checkrp */
2722 /*      jsr     pc,checkreg */
2723 /*      clr     r0 */
2724 /*      rts     pc */
2725
2726 void p0amin() {
2727 #ifdef TRANSLATE
2728  xstartpsave = xstartp;
2729  xbufpsave = xbufp;
2730 #endif
2731         p0readop();
2732         if (token != TLPAREN) {
2733                 savop = token;
2734 #ifdef TRANSLATE
2735  xsavestartn = xstartp - xbufpsave;
2736  xsavebufn = xbufp - xbufpsave;
2737  memcpy(xsave, xbufpsave, xsavebufn);
2738 #endif
2739                 token = TMIN;
2740 #ifdef TRANSLATE
2741  xstartp = xstartpsave;
2742  xbufp = xbufpsave;
2743 #endif
2744                 p0getx();
2745         }
2746         else {
2747                 p0readop();
2748                 p0expres();
2749                 p0checkrp();
2750                 p0checkreg();
2751                 indirect = 0;
2752         }
2753 }
2754
2755 /* adoll: */
2756 /*      jsr     pc,p0readop */
2757 /*      jsr     pc,expres */
2758 /*      add     $2,dot */
2759 /*      clr     r0 */
2760 /*      rts     pc */
2761
2762 void p0adoll() {
2763         p0readop();
2764         p0expres();
2765         pdot->value += 2;
2766         indirect = 0;
2767 }
2768
2769 /* astar: */
2770 /*      jsr     pc,p0readop */
2771 /*      cmp     r4,$'* */
2772 /*      bne     1f */
2773 /*      mov     $'*,r5 */
2774 /*      jsr     pc,error */
2775 /* 1: */
2776 /*      jsr     pc,addres */
2777 /*      add     r0,dot */
2778 /*      rts     pc */
2779
2780 void p0astar() {
2781         p0readop();
2782         if (token == TSTAR)
2783                 error('*');
2784         p0addres();
2785         pdot->value += indirect;
2786 }
2787
2788 /* errora: */
2789 /*      mov     $'a,r5 */
2790 /*      jsr     pc,error */
2791 /*      rts     pc */
2792
2793 void errora() {
2794         error('a');
2795 }
2796
2797 /* checkreg: */
2798 /*      cmp     r2,$7 */
2799 /*      bhi     1f */
2800 /*      cmp     r3,$1 */
2801 /*      beq     2f */
2802 /*      cmp     r3,$4 */
2803 /*      bhi     2f */
2804 /* 1: */
2805 /*      jsr     pc,errora */
2806 /* 2: */
2807 /*      rts     pc */
2808
2809 void p0checkreg() {
2810         if (leftvalue > 7 || (leftflags != FABS && leftflags <= FBSS))
2811                 errora();
2812 }
2813
2814 /* errore: */
2815 /*      mov     $'e,r5 */
2816 /*      jsr     pc,error */
2817 /*      rts     pc */
2818
2819 void errore() {
2820         error('e');
2821 }
2822
2823 /* checkrp: */
2824 /*      cmp     r4,$') */
2825 /*      beq     1f */
2826 /*      mov     $'),r5 */
2827 /*      jsr     pc,error */
2828 /*      rts     pc */
2829 /* 1: */
2830 /*      jsr     pc,p0readop */
2831 /*      rts     pc */
2832
2833 void p0checkrp() {
2834         if (token != TRPAREN)
2835                 error(')');
2836         else
2837                 p0readop();
2838 }
2839
2840 /* expres: */
2841 /*      mov     r5,-(sp) */
2842 /*      mov     $'+,-(sp) */
2843 /*      clr     opfound */
2844 /*      clr     r2 */
2845 /*      mov     $1,r3 */
2846 /*      br      1f */
2847
2848 void p0expres() {
2849         struct symbol *psymbol;
2850
2851 /* printf("p0expres()\n"); */
2852         optoken = TPLUS;
2853         opfound = 0;
2854         leftvalue = 0;
2855         leftflags = FABS;
2856         goto entry;
2857
2858 /* advanc: */
2859 /*      jsr     pc,p0readop */
2860 /* 1: */
2861 /*      mov     r4,r0 */
2862 /*      tst     r0 */
2863 /*      blt     6f */
2864 /*      cmp     r0,$177 */
2865 /*      ble     7f */
2866 /* 6: */
2867 /*      movb    (r4),r0 */
2868 /*      mov     2(r4),r1 */
2869 /*      br      oprand */
2870 /* 7: */
2871
2872         while (1) {
2873                 p0readop();
2874         entry:
2875                 rightflags = token;
2876                 if (token < 0 || token >= TASCII) {
2877                         psymbol = (struct symbol *)token;
2878                         rightflags = psymbol->flags;
2879                         rightvalue = psymbol->value;
2880                         p0oprand();
2881                         continue;
2882                 }
2883
2884 /*      cmp     r4,$141 */
2885 /*      blo     1f */
2886 /*      cmp     r4,$141+10. */
2887 /*      bhis    2f */
2888 /*      movb    curfbr-141(r4),r0 */
2889 /*      asl     r4 */
2890 /*      mov     curfb-[2*141](r4),r2 */
2891 /*      cmp     r2,$-1 */
2892 /*      bne     oprand */
2893 /*      mov     $'f,r5 */
2894 /*      jsr     pc,error */
2895 /*      br      oprand */
2896 /* 2: */
2897 /*      clr     r3 */
2898 /*      clr     r2 */
2899 /*      br      oprand */
2900 /* 1: */
2901
2902                 if (token >= TLABEL) {
2903                         if (token < TLABEL + 10) {
2904 #ifdef TRANSLATE
2905  if (xstartp >= xbuf + 0xff0)
2906   abort();
2907  // for asxlat, -u means local labels will be changed to ordinary labels
2908  // (use this when there is an inconvenient ordinary label within locals)
2909  if (defund == FGLOBAL)
2910   xbufp = xstartp + sprintf(xstartp, "_%d", xlabb[token - TLABEL]);
2911  else
2912   xbufp = xstartp + sprintf(xstartp, "%d$", xlabb[token - TLABEL]);
2913 #endif
2914                                 rightflags = curfbr[token - TLABEL];
2915  /* bug!! should be rightvalue / rightflags below: */
2916                                 leftvalue = curfb[token - TLABEL];
2917                                 if (leftvalue == -1)
2918                                         error('f');
2919                         }
2920                         else {
2921 #ifdef TRANSLATE
2922  xlab = token - (TLABEL + 10);
2923  if (xlab < 10) {
2924   if (xlabf[xlab] == -1)
2925    xlabf[xlab] = xlabnext++;
2926   if (xstartp >= xbuf + 0xff0)
2927    abort();
2928   // for asxlat, -u means local labels will be changed to ordinary labels
2929   // (use this when there is an inconvenient ordinary label within locals)
2930   if (defund == FGLOBAL)
2931    xbufp = xstartp + sprintf(xstartp, "_%d", xlabf[xlab]);
2932   else
2933    xbufp = xstartp + sprintf(xstartp, "%d$", xlabf[xlab]);
2934  }
2935 #endif
2936                                 leftflags = 0;
2937                                 leftvalue = 0;
2938                         }
2939                         p0oprand();
2940                         continue;
2941                 }
2942
2943 /*      mov     $esw1,r1 */
2944 /* 1: */
2945 /*      cmp     (r1)+,r4 */
2946 /*      beq     1f */
2947 /*      tst     (r1)+ */
2948 /*      bne     1b */
2949 /*      tst     opfound */
2950 /*      bne     2f */
2951 /*      jsr     pc,errore */
2952 /* 2: */
2953 /*      tst     (sp)+ */
2954 /*      mov     (sp)+,r5 */
2955 /*      rts     pc */
2956 /* 1: */
2957 /*      jmp     *(r1) */
2958
2959                 switch (token) {
2960                 default:
2961                         if (opfound == 0)
2962                                 error('e');
2963                         return;
2964
2965 /*      .data */
2966 /* esw1: */
2967 /*      '+;     binop */
2968 /*      '-;     binop */
2969 /*      '*;     binop */
2970 /*      '/;     binop */
2971 /*      '&;     binop */
2972 /*      037;    binop */
2973 /*      035;    binop */
2974 /*      036;    binop */
2975 /*      '%;     binop */
2976
2977                 case TPLUS:
2978                 case TMIN:
2979                 case TSTAR:
2980                 case TSLASH:
2981                 case TAND:
2982                 case TOR:
2983                 case TLSH:
2984                 case TRSH:
2985                 case TMOD:
2986                         p0binop();
2987                         break;
2988
2989 /*      '[;     brack */
2990
2991                 case TLBRACK:
2992                         p0brack();
2993                         break;
2994
2995 /*      '^;     binop */
2996
2997                 case TCARET:
2998                         p0binop();
2999                         break;
3000
3001 /*      1;      exnum */
3002
3003                 case TABS:
3004                         p0exnum();
3005                         break;
3006
3007 /*      '!;     binop */
3008
3009                 case TNOT:
3010 #ifdef TRANSLATE
3011  xbufp[-1] = '~';
3012 #endif
3013                         p0binop();
3014                         break;
3015
3016 /*      0;      0 */
3017 /*      .text */
3018
3019                 }
3020         }
3021 }
3022
3023 /* binop: */
3024 /*      cmpb    (sp),$'+ */
3025 /*      beq     1f */
3026 /*      jsr     pc,errore */
3027 /* 1: */
3028 /*      movb    r4,(sp) */
3029 /*      br      advanc */
3030
3031 void p0binop() {
3032         if (optoken != TPLUS)
3033                 error('e');
3034         optoken = token;
3035 }
3036
3037 /* exnum: */
3038 /*      mov     numval,r1 */
3039 /*      mov     $1,r0 */
3040 /*      br      oprand */
3041
3042 void p0exnum() {
3043 /* printf("p0exnum() numval = 0%o\n", numval); */
3044         rightvalue = numval;
3045         rightflags = FABS;
3046         p0oprand();
3047 }
3048
3049 /* brack: */
3050 /*      mov     r2,-(sp) */
3051 /*      mov     r3,-(sp) */
3052 /*      jsr     pc,p0readop */
3053 /*      jsr     pc,expres */
3054 /*      cmp     r4,$'] */
3055 /*      beq     1f */
3056 /*      mov     $'],r5 */
3057 /*      jsr     pc,error */
3058 /* 1: */
3059 /*      mov     r3,r0 */
3060 /*      mov     r2,r1 */
3061 /*      mov     (sp)+,r3 */
3062 /*      mov     (sp)+,r2 */
3063
3064 void p0brack() {
3065         int tempvalue;
3066         int tempflags;
3067         int temptoken;
3068
3069         tempvalue = leftvalue;
3070         tempflags = leftflags;
3071         temptoken = optoken;
3072         p0readop();
3073         p0expres();
3074         if (token != TRBRACK)
3075                 error(']');
3076         rightflags = leftflags;
3077         rightvalue = leftvalue;
3078         leftflags = tempflags;
3079         leftvalue = tempvalue;
3080         optoken = temptoken;
3081         p0oprand();
3082 }
3083
3084 /* oprand: */
3085 /*      inc     opfound */
3086 /*      mov     $exsw2,r5 */
3087 /* 1: */
3088 /*      cmp     (sp),(r5)+ */
3089 /*      beq     1f */
3090 /*      tst     (r5)+ */
3091 /*      bne     1b */
3092 /*      br      eoprnd */
3093 /* 1: */
3094 /*      jmp     *(r5) */
3095
3096 void p0oprand() {
3097         opfound = 1;
3098         switch (optoken) {
3099         default:
3100                 p0eoprnd();
3101                 return;
3102
3103 /*      .data */
3104 /* exsw2: */
3105 /*      '+; exadd */
3106
3107         case TPLUS:
3108                 p0exadd();
3109                 return;
3110
3111 /*      '-; exsub */
3112
3113         case TMIN:
3114                 p0exsub();
3115                 return;
3116
3117 /*      '*; exmul */
3118
3119         case TSTAR:
3120                 p0exmul();
3121                 return;
3122
3123 /*      '/; exdiv */
3124
3125         case TSLASH:
3126                 p0exdiv();
3127                 return;
3128
3129 /*      037; exor */
3130
3131         case TOR:
3132                 p0exor();
3133                 return;
3134
3135 /*      '&; exand */
3136
3137         case TAND:
3138                 p0exand();
3139                 return;
3140
3141 /*      035;exlsh */
3142
3143         case TLSH:
3144                 p0exlsh();
3145                 return;
3146
3147 /*      036;exrsh */
3148
3149         case TRSH:
3150                 p0exrsh();
3151                 return;
3152
3153 /*      '%; exmod */
3154
3155         case TMOD:
3156                 p0exmod();
3157                 return;
3158
3159 /*      '!; exnot */
3160
3161         case TNOT:
3162                 p0exnot();
3163                 return;
3164
3165 /*      '^; excmbin */
3166
3167         case TCARET:
3168                 p0excmbin();
3169                 return;
3170
3171 /*      0;  0 */
3172 /*      .text */
3173
3174         }
3175 }
3176
3177 /* excmbin: */
3178 /*      mov     r0,r3                   / give left flag of right */
3179 /*      br      eoprnd */
3180
3181 void p0excmbin() {
3182         leftflags = rightflags;
3183         p0eoprnd();
3184 }
3185
3186 /* exrsh: */
3187 /*      neg     r1 */
3188 /*      beq     exlsh */
3189 /*      inc     r1 */
3190 /*      clc */
3191 /*      ror     r2 */
3192 /* exlsh: */
3193 /*      clr     r5 */
3194 /*      jsr     pc,combin */
3195 /*      ash     r1,r2 */
3196 /*      br      eoprnd */
3197
3198 void p0exrsh() {
3199         p0combin(0);
3200         leftvalue = ((unsigned int)leftvalue & 0177777) >> rightvalue;
3201         p0eoprnd();
3202 }
3203
3204 void p0exlsh() {
3205         p0combin(0);
3206         leftvalue <<= rightvalue;
3207         p0eoprnd();
3208 }
3209
3210 /* exmod: */
3211 /*      clr     r5 */
3212 /*      jsr     pc,combin */
3213 /*      mov     r1,-(sp) */
3214 /*      mov     r2,r1 */
3215 /*      clr     r0 */
3216 /*      div     (sp)+,r0 */
3217 /*      mov     r1,r2 */
3218 /*      br      eoprnd */
3219
3220 void p0exmod() {
3221         int temp;
3222
3223         p0combin(0);
3224         temp = rightvalue & 0177777;
3225         if (temp)
3226                 leftvalue = (leftvalue & 0177777) % temp;
3227         else {
3228                 error('0'); /* a nick innovation */
3229                 leftvalue = 0;
3230         }
3231         p0eoprnd();
3232 }
3233
3234 /* exadd: */
3235 /*      clr     r5 */
3236 /*      jsr     pc,combin */
3237 /*      add     r1,r2 */
3238 /*      br      eoprnd */
3239
3240 void p0exadd() {
3241         p0combin(0);
3242         leftvalue += rightvalue;
3243         p0eoprnd();
3244 }
3245
3246 /* exsub: */
3247 /*      mov     $1,r5 */
3248 /*      jsr     pc,combin */
3249 /*      sub     r1,r2 */
3250 /*      br      eoprnd */
3251
3252 void p0exsub() {
3253         p0combin(1);
3254         leftvalue -= rightvalue;
3255         p0eoprnd();
3256 }
3257
3258 /* exand: */
3259 /*      clr     r5 */
3260 /*      jsr     pc,combin */
3261 /*      com     r1 */
3262 /*      bic     r1,r2 */
3263 /*      br      eoprnd */
3264
3265 void p0exand() {
3266         p0combin(0);
3267         leftvalue &= rightvalue;
3268         p0eoprnd();
3269 }
3270
3271 /* exor: */
3272 /*      clr     r5 */
3273 /*      jsr     pc,combin */
3274 /*      bis     r1,r2 */
3275 /*      br      eoprnd */
3276
3277 void p0exor() {
3278         p0combin(0);
3279         leftvalue |= rightvalue;
3280         p0eoprnd();
3281 }
3282
3283 /* exmul: */
3284 /*      clr     r5 */
3285 /*      jsr     pc,combin */
3286 /*      mul     r2,r1 */
3287 /*      mov     r1,r2 */
3288 /*      br      eoprnd */
3289
3290 void p0exmul() {
3291         p0combin(0);
3292         leftvalue *= rightvalue;
3293         p0eoprnd();
3294 }
3295
3296 /* exdiv: */
3297 /*      clr     r5 */
3298 /*      jsr     pc,combin */
3299 /*      mov     r1,-(sp) */
3300 /*      mov     r2,r1 */
3301 /*      clr     r0 */
3302 /*      div     (sp)+,r0 */
3303 /*      mov     r0,r2 */
3304 /*      br      eoprnd */
3305
3306 void p0exdiv() {
3307         int temp;
3308
3309         p0combin(0);
3310         temp = rightvalue & 0177777;
3311         if (temp)
3312                 leftvalue = (leftvalue & 0177777) / temp;
3313         else {
3314                 error('0'); /* a nick innovation */
3315                 leftvalue = 0;
3316         }
3317         p0eoprnd();
3318 }
3319
3320 /* exnot: */
3321 /*      clr     r5 */
3322 /*      jsr     pc,combin */
3323 /*      com     r1 */
3324 /*      add     r1,r2 */
3325 /*      br      eoprnd */
3326
3327 void p0exnot() {
3328         p0combin(0);
3329         leftvalue += ~rightvalue;
3330         p0eoprnd();
3331 }
3332
3333 /* eoprnd: */
3334 /*      mov     $'+,(sp) */
3335 /*      jmp     advanc */
3336
3337 void p0eoprnd() {
3338         optoken = TPLUS;
3339 }
3340
3341 /* combin: */
3342 /*      mov     r0,-(sp) */
3343 /*      bis     r3,(sp) */
3344 /*      bic     $!40,(sp) */
3345 /*      bic     $!37,r0 */
3346 /*      bic     $!37,r3 */
3347 /*      cmp     r0,r3 */
3348 /*      ble     1f */
3349 /*      mov     r0,-(sp) */
3350 /*      mov     r3,r0 */
3351 /*      mov     (sp)+,r3 */
3352 /* 1: */
3353
3354 void p0combin(minflag) int minflag; {
3355         int global;
3356         int flags;
3357
3358         global = (rightflags | leftflags) & FGLOBAL;
3359         rightflags &= 037;
3360         leftflags &= 037;
3361         if (rightflags > leftflags) {
3362                 flags = rightflags;
3363                 rightflags = leftflags;
3364                 leftflags = flags;
3365         }
3366
3367 /*      tst     r0 */
3368 /*      beq     1f */
3369 /*      tst     r5 */
3370 /*      beq     2f */
3371 /*      cmp     r0,r3 */
3372 /*      bne     2f */
3373 /*      mov     $1,r3 */
3374 /*      br      2f */
3375 /* 1: */
3376 /*      clr     r3 */
3377 /* 2: */
3378 /*      bis     (sp)+,r3 */
3379 /*      rts     pc */
3380
3381         if (rightflags) {
3382                 if (minflag && rightflags == leftflags)
3383                         leftflags = TABS;
3384         }
3385         else {
3386                 leftflags = 0;
3387         }
3388         leftflags |= global;
3389 }
3390
3391 /*      .data */
3392 /* chartab: */
3393 /*      .byte -14,-14,-14,-14,-02,-14,-14,-14 */
3394 /*      .byte -14,-22, -2,-14,-14,-22,-14,-14 */
3395 /*      .byte -14,-14,-14,-14,-14,-14,-14,-14 */
3396 /*      .byte -14,-14,-14,-14,-14,-14,-14,-14 */
3397 /*      .byte -22,-20,-16,-14,-20,-20,-20,-12 */
3398 /*      .byte -20,-20,-20,-20,-20,-20,056,-06 */
3399 /*      .byte 060,061,062,063,064,065,066,067 */
3400 /*      .byte 070,071,-20,-02,-00,-20,-14,-14 */
3401 /*      .byte -14,101,102,103,104,105,106,107 */
3402 /*      .byte 110,111,112,113,114,115,116,117 */
3403 /*      .byte 120,121,122,123,124,125,126,127 */
3404 /*      .byte 130,131,132,-20,-24,-20,-20,137 */
3405 /*      .byte -14,141,142,143,144,145,146,147 */
3406 /*      .byte 150,151,152,153,154,155,156,157 */
3407 /*      .byte 160,161,162,163,164,165,166,167 */
3408 /*      .byte 170,171,172,-14,-26,-14,176,-14 */
3409
3410 char chartab[TASCII] = {
3411         -014,-014,-014,-014,-002,-014,-014,-014,
3412         -014,-022,0 -2,-014,-014,-022,-014,-014,
3413         -014,-014,-014,-014,-014,-014,-014,-014,
3414         -014,-014,-014,-014,-014,-014,-014,-014,
3415 #if 1 /* modifications for dec syntax */
3416         -022,-020,-016,-026,-020,-020,-020,-012,
3417 #else
3418         -022,-020,-016,-014,-020,-020,-020,-012,
3419 #endif
3420         -020,-020,-020,-020,-020,-020,0056,-006,
3421         0060,0061,0062,0063,0064,0065,0066,0067,
3422         0070,0071,-020,-002,-000,-020,-014,-014,
3423 #if 1 /* modifications for dec syntax */
3424         -026,0101,0102,0103,0104,0105,0106,0107,
3425 #else
3426         -014,0101,0102,0103,0104,0105,0106,0107,
3427 #endif
3428         0110,0111,0112,0113,0114,0115,0116,0117,
3429         0120,0121,0122,0123,0124,0125,0126,0127,
3430         0130,0131,0132,-020,-024,-020,-020,0137,
3431         -014,0141,0142,0143,0144,0145,0146,0147,
3432         0150,0151,0152,0153,0154,0155,0156,0157,
3433         0160,0161,0162,0163,0164,0165,0166,0167,
3434         0170,0171,0172,-014,-026,-014,0176,-014
3435 };
3436
3437 /* a.tmp1:      </tmp/atm1XX\0> */
3438
3439 #ifdef pdp11
3440 char a_tmp1[] = "/tmp/atm1XX";
3441 #else
3442 char a_tmp1[] = "/tmp/atm1XXXXXX"; /* linux requires 6 X's */
3443 #endif
3444
3445 /* Ncps:        .byte 8. */
3446
3447 char Ncps = 8;
3448
3449 /* 1:   <-\0> */
3450 /*      .even */
3451 /* dash:        1b */
3452
3453 char *dash = "-";
3454
3455 /* fin: -1 */
3456
3457 int fin = -1;
3458
3459 /* fout:        -1 */
3460
3461 int fout = -1;
3462
3463 /* The next two _must_ be adjacent!  Not sure why, but then this whole */
3464 /* assembler is weird beyond belief. */
3465 /* curfb:       -1;-1;-1;-1;-1;-1;-1;-1;-1;-1 */
3466
3467 /* THEY HAD TO BE ADJACENT BECAUSE PASS 2 p0expres() READS curfb[token - 0141] */
3468 /* THIS HAS BEEN SPLIT INTO curfb[token - 0141], nxtfb[token - (0141 + 10)] */
3469 /* BY THE WAY, THE ASSEMBLER IS NOT REALLY WEIRD, IT'S KIND OF ELEGANT !!! */
3470 intptr_t curfb[10] = {
3471         -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
3472 };
3473
3474 /* nxtfb:       .=.+20.                 / first 4 used by pass0, all 20. by pass1+2 */
3475
3476 /* FIRST 4 AREN'T USED BY PASS 0 ANYMORE, IT WAS ONLY TEMPORARY SCRATCH !!!! */
3477 intptr_t nxtfb[10];
3478
3479 /*      .bss */
3480 /* curfbr:      .=.+10. */
3481
3482 int curfbr[10];
3483
3484 /* savdot:      .=.+6 */
3485
3486 int savdot[3];
3487
3488 /* hshtab:      .=.+2                   / dynamically allocated */
3489
3490 struct symbol **hshtab;
3491
3492 /* ch:  .=.+2 */
3493
3494 int ch;
3495
3496 /* symnum:      .=.+2                   / symbol number */
3497
3498 int symnum;
3499
3500 /* symbol:      .=.+32.                 / XXX */
3501 /*      .=.+2                   / paranoia to make sure a null is present */
3502
3503 char symbol[33];
3504
3505 /* inbuf:  .=.+1024. */
3506
3507 char inbuf[1024];
3508
3509 /* line:        .=.+2 */
3510
3511 int line;
3512
3513 /* ifflg:       .=.+2 */
3514
3515 int ifflg;
3516
3517 /* nargs:       .=.+2 */
3518
3519 int nargs;
3520
3521 /* curarg:      .=.+2 */
3522
3523 char **curarg;
3524
3525 /* opfound:.=.+2 */
3526
3527 int opfound;
3528
3529 /* savop:       .=.+2 */
3530
3531 int savop;
3532
3533 /* numval:      .=.+2 */
3534
3535 int numval;
3536
3537 /* fbtblsz:.=.+2 */
3538
3539 int fbtblsz;
3540
3541 /* fbfree: .=.+2 */
3542
3543 int fbfree;
3544
3545 /* fbptr:  .=.+2 */
3546
3547 struct symbol *fbptr;
3548
3549 /* fbtbl:  .=.+2 */
3550
3551 struct symbol *fbtbl;
3552
3553 /* usymtab:.=.+2                        / ptr to first block of symbols */
3554
3555 struct symblk *usymtab;
3556
3557 /* symleft:.=.+2                        / bytes left in current symbol block */
3558
3559 int symleft;
3560
3561 /* symend: .=.+2                        / ptr to next symbol space in block */
3562
3563 struct symbol *symend;
3564
3565 /* symblk: .=.+2                        / ptr to beginning of current sym block */
3566
3567 struct symblk *symblk;
3568
3569 /* strleft:.=.+2                        / amount left in string block */
3570
3571 int strleft;
3572
3573 /* strend:      .=.+2                   / ptr to next available string byte */
3574
3575 char *strend;
3576
3577 /* strblk:      .=.+2                   / ptr to current string block link word */
3578
3579 struct strblk *strblk;
3580
3581 /* key to types */
3582
3583 /*      0       undefined */
3584 /*      1       absolute (nop, reset, bpt, ...) */
3585 /*      2       text */
3586 /*      3       data */
3587 /*      4       bss */
3588 /*      5       flop freg,dst (movfo, = stcfd) */
3589 /*      6       branch */
3590 /*      7       jsr */
3591 /*      10      rts */
3592 /*      11      sys, trap */
3593 /*      12      movf (=ldf,stf) */
3594 /*      13      double operand (mov) */
3595 /*      14      flop fsrc,freg (addf) */
3596 /*      15      single operand (clr) */
3597 /*      16      .byte */
3598 /*      17      string (.ascii, "<") */
3599 /*      20      .even */
3600 /*      21      .if */
3601 /*      22      .endif */
3602 /*      23      .globl */
3603 /*      24      register */
3604 /*      25      .text */
3605 /*      26      .data */
3606 /*      27      .bss */
3607 /*      30      mul,div, etc */
3608 /*      31      sob */
3609 /*      32      .comm */
3610 /*      33      estimated text */
3611 /*      34      estimated data */
3612 /*      35      jbr */
3613 /*      36      jeq, jne, etc */
3614
3615 /*      .data */
3616 /* the format of PST entries was changed.  rather than fixed 8 byte strings */
3617 /* (often with many trailing nulls) a pointer to a null terminated string */
3618 /* is now used.  This saves quite a bit of space since most PST entries are */
3619 /* only 3 or 4 characters long.  we had to do this the hard way since there */
3620 /* is no macro capability in the assembler and i'd chuck out the SDI [Span */
3621 /* Dependent Instruction] stuff and use my own assembler before trying to */
3622 /* add macros to this one.  Symbols beginning with 'L' are used since the */
3623 /* linker can be told to discard those. */
3624
3625 /* symtab: */
3626 /* special symbols */
3627
3628 /* L1; dotrel: 02;    dot: 0000000 */
3629 /* L2;      01; dotdot: 0000000 */
3630
3631 /* register */
3632
3633 /* L3;  24;     000000 */
3634 /* L4;  24;     000001 */
3635 /* L5;  24;     000002 */
3636 /* L6;  24;     000003 */
3637 /* L7;  24;     000004 */
3638 /* L8;  24;     000005 */
3639 /* L9;  24;     000006 */
3640 /* L10; 24;     000007 */
3641
3642 /* double operand */
3643
3644 /* L11; 13;     0010000 */
3645 /* L12; 13;     0110000 */
3646 /* L13; 13;     0020000 */
3647 /* L14; 13;     0120000 */
3648 /* L15; 13;     0030000 */
3649 /* L16; 13;     0130000 */
3650 /* L17; 13;     0040000 */
3651 /* L18; 13;     0140000 */
3652 /* L19; 13;     0050000 */
3653 /* L20; 13;     0150000 */
3654 /* L21; 13;     0060000 */
3655 /* L22; 13;     0160000 */
3656
3657 /* branch */
3658
3659 /* L23; 06;     0000400 */
3660 /* L24; 06;     0001000 */
3661 /* L25; 06;     0001400 */
3662 /* L26; 06;     0002000 */
3663 /* L27; 06;     0002400 */
3664 /* L28; 06;     0003000 */
3665 /* L29; 06;     0003400 */
3666 /* L30; 06;     0100000 */
3667 /* L31; 06;     0100400 */
3668 /* L32; 06;     0101000 */
3669 /* L33; 06;     0101400 */
3670 /* L34; 06;     0102000 */
3671 /* L35; 06;     0102400 */
3672 /* L36; 06;     0103000 */
3673 /* L37; 06;     0103000 */
3674 /* L38; 06;     0103000 */
3675 /* L39; 06;     0103400 */
3676 /* L40; 06;     0103400 */
3677 /* L41; 06;     0103400 */
3678
3679 /* jump/branch type */
3680
3681 /* L42; 35;     0000400 */
3682 /* L43; 36;     0001000 */
3683 /* L44; 36;     0001400 */
3684 /* L45; 36;     0002000 */
3685 /* L46; 36;     0002400 */
3686 /* L47; 36;     0003000 */
3687 /* L48; 36;     0003400 */
3688 /* L49; 36;     0100000 */
3689 /* L50; 36;     0100400 */
3690 /* L51; 36;     0101000 */
3691 /* L52; 36;     0101400 */
3692 /* L53; 36;     0102000 */
3693 /* L54; 36;     0102400 */
3694 /* L55; 36;     0103000 */
3695 /* L56; 36;     0103000 */
3696 /* L57; 36;     0103000 */
3697 /* L58; 36;     0103400 */
3698 /* L59; 36;     0103400 */
3699 /* L60; 36;     0103400 */
3700
3701 /* single operand */
3702
3703 /* L61; 15;     0005000 */
3704 /* L62; 15;     0105000 */
3705 /* L63; 15;     0005100 */
3706 /* L64; 15;     0105100 */
3707 /* L65; 15;     0005200 */
3708 /* L66; 15;     0105200 */
3709 /* L67; 15;     0005300 */
3710 /* L68; 15;     0105300 */
3711 /* L69; 15;     0005400 */
3712 /* L70; 15;     0105400 */
3713 /* L71; 15;     0005500 */
3714 /* L72; 15;     0105500 */
3715 /* L73; 15;     0005600 */
3716 /* L74; 15;     0105600 */
3717 /* L75; 15;     0005700 */
3718 /* L76; 15;     0105700 */
3719 /* L77; 15;     0006000 */
3720 /* L78; 15;     0106000 */
3721 /* L79; 15;     0006100 */
3722 /* L80; 15;     0106100 */
3723 /* L81; 15;     0006200 */
3724 /* L82; 15;     0106200 */
3725 /* L83; 15;     0006300 */
3726 /* L84; 15;     0106300 */
3727 /* L85; 15;     0000100 */
3728 /* L86; 15;     0000300 */
3729 /* L87; 15;     0006500 */
3730 /* L88; 15;     0006600 */
3731 /* L89; 15;     0106500 */
3732 /* L90; 15;     0106600 */
3733 /* L91; 15;     0170300 */
3734 /* L92; 15;     0106700 */
3735 /* L93; 15;     0106400 */
3736 /* L94; 15;     0007000 */
3737 /* L95; 15;     0007200 */
3738 /* L96; 15;     0007300 */
3739
3740 /* jsr */
3741
3742 /* L97; 07;     0004000 */
3743
3744 /* rts */
3745
3746 /* L98; 010;    000200 */
3747
3748 /* simple operand */
3749
3750 /* L99; 011;    104400 */
3751 /* L102;        011;    000230 */
3752
3753 /* flag-setting */
3754
3755 /* L103;        01;     0000240 */
3756 /* L104;        01;     0000241 */
3757 /* L105;        01;     0000242 */
3758 /* L106;        01;     0000244 */
3759 /* L107;        01;     0000250 */
3760 /* L108;        01;     0000257 */
3761 /* L109;        01;     0000261 */
3762 /* L110;        01;     0000262 */
3763 /* L111;        01;     0000264 */
3764 /* L112;        01;     0000270 */
3765 /* L113;        01;     0000277 */
3766 /* L114;        01;     0000000 */
3767 /* L115;        01;     0000001 */
3768 /* L116;        01;     0000002 */
3769 /* L117;        01;     0000003 */
3770 /* L118;        01;     0000004 */
3771 /* L119;        01;     0000005 */
3772 /* L120;        01;     0000006 */
3773 /* L121;        01;     0000007 */
3774
3775 /* floating point ops */
3776
3777 /* L122;        01;     170000 */
3778 /* L123;        01;     170001 */
3779 /* L124;        01;     170011 */
3780 /* L125;        01;     170002 */
3781 /* L126;        01;     170012 */
3782 /* L127;        15;     170400 */
3783 /* L128;        15;     170700 */
3784 /* L129;        15;     170600 */
3785 /* L130;        15;     170500 */
3786 /* L131;        12;     172400 */
3787 /* L132;        14;     177000 */
3788 /* L133;        05;     175400 */
3789 /* L134;        14;     177400 */
3790 /* L135;        05;     176000 */
3791 /* L136;        14;     172000 */
3792 /* L137;        14;     173000 */
3793 /* L138;        14;     171000 */
3794 /* L139;        14;     174400 */
3795 /* L140;        14;     173400 */
3796 /* L141;        14;     171400 */
3797 /* L142;        14;     176400 */
3798 /* L143;        05;     175000 */
3799 /* L144;        15;     170100 */
3800 /* L145;        15;     170200 */
3801 /* L146;        24;     000000 */
3802 /* L147;        24;     000001 */
3803 /* L148;        24;     000002 */
3804 /* L149;        24;     000003 */
3805 /* L150;        24;     000004 */
3806 /* L151;        24;     000005 */
3807
3808 /* L152;        30;     070000 */
3809 /* L153;        30;     071000 */
3810 /* L154;        30;     072000 */
3811 /* L155;        30;     073000 */
3812 /* L156;        07;     074000 */
3813 /* L157;        15;     006700 */
3814 /* L158;        11;     006400 */
3815 /* L159;        31;     077000 */
3816
3817 /* pseudo ops */
3818
3819 /* L160;        16;     000000 */
3820 /* L161;        20;     000000 */
3821 /* L162;        21;     000000 */
3822 /* L163;        22;     000000 */
3823 /* L164;        23;     000000 */
3824 /* L165;        25;     000000 */
3825 /* L166;        26;     000000 */
3826 /* L167;        27;     000000 */
3827 /* L168;        32;     000000 */
3828
3829 /* ebsymtab: */
3830
3831 /* L1:  <.\0> */
3832 /* L2:  <..\0> */
3833 /* L3:  <r0\0> */
3834 /* L4:  <r1\0> */
3835 /* L5:  <r2\0> */
3836 /* L6:  <r3\0> */
3837 /* L7:  <r4\0> */
3838 /* L8:  <r5\0> */
3839 /* L9:  <sp\0> */
3840 /* L10: <pc\0> */
3841 /* L11: <mov\0> */
3842 /* L12: <movb\0> */
3843 /* L13: <cmp\0> */
3844 /* L14: <cmpb\0> */
3845 /* L15: <bit\0> */
3846 /* L16: <bitb\0> */
3847 /* L17: <bic\0> */
3848 /* L18: <bicb\0> */
3849 /* L19: <bis\0> */
3850 /* L20: <bisb\0> */
3851 /* L21: <add\0> */
3852 /* L22: <sub\0> */
3853 /* L23: <br\0> */
3854 /* L24: <bne\0> */
3855 /* L25: <beq\0> */
3856 /* L26: <bge\0> */
3857 /* L27: <blt\0> */
3858 /* L28: <bgt\0> */
3859 /* L29: <ble\0> */
3860 /* L30: <bpl\0> */
3861 /* L31: <bmi\0> */
3862 /* L32: <bhi\0> */
3863 /* L33: <blos\0> */
3864 /* L34: <bvc\0> */
3865 /* L35: <bvs\0> */
3866 /* L36: <bhis\0> */
3867 /* L37: <bec\0> */
3868 /* L38: <bcc\0> */
3869 /* L39: <blo\0> */
3870 /* L40: <bcs\0> */
3871 /* L41: <bes\0> */
3872 /* L42: <jbr\0> */
3873 /* L43: <jne\0> */
3874 /* L44: <jeq\0> */
3875 /* L45: <jge\0> */
3876 /* L46: <jlt\0> */
3877 /* L47: <jgt\0> */
3878 /* L48: <jle\0> */
3879 /* L49: <jpl\0> */
3880 /* L50: <jmi\0> */
3881 /* L51: <jhi\0> */
3882 /* L52: <jlos\0> */
3883 /* L53: <jvc\0> */
3884 /* L54: <jvs\0> */
3885 /* L55: <jhis\0> */
3886 /* L56: <jec\0> */
3887 /* L57: <jcc\0> */
3888 /* L58: <jlo\0> */
3889 /* L59: <jcs\0> */
3890 /* L60: <jes\0> */
3891 /* L61: <clr\0> */
3892 /* L62: <clrb\0> */
3893 /* L63: <com\0> */
3894 /* L64: <comb\0> */
3895 /* L65: <inc\0> */
3896 /* L66: <incb\0> */
3897 /* L67: <dec\0> */
3898 /* L68: <decb\0> */
3899 /* L69: <neg\0> */
3900 /* L70: <negb\0> */
3901 /* L71: <adc\0> */
3902 /* L72: <adcb\0> */
3903 /* L73: <sbc\0> */
3904 /* L74: <sbcb\0> */
3905 /* L75: <tst\0> */
3906 /* L76: <tstb\0> */
3907 /* L77: <ror\0> */
3908 /* L78: <rorb\0> */
3909 /* L79: <rol\0> */
3910 /* L80: <rolb\0> */
3911 /* L81: <asr\0> */
3912 /* L82: <asrb\0> */
3913 /* L83: <asl\0> */
3914 /* L84: <aslb\0> */
3915 /* L85: <jmp\0> */
3916 /* L86: <swab\0> */
3917 /* L87: <mfpi\0> */
3918 /* L88: <mtpi\0> */
3919 /* L89: <mfpd\0> */
3920 /* L90: <mtpd\0> */
3921 /* L91: <stst\0> */
3922 /* L92: <mfps\0> */
3923 /* L93: <mtps\0> */
3924 /* L94: <csm\0> */
3925 /* L95: <tstset\0> */
3926 /* L96: <wrtlck\0> */
3927 /* L97: <jsr\0> */
3928 /* L98: <rts\0> */
3929 /* L99: <sys\0> */
3930 /* L102:        <spl\0> */
3931 /* L103:        <nop\0> */
3932 /* L104:        <clc\0> */
3933 /* L105:        <clv\0> */
3934 /* L106:        <clz\0> */
3935 /* L107:        <cln\0> */
3936 /* L108:        <ccc\0> */
3937 /* L109:        <sec\0> */
3938 /* L110:        <sev\0> */
3939 /* L111:        <sez\0> */
3940 /* L112:        <sen\0> */
3941 /* L113:        <scc\0> */
3942 /* L114:        <halt\0> */
3943 /* L115:        <wait\0> */
3944 /* L116:        <rti\0> */
3945 /* L117:        <bpt\0> */
3946 /* L118:        <iot\0> */
3947 /* L119:        <reset\0> */
3948 /* L120:        <rtt\0> */
3949 /* L121:        <mfpt\0> */
3950 /* L122:        <cfcc\0> */
3951 /* L123:        <setf\0> */
3952 /* L124:        <setd\0> */
3953 /* L125:        <seti\0> */
3954 /* L126:        <setl\0> */
3955 /* L127:        <clrf\0> */
3956 /* L128:        <negf\0> */
3957 /* L129:        <absf\0> */
3958 /* L130:        <tstf\0> */
3959 /* L131:        <movf\0> */
3960 /* L132:        <movif\0> */
3961 /* L133:        <movfi\0> */
3962 /* L134:        <movof\0> */
3963 /* L135:        <movfo\0> */
3964 /* L136:        <addf\0> */
3965 /* L137:        <subf\0> */
3966 /* L138:        <mulf\0> */
3967 /* L139:        <divf\0> */
3968 /* L140:        <cmpf\0> */
3969 /* L141:        <modf\0> */
3970 /* L142:        <movie\0> */
3971 /* L143:        <movei\0> */
3972 /* L144:        <ldfps\0> */
3973 /* L145:        <stfps\0> */
3974 /* L146:        <fr0\0> */
3975 /* L147:        <fr1\0> */
3976 /* L148:        <fr2\0> */
3977 /* L149:        <fr3\0> */
3978 /* L150:        <fr4\0> */
3979 /* L151:        <fr5\0> */
3980 /* L152:        <mul\0> */
3981 /* L153:        <div\0> */
3982 /* L154:        <ash\0> */
3983 /* L155:        <ashc\0> */
3984 /* L156:        <xor\0> */
3985 /* L157:        <sxt\0> */
3986 /* L158:        <mark\0> */
3987 /* L159:        <sob\0> */
3988 /* L160:        <.byte\0> */
3989 /* L161:        <.even\0> */
3990 /* L162:        <.if\0> */
3991 /* L163:        <.endif\0> */
3992 /* L164:        <.globl\0> */
3993 /* L165:        <.text\0> */
3994 /* L166:        <.data\0> */
3995 /* L167:        <.bss\0> */
3996 /* L168:        <.comm\0> */
3997 /*      .text */
3998
3999 struct symbol symtab[] = {
4000         { ".",          FTEXT,          0000000,        0 },
4001         { "..",         FABS,           0000000,        0 },
4002
4003 /* register */
4004
4005         { "r0",         FREGISTER,      0000000,        0 },
4006         { "r1",         FREGISTER,      0000001,        0 },
4007         { "r2",         FREGISTER,      0000002,        0 },
4008         { "r3",         FREGISTER,      0000003,        0 },
4009         { "r4",         FREGISTER,      0000004,        0 },
4010         { "r5",         FREGISTER,      0000005,        0 },
4011         { "sp",         FREGISTER,      0000006,        0 },
4012         { "pc",         FREGISTER,      0000007,        0 },
4013
4014 /* double operand */
4015
4016         { "mov",        FDOUBLE,        0010000,        0 },
4017         { "movb",       FDOUBLE,        0110000,        0 },
4018         { "cmp",        FDOUBLE,        0020000,        0 },
4019         { "cmpb",       FDOUBLE,        0120000,        0 },
4020         { "bit",        FDOUBLE,        0030000,        0 },
4021         { "bitb",       FDOUBLE,        0130000,        0 },
4022         { "bic",        FDOUBLE,        0040000,        0 },
4023         { "bicb",       FDOUBLE,        0140000,        0 },
4024         { "bis",        FDOUBLE,        0050000,        0 },
4025         { "bisb",       FDOUBLE,        0150000,        0 },
4026         { "add",        FDOUBLE,        0060000,        0 },
4027         { "sub",        FDOUBLE,        0160000,        0 },
4028
4029 /* branch */
4030
4031         { "br",         FBRANCH,        0000400,        0 },
4032         { "bne",        FBRANCH,        0001000,        0 },
4033         { "beq",        FBRANCH,        0001400,        0 },
4034         { "bge",        FBRANCH,        0002000,        0 },
4035         { "blt",        FBRANCH,        0002400,        0 },
4036         { "bgt",        FBRANCH,        0003000,        0 },
4037         { "ble",        FBRANCH,        0003400,        0 },
4038         { "bpl",        FBRANCH,        0100000,        0 },
4039         { "bmi",        FBRANCH,        0100400,        0 },
4040         { "bhi",        FBRANCH,        0101000,        0 },
4041         { "blos",       FBRANCH,        0101400,        0 },
4042         { "bvc",        FBRANCH,        0102000,        0 },
4043         { "bvs",        FBRANCH,        0102400,        0 },
4044         { "bhis",       FBRANCH,        0103000,        0 },
4045         { "bec",        FBRANCH,        0103000,        0 },
4046         { "bcc",        FBRANCH,        0103000,        0 },
4047         { "blo",        FBRANCH,        0103400,        0 },
4048         { "bcs",        FBRANCH,        0103400,        0 },
4049         { "bes",        FBRANCH,        0103400,        0 },
4050
4051 /* jump/branch type */
4052
4053         { "jbr",        FJBR,           0000400,        0 },
4054         { "jne",        FJCOND,         0001000,        0 },
4055         { "jeq",        FJCOND,         0001400,        0 },
4056         { "jge",        FJCOND,         0002000,        0 },
4057         { "jlt",        FJCOND,         0002400,        0 },
4058         { "jgt",        FJCOND,         0003000,        0 },
4059         { "jle",        FJCOND,         0003400,        0 },
4060         { "jpl",        FJCOND,         0100000,        0 },
4061         { "jmi",        FJCOND,         0100400,        0 },
4062         { "jhi",        FJCOND,         0101000,        0 },
4063         { "jlos",       FJCOND,         0101400,        0 },
4064         { "jvc",        FJCOND,         0102000,        0 },
4065         { "jvs",        FJCOND,         0102400,        0 },
4066         { "jhis",       FJCOND,         0103000,        0 },
4067         { "jec",        FJCOND,         0103000,        0 },
4068         { "jcc",        FJCOND,         0103000,        0 },
4069         { "jlo",        FJCOND,         0103400,        0 },
4070         { "jcs",        FJCOND,         0103400,        0 },
4071         { "jes",        FJCOND,         0103400,        0 },
4072
4073 /* single operand */
4074
4075         { "clr",        FSINGLE,        0005000,        0 },
4076         { "clrb",       FSINGLE,        0105000,        0 },
4077         { "com",        FSINGLE,        0005100,        0 },
4078         { "comb",       FSINGLE,        0105100,        0 },
4079         { "inc",        FSINGLE,        0005200,        0 },
4080         { "incb",       FSINGLE,        0105200,        0 },
4081         { "dec",        FSINGLE,        0005300,        0 },
4082         { "decb",       FSINGLE,        0105300,        0 },
4083         { "neg",        FSINGLE,        0005400,        0 },
4084         { "negb",       FSINGLE,        0105400,        0 },
4085         { "adc",        FSINGLE,        0005500,        0 },
4086         { "adcb",       FSINGLE,        0105500,        0 },
4087         { "sbc",        FSINGLE,        0005600,        0 },
4088         { "sbcb",       FSINGLE,        0105600,        0 },
4089         { "tst",        FSINGLE,        0005700,        0 },
4090         { "tstb",       FSINGLE,        0105700,        0 },
4091         { "ror",        FSINGLE,        0006000,        0 },
4092         { "rorb",       FSINGLE,        0106000,        0 },
4093         { "rol",        FSINGLE,        0006100,        0 },
4094         { "rolb",       FSINGLE,        0106100,        0 },
4095         { "asr",        FSINGLE,        0006200,        0 },
4096         { "asrb",       FSINGLE,        0106200,        0 },
4097         { "asl",        FSINGLE,        0006300,        0 },
4098         { "aslb",       FSINGLE,        0106300,        0 },
4099         { "jmp",        FSINGLE,        0000100,        0 },
4100         { "swab",       FSINGLE,        0000300,        0 },
4101         { "mfpi",       FSINGLE,        0006500,        0 },
4102         { "mtpi",       FSINGLE,        0006600,        0 },
4103         { "mfpd",       FSINGLE,        0106500,        0 },
4104         { "mtpd",       FSINGLE,        0106600,        0 },
4105         { "stst",       FSINGLE,        0170300,        0 },
4106         { "mfps",       FSINGLE,        0106700,        0 },
4107         { "mtps",       FSINGLE,        0106400,        0 },
4108         { "csm",        FSINGLE,        0007000,        0 },
4109         { "tstset",     FSINGLE,        0007200,        0 },
4110         { "wrtlck",     FSINGLE,        0007300,        0 },
4111
4112 /* jsr */
4113
4114         { "jsr",        FJSR,           0004000,        0 },
4115
4116 /* rts */
4117
4118         { "rts",        FRTS,           0000200,        0 },
4119
4120 /* simple operand */
4121
4122         { "sys",        FSYSTRAP,       0104400,        0 },
4123         { "spl",        FSYSTRAP,       0000230,        0 },
4124
4125 /* flag-setting */
4126
4127         { "nop",        FABS,           0000240,        0 },
4128         { "clc",        FABS,           0000241,        0 },
4129         { "clv",        FABS,           0000242,        0 },
4130         { "clz",        FABS,           0000244,        0 },
4131         { "cln",        FABS,           0000250,        0 },
4132         { "ccc",        FABS,           0000257,        0 },
4133         { "sec",        FABS,           0000261,        0 },
4134         { "sev",        FABS,           0000262,        0 },
4135         { "sez",        FABS,           0000264,        0 },
4136         { "sen",        FABS,           0000270,        0 },
4137         { "scc",        FABS,           0000277,        0 },
4138         { "halt",       FABS,           0000000,        0 },
4139         { "wait",       FABS,           0000001,        0 },
4140         { "rti",        FABS,           0000002,        0 },
4141         { "bpt",        FABS,           0000003,        0 },
4142         { "iot",        FABS,           0000004,        0 },
4143         { "reset",      FABS,           0000005,        0 },
4144         { "rtt",        FABS,           0000006,        0 },
4145         { "mfpt",       FABS,           0000007,        0 },
4146
4147 /* floating point ops */
4148
4149         { "cfcc",       FABS,           0170000,        0 },
4150         { "setf",       FABS,           0170001,        0 },
4151         { "setd",       FABS,           0170011,        0 },
4152         { "seti",       FABS,           0170002,        0 },
4153         { "setl",       FABS,           0170012,        0 },
4154         { "clrf",       FSINGLE,        0170400,        0 },
4155         { "negf",       FSINGLE,        0170700,        0 },
4156         { "absf",       FSINGLE,        0170600,        0 },
4157         { "tstf",       FSINGLE,        0170500,        0 },
4158         { "movf",       FMOVF,          0172400,        0 },
4159         { "movif",      FFLOP,          0177000,        0 },
4160         { "movfi",      FMOVFO,         0175400,        0 },
4161         { "movof",      FFLOP,          0177400,        0 },
4162         { "movfo",      FMOVFO,         0176000,        0 },
4163         { "addf",       FFLOP,          0172000,        0 },
4164         { "subf",       FFLOP,          0173000,        0 },
4165         { "mulf",       FFLOP,          0171000,        0 },
4166         { "divf",       FFLOP,          0174400,        0 },
4167         { "cmpf",       FFLOP,          0173400,        0 },
4168         { "modf",       FFLOP,          0171400,        0 },
4169         { "movie",      FFLOP,          0176400,        0 },
4170         { "movei",      FMOVFO,         0175000,        0 },
4171         { "ldfps",      FSINGLE,        0170100,        0 },
4172         { "stfps",      FSINGLE,        0170200,        0 },
4173         { "fr0",        FREGISTER,      0000000,        0 },
4174         { "fr1",        FREGISTER,      0000001,        0 },
4175         { "fr2",        FREGISTER,      0000002,        0 },
4176         { "fr3",        FREGISTER,      0000003,        0 },
4177         { "fr4",        FREGISTER,      0000004,        0 },
4178         { "fr5",        FREGISTER,      0000005,        0 },
4179
4180         { "mul",        FMULDIV,        0070000,        0 },
4181         { "div",        FMULDIV,        0071000,        0 },
4182         { "ash",        FMULDIV,        0072000,        0 },
4183         { "ashc",       FMULDIV,        0073000,        0 },
4184         { "xor",        FJSR,           0074000,        0 },
4185         { "sxt",        FSINGLE,        0006700,        0 },
4186         { "mark",       FSYSTRAP,       0006400,        0 },
4187         { "sob",        FSOB,           0077000,        0 },
4188
4189 /* pseudo ops */
4190
4191         { ".byte",      FDOTBYTE,       0000000,        0 },
4192 #if 1 /* modifications for dec syntax */
4193         { ".word",      FDOTWORD,       0000000,        0 },
4194 #endif
4195         { ".even",      FDOTEVEN,       0000000,        0 },
4196         { ".if",        FDOTIF,         0000000,        0 },
4197         { ".endif",     FDOTENDIF,      0000000,        0 },
4198         { ".globl",     FDOTGLOBL,      0000000,        0 },
4199         { ".text",      FDOTTEXT,       0000000,        0 },
4200         { ".data",      FDOTDATA,       0000000,        0 },
4201         { ".bss",       FDOTBSS,        0000000,        0 },
4202         { ".comm",      FDOTCOMM,       0000000,        0 }
4203 };
4204
4205 int ebsymtab = sizeof(symtab) / sizeof(struct symbol);
4206