4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber
25 * The module aslist.c contains all the functions used
26 * to generate the assembler list and symbol output files.
28 * aslist.c contains the following functions:
35 * The module aslist.c contains no local/static variables
38 /*)Function VOID list()
40 * The function list() generates the listing output
41 * which includes the input source, line numbers,
42 * and generated code. Numerical output may be selected
43 * as hexadecimal, decimal, or octal.
46 * int * wp pointer to the assembled data bytes
47 * int * wpt pointer to the data byte mode
48 * int nb computed number of assembled bytes
51 * int cb[] array of assembler output values
52 * int cbt[] array of assembler relocation types
53 * describing the data in cb[]
54 * int * cp pointer to assembler output array cb[]
55 * int * cpt pointer to assembler relocation type
57 * char eb[] array of generated error codes
58 * char * ep pointer into error list
60 * char ib[] assembler-source text line
61 * FILE * lfp list output file handle
62 * int line current assembler source line number
63 * int lmode listing mode
64 * int xflag -x, listing radix flag
67 * int fprintf() c_library
68 * VOID list1() aslist.c
69 * int putc() c_library
70 * VOID slew() asslist.c
73 * Listing or symbol output updated.
84 if (lfp == NULL || lmode == NLIST)
88 * Get Correct Line Number
91 line = incline[incfil];
94 line = incline[incfil-1];
96 line = srcline[cfile];
100 line = srcline[cfile];
109 * Output a maximum of NERR error codes with listing.
111 while (ep < &eb[NERR])
113 fprintf(lfp, "%.2s", eb);
116 * Source listing only option.
118 if (lmode == SLIST) {
119 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
123 if (lmode == ALIST) {
131 if (xflag == 0) { /* HEX */
135 if (lmode == ELIST) {
136 fprintf(lfp, "%18s%04X", "", laddr);
137 fprintf(lfp, " %5u %s\n", line, ib);
142 * Address (with allocation)
144 fprintf(lfp, " %04X", laddr);
145 if (lmode == ALIST || lmode == BLIST) {
146 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
154 nb = (int) (cp - cb);
157 * First line of output for this source line with data.
159 list1(wp, wpt, nb, 1);
160 fprintf(lfp, " %5u %s\n", line, ib);
163 * Subsequent lines of output if more data.
165 while ((nb -= 6) > 0) {
169 fprintf(lfp, "%7s", "");
170 list1(wp, wpt, nb, 0);
175 * OCTAL output Option.
177 if (xflag == 1) { /* OCTAL */
181 if (lmode == ELIST) {
182 fprintf(lfp, "%16s%06o", "", laddr);
183 fprintf(lfp, " %5u %s\n", line, ib);
188 * Address (with allocation)
190 fprintf(lfp, " %06o", laddr);
191 if (lmode == ALIST || lmode == BLIST) {
192 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
200 nb = (int) (cp - cb);
203 * First line of output for this source line with data.
205 list1(wp, wpt, nb, 1);
206 fprintf(lfp, " %5u %s\n", line, ib);
209 * Subsequent lines of output if more data.
211 while ((nb -= 4) > 0) {
215 fprintf(lfp, "%9s", "");
216 list1(wp, wpt, nb, 0);
221 * DECIMAL output Option.
223 if (xflag == 2) { /* DECIMAL */
227 if (lmode == ELIST) {
228 fprintf(lfp, "%16s%05u", "", laddr);
229 fprintf(lfp, " %5u %s\n", line, ib);
234 * Address (with allocation)
236 fprintf(lfp, " %05u", laddr);
237 if (lmode == ALIST || lmode == BLIST) {
238 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
246 nb = (int) (cp - cb);
249 * First line of output for this source line with data.
251 list1(wp, wpt, nb, 1);
252 fprintf(lfp, " %5u %s\n", line, ib);
255 * Subsequent lines of output if more data.
257 while ((nb -= 4) > 0) {
261 fprintf(lfp, "%9s", "");
262 list1(wp, wpt, nb, 0);
275 if (lfp == NULL || lmode == NLIST)
279 * Get Correct Line Number
282 line = incline[incfil];
285 line = incline[incfil-1];
287 line = srcline[cfile];
291 line = srcline[cfile];
297 /* Output filename relative_address line_number */
300 fprintf(lfp, "%s ", incfn[incfil]);
303 fprintf(lfp, "%s ", srcfn[cfile]);
305 fprintf(lfp, "%u %04X\n", line, laddr);
309 nb = (int) (cp - cb);
312 * First line of output for this source line with data.
314 list1(wp, wpt, nb, 1);
315 fprintf(lfp, " %5u %s\n", line, ib);
318 * Subsequent lines of output if more data.
320 while ((nb -= 6) > 0) {
324 fprintf(lfp, "%7s", "");
325 list1(wp, wpt, nb, 0);
332 /*)Function VOID list1(wp, wpt, nw, f)
334 * int f fill blank fields (1)
335 * int nb number of data bytes
336 * int * wp pointer to data bytes
337 * int * wpt pointer to data byte mode
343 * int xflag -x, listing radix flag
346 * VOID list2() asslist.c
347 * int fprintf() c_library
350 * Data formatted and output to listing.
354 list1(wp, wpt, nb, f)
356 register int *wpt, nb, f;
363 if (xflag == 0) { /* HEX */
365 * Bound number of words to HEX maximum per line.
373 for (i=0; i<nb; ++i) {
375 fprintf(lfp, "%02X", (*wp++)&0377);
379 * Output blanks if required.
389 * OCTAL output Option.
391 if (xflag == 1) { /* OCTAL */
393 * Bound number of words to OCTAL maximum per line.
401 for (i=0; i<nb; ++i) {
403 fprintf(lfp, "%03o", (*wp++)&0377);
407 * Output blanks if required.
417 * DECIMAL output Option.
419 if (xflag == 2) { /* DECIMAL */
421 * Bound number of words to DECIMAL maximum per line.
429 for (i=0; i<nb; ++i) {
431 fprintf(lfp, "%03u", (*wp++)&0377);
435 * Output blanks if required.
446 /*)Function VOID list2(wpt)
448 * int * wpt pointer to relocation mode
450 * The function list2() outputs the selected
451 * relocation flag as specified by fflag.
454 * int c relocation flag character
455 * int t relocation mode
458 * int fflag -f(f), relocations flagged flag
461 * int putc() c_library
464 * Relocation flag output to listing file.
476 * Designate a relocatable word by `.
484 * Designate a relocatable word by its mode:
487 * operand offset p (q)
488 * relocatable symbol r (s)
492 if (t & (R_PAG0|R_PAG)) {
494 } else if (t & R_USGN) {
496 } else if (t & R_PCR) {
501 if (t & R_HIGH) c += 1;
506 * Output the selected mode.
511 /*)Function VOID slew(fp, flag)
513 * FILE * fp file handle for listing
514 * int flag enable pagination
516 * The function slew() increments the page line count.
517 * If the page overflows and pagination is enabled:
518 * 1) put out a page skip,
521 * 4) and reset the line count.
527 * char cpu[] cpu type string
528 * int lop current line number on page
529 * int page current page number
530 * char stb[] Subtitle string buffer
531 * char tb[] Title string buffer
534 * int fprintf() c_library
537 * Increments page line counter, on overflow
538 * a new page header is output to the listing file.
546 if ((lop++ >= NLPP) && flag) {
547 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
548 VERSION, cpu, ++page);
549 fprintf(fp, "%s\n", tb);
550 fprintf(fp, "%s\n\n", stb);
555 /*)Function VOID lstsym(fp)
557 * FILE * fp file handle for output
559 * The function lstsym() outputs alphabetically
560 * sorted symbol and area tables.
567 * char * ptr pointer to an id string
568 * int nmsym number of symbols
569 * int narea number of areas
570 * sym * sp pointer to symbol structure
571 * sym ** p pointer to an array of
572 * pointers to symbol structures
573 * area * ap pointer to an area structure
576 * area * areap pointer to an area structure
577 * char aretbl[] string "Area Table"
578 * sym dot defined as sym[0]
579 * char stb[] Subtitle string buffer
580 * sym * symhash[] array of pointers to NHASH
581 * linked symbol lists
582 * char symtbl[] string "Symbol Table"
583 * FILE * tfp symbol table output file handle
584 * int xflag -x, listing radix flag
587 * int fprintf() c_library
588 * int putc() c_library
589 * VOID slew() aslist.c
590 * int strcmp() c_library
591 * char * strcpy() c_library
594 * Symbol and area tables output.
601 register int c, i, j, k;
609 * Symbol Table Header
611 strcpy(stb, &symtbl[0]);
618 * Find number of symbols
621 for (i=0; i<NHASH; i++) {
633 * Allocate space for an array of pointers to symbols
636 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
638 fprintf(fp, "Insufficient space to build Symbol Table.\n");
642 for (i=0; i<NHASH; i++) {
652 * Bubble Sort on Symbol Table Array
658 for (i=0; i<c; ++i) {
659 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
669 * Symbol Table Output
671 for (i=0; i<nmsym;) {
674 j = sp->s_area->a_ref;
676 fprintf(fp, " %2X ", j);
679 fprintf(fp, "%3o ", j);
682 fprintf(fp, "%3u ", j);
688 while (ptr < &sp->s_id[NCPS]) {
689 if ((c = *ptr++) != 0) {
695 if (sp->s_flag & S_ASG) {
700 if (sp->s_type == S_NEW) {
702 fprintf(fp, " **** ");
705 fprintf(fp, "****** ");
708 fprintf(fp, " ***** ");
713 fprintf(fp, " %04X ", j);
716 fprintf(fp, "%06o ", j);
719 fprintf(fp, " %05u ", j);
723 if (sp->s_flag & S_GBL) {
727 if (sp->s_area != NULL) {
731 if (sp->s_type == S_NEW) {
758 strcpy(stb, &aretbl[0]);
771 for (i=0; i<narea; ++i) {
773 for (j=i+1; j<narea; ++j)
777 fprintf(fp, " %2X ", j);
780 fprintf(fp, " %3o ", j);
783 fprintf(fp, " %3u ", j);
786 while (ptr < &ap->a_id[NCPS]) {
787 if ((c = *ptr++) != 0) {
796 fprintf(fp, " size %4X flags %X\n", j, k);
799 fprintf(fp, " size %6o flags %o\n", j, k);
802 fprintf(fp, " size %5u flags %u\n", j, k);