4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber
24 * The module aslist.c contains all the functions used
25 * to generate the assembler list and symbol output files.
27 * aslist.c contains the following functions:
34 * The module aslist.c contains no local/static variables
37 /*)Function VOID list()
39 * The function list() generates the listing output
40 * which includes the input source, line numbers,
41 * and generated code. Numerical output may be selected
42 * as hexadecimal, decimal, or octal.
45 * int * wp pointer to the assembled data bytes
46 * int * wpt pointer to the data byte mode
47 * int nb computed number of assembled bytes
50 * int cb[] array of assembler output values
51 * int cbt[] array of assembler relocation types
52 * describing the data in cb[]
53 * int * cp pointer to assembler output array cb[]
54 * int * cpt pointer to assembler relocation type
56 * char eb[] array of generated error codes
57 * char * ep pointer into error list
59 * char ib[] assembler-source text line
60 * FILE * lfp list output file handle
61 * int line current assembler source line number
62 * int lmode listing mode
63 * int xflag -x, listing radix flag
66 * int fprintf() c_library
67 * VOID list1() aslist.c
68 * int putc() c_library
69 * VOID slew() asslist.c
72 * Listing or symbol output updated.
83 if (lfp == NULL || lmode == NLIST)
87 * Get Correct Line Number
90 line = incline[incfil];
93 line = incline[incfil-1];
95 line = srcline[cfile];
99 line = srcline[cfile];
108 * Output a maximum of NERR error codes with listing.
110 while (ep < &eb[NERR])
112 fprintf(lfp, "%.2s", eb);
115 * Source listing only option.
117 if (lmode == SLIST) {
118 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
122 if (lmode == ALIST) {
130 if (xflag == 0) { /* HEX */
134 if (lmode == ELIST) {
135 fprintf(lfp, "%18s%04X", "", laddr);
136 fprintf(lfp, " %5u %s\n", line, ib);
141 * Address (with allocation)
143 fprintf(lfp, " %04X", laddr);
144 if (lmode == ALIST || lmode == BLIST) {
145 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
153 nb = (int) (cp - cb);
156 * First line of output for this source line with data.
158 list1(wp, wpt, nb, 1);
159 fprintf(lfp, " %5u %s\n", line, ib);
162 * Subsequent lines of output if more data.
164 while ((nb -= 6) > 0) {
168 fprintf(lfp, "%7s", "");
169 list1(wp, wpt, nb, 0);
174 * OCTAL output Option.
176 if (xflag == 1) { /* OCTAL */
180 if (lmode == ELIST) {
181 fprintf(lfp, "%16s%06o", "", laddr);
182 fprintf(lfp, " %5u %s\n", line, ib);
187 * Address (with allocation)
189 fprintf(lfp, " %06o", laddr);
190 if (lmode == ALIST || lmode == BLIST) {
191 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
199 nb = (int) (cp - cb);
202 * First line of output for this source line with data.
204 list1(wp, wpt, nb, 1);
205 fprintf(lfp, " %5u %s\n", line, ib);
208 * Subsequent lines of output if more data.
210 while ((nb -= 4) > 0) {
214 fprintf(lfp, "%9s", "");
215 list1(wp, wpt, nb, 0);
220 * DECIMAL output Option.
222 if (xflag == 2) { /* DECIMAL */
226 if (lmode == ELIST) {
227 fprintf(lfp, "%16s%05u", "", laddr);
228 fprintf(lfp, " %5u %s\n", line, ib);
233 * Address (with allocation)
235 fprintf(lfp, " %05u", laddr);
236 if (lmode == ALIST || lmode == BLIST) {
237 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
245 nb = (int) (cp - cb);
248 * First line of output for this source line with data.
250 list1(wp, wpt, nb, 1);
251 fprintf(lfp, " %5u %s\n", line, ib);
254 * Subsequent lines of output if more data.
256 while ((nb -= 4) > 0) {
260 fprintf(lfp, "%9s", "");
261 list1(wp, wpt, nb, 0);
274 if (lfp == NULL || lmode == NLIST)
278 * Get Correct Line Number
281 line = incline[incfil];
284 line = incline[incfil-1];
286 line = srcline[cfile];
290 line = srcline[cfile];
296 /* Output filename relative_address line_number */
299 fprintf(lfp, "%s ", incfn[incfil]);
302 fprintf(lfp, "%s ", srcfn[cfile]);
304 fprintf(lfp, "%u %04X\n", line, laddr);
308 nb = (int) (cp - cb);
311 * First line of output for this source line with data.
313 list1(wp, wpt, nb, 1);
314 fprintf(lfp, " %5u %s\n", line, ib);
317 * Subsequent lines of output if more data.
319 while ((nb -= 6) > 0) {
323 fprintf(lfp, "%7s", "");
324 list1(wp, wpt, nb, 0);
331 /*)Function VOID list1(wp, wpt, nw, f)
333 * int f fill blank fields (1)
334 * int nb number of data bytes
335 * int * wp pointer to data bytes
336 * int * wpt pointer to data byte mode
342 * int xflag -x, listing radix flag
345 * VOID list2() asslist.c
346 * int fprintf() c_library
349 * Data formatted and output to listing.
353 list1(wp, wpt, nb, f)
355 register int *wpt, nb, f;
362 if (xflag == 0) { /* HEX */
364 * Bound number of words to HEX maximum per line.
372 for (i=0; i<nb; ++i) {
374 fprintf(lfp, "%02X", (*wp++)&0377);
378 * Output blanks if required.
388 * OCTAL output Option.
390 if (xflag == 1) { /* OCTAL */
392 * Bound number of words to OCTAL maximum per line.
400 for (i=0; i<nb; ++i) {
402 fprintf(lfp, "%03o", (*wp++)&0377);
406 * Output blanks if required.
416 * DECIMAL output Option.
418 if (xflag == 2) { /* DECIMAL */
420 * Bound number of words to DECIMAL maximum per line.
428 for (i=0; i<nb; ++i) {
430 fprintf(lfp, "%03u", (*wp++)&0377);
434 * Output blanks if required.
445 /*)Function VOID list2(wpt)
447 * int * wpt pointer to relocation mode
449 * The function list2() outputs the selected
450 * relocation flag as specified by fflag.
453 * int c relocation flag character
454 * int t relocation mode
457 * int fflag -f(f), relocations flagged flag
460 * int putc() c_library
463 * Relocation flag output to listing file.
475 * Designate a relocatable word by `.
483 * Designate a relocatable word by its mode:
486 * operand offset p (q)
487 * relocatable symbol r (s)
491 if (t & (R_PAG0|R_PAG)) {
493 } else if (t & R_USGN) {
495 } else if (t & R_PCR) {
500 if (t & R_HIGH) c += 1;
505 * Output the selected mode.
510 /*)Function VOID slew(fp, flag)
512 * FILE * fp file handle for listing
513 * int flag enable pagination
515 * The function slew() increments the page line count.
516 * If the page overflows and pagination is enabled:
517 * 1) put out a page skip,
520 * 4) and reset the line count.
526 * char cpu[] cpu type string
527 * int lop current line number on page
528 * int page current page number
529 * char stb[] Subtitle string buffer
530 * char tb[] Title string buffer
533 * int fprintf() c_library
536 * Increments page line counter, on overflow
537 * a new page header is output to the listing file.
545 if ((lop++ >= NLPP) && flag) {
546 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
547 VERSION, cpu, ++page);
548 fprintf(fp, "%s\n", tb);
549 fprintf(fp, "%s\n\n", stb);
554 /*)Function VOID lstsym(fp)
556 * FILE * fp file handle for output
558 * The function lstsym() outputs alphabetically
559 * sorted symbol and area tables.
566 * char * ptr pointer to an id string
567 * int nmsym number of symbols
568 * int narea number of areas
569 * sym * sp pointer to symbol structure
570 * sym ** p pointer to an array of
571 * pointers to symbol structures
572 * area * ap pointer to an area structure
575 * area * areap pointer to an area structure
576 * char aretbl[] string "Area Table"
577 * sym dot defined as sym[0]
578 * char stb[] Subtitle string buffer
579 * sym * symhash[] array of pointers to NHASH
580 * linked symbol lists
581 * char symtbl[] string "Symbol Table"
582 * FILE * tfp symbol table output file handle
583 * int xflag -x, listing radix flag
586 * int fprintf() c_library
587 * int putc() c_library
588 * VOID slew() aslist.c
589 * int strcmp() c_library
590 * char * strcpy() c_library
593 * Symbol and area tables output.
600 register int c, i, j, k;
608 * Symbol Table Header
610 strcpy(stb, &symtbl[0]);
617 * Find number of symbols
620 for (i=0; i<NHASH; i++) {
632 * Allocate space for an array of pointers to symbols
635 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
637 fprintf(fp, "Insufficient space to build Symbol Table.\n");
641 for (i=0; i<NHASH; i++) {
651 * Bubble Sort on Symbol Table Array
657 for (i=0; i<c; ++i) {
658 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
668 * Symbol Table Output
670 for (i=0; i<nmsym;) {
673 j = sp->s_area->a_ref;
675 fprintf(fp, " %2X ", j);
678 fprintf(fp, "%3o ", j);
681 fprintf(fp, "%3u ", j);
687 while (ptr < &sp->s_id[NCPS]) {
688 if ((c = *ptr++) != 0) {
694 if (sp->s_flag & S_ASG) {
699 if (sp->s_type == S_NEW) {
701 fprintf(fp, " **** ");
704 fprintf(fp, "****** ");
707 fprintf(fp, " ***** ");
712 fprintf(fp, " %04X ", j);
715 fprintf(fp, "%06o ", j);
718 fprintf(fp, " %05u ", j);
722 if (sp->s_flag & S_GBL) {
726 if (sp->s_area != NULL) {
730 if (sp->s_type == S_NEW) {
757 strcpy(stb, &aretbl[0]);
770 for (i=0; i<narea; ++i) {
772 for (j=i+1; j<narea; ++j)
776 fprintf(fp, " %2X ", j);
779 fprintf(fp, " %3o ", j);
782 fprintf(fp, " %3u ", j);
785 while (ptr < &ap->a_id[NCPS]) {
786 if ((c = *ptr++) != 0) {
795 fprintf(fp, " size %4X flags %X\n", j, k);
798 fprintf(fp, " size %6o flags %o\n", j, k);
801 fprintf(fp, " size %5u flags %u\n", j, k);