3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 * Extensions: P. Felber
33 * The module aslist.c contains all the functions used
34 * to generate the assembler list and symbol output files.
36 * aslist.c contains the following functions:
43 * The module aslist.c contains no local/static variables
46 /*)Function VOID list()
48 * The function list() generates the listing output
49 * which includes the input source, line numbers,
50 * and generated code. Numerical output may be selected
51 * as hexadecimal, decimal, or octal.
54 * int * wp pointer to the assembled data bytes
55 * int * wpt pointer to the data byte mode
56 * int nb computed number of assembled bytes
59 * int cb[] array of assembler output values
60 * int cbt[] array of assembler relocation types
61 * describing the data in cb[]
62 * int * cp pointer to assembler output array cb[]
63 * int * cpt pointer to assembler relocation type
65 * char eb[] array of generated error codes
66 * char * ep pointer into error list
68 * char ib[] assembler-source text line
69 * FILE * lfp list output file handle
70 * int line current assembler source line number
71 * int lmode listing mode
72 * int xflag -x, listing radix flag
75 * int fprintf() c_library
76 * VOID list1() aslist.c
77 * int putc() c_library
78 * VOID slew() asslist.c
81 * Listing or symbol output updated.
92 if (lfp == NULL || lmode == NLIST)
96 * Get Correct Line Number
99 line = incline[incfil];
102 line = incline[incfil-1];
104 line = srcline[cfile];
108 line = srcline[cfile];
117 * Output a maximum of NERR error codes with listing.
119 while (ep < &eb[NERR])
121 fprintf(lfp, "%.2s", eb);
124 * Source listing only option.
126 if (lmode == SLIST) {
127 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
131 if (lmode == ALIST) {
139 if (xflag == 0) { /* HEX */
143 if (lmode == ELIST) {
144 fprintf(lfp, "%18s%04X", "", laddr);
145 fprintf(lfp, " %5u %s\n", line, ib);
150 * Address (with allocation)
152 fprintf(lfp, " %04X", laddr);
153 if (lmode == ALIST || lmode == BLIST) {
154 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
162 nb = (int) (cp - cb);
165 * First line of output for this source line with data.
167 list1(wp, wpt, nb, 1);
168 fprintf(lfp, " %5u %s\n", line, ib);
171 * Subsequent lines of output if more data.
173 while ((nb -= 6) > 0) {
177 fprintf(lfp, "%7s", "");
178 list1(wp, wpt, nb, 0);
183 * OCTAL output Option.
185 if (xflag == 1) { /* OCTAL */
189 if (lmode == ELIST) {
190 fprintf(lfp, "%16s%06o", "", laddr);
191 fprintf(lfp, " %5u %s\n", line, ib);
196 * Address (with allocation)
198 fprintf(lfp, " %06o", laddr);
199 if (lmode == ALIST || lmode == BLIST) {
200 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
208 nb = (int) (cp - cb);
211 * First line of output for this source line with data.
213 list1(wp, wpt, nb, 1);
214 fprintf(lfp, " %5u %s\n", line, ib);
217 * Subsequent lines of output if more data.
219 while ((nb -= 4) > 0) {
223 fprintf(lfp, "%9s", "");
224 list1(wp, wpt, nb, 0);
229 * DECIMAL output Option.
231 if (xflag == 2) { /* DECIMAL */
235 if (lmode == ELIST) {
236 fprintf(lfp, "%16s%05u", "", laddr);
237 fprintf(lfp, " %5u %s\n", line, ib);
242 * Address (with allocation)
244 fprintf(lfp, " %05u", laddr);
245 if (lmode == ALIST || lmode == BLIST) {
246 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
254 nb = (int) (cp - cb);
257 * First line of output for this source line with data.
259 list1(wp, wpt, nb, 1);
260 fprintf(lfp, " %5u %s\n", line, ib);
263 * Subsequent lines of output if more data.
265 while ((nb -= 4) > 0) {
269 fprintf(lfp, "%9s", "");
270 list1(wp, wpt, nb, 0);
283 if (lfp == NULL || lmode == NLIST)
287 * Get Correct Line Number
290 line = incline[incfil];
293 line = incline[incfil-1];
295 line = srcline[cfile];
299 line = srcline[cfile];
305 /* Output filename relative_address line_number */
308 fprintf(lfp, "%s ", incfn[incfil]);
311 fprintf(lfp, "%s ", srcfn[cfile]);
313 fprintf(lfp, "%u %04X\n", line, laddr);
317 nb = (int) (cp - cb);
320 * First line of output for this source line with data.
322 list1(wp, wpt, nb, 1);
323 fprintf(lfp, " %5u %s\n", line, ib);
326 * Subsequent lines of output if more data.
328 while ((nb -= 6) > 0) {
332 fprintf(lfp, "%7s", "");
333 list1(wp, wpt, nb, 0);
340 /*)Function VOID list1(wp, wpt, nw, f)
342 * int f fill blank fields (1)
343 * int nb number of data bytes
344 * int * wp pointer to data bytes
345 * int * wpt pointer to data byte mode
351 * int xflag -x, listing radix flag
354 * VOID list2() asslist.c
355 * int fprintf() c_library
358 * Data formatted and output to listing.
362 list1(wp, wpt, nb, f)
364 register int *wpt, nb, f;
371 if (xflag == 0) { /* HEX */
373 * Bound number of words to HEX maximum per line.
381 for (i=0; i<nb; ++i) {
383 fprintf(lfp, "%02X", (*wp++)&0377);
387 * Output blanks if required.
397 * OCTAL output Option.
399 if (xflag == 1) { /* OCTAL */
401 * Bound number of words to OCTAL maximum per line.
409 for (i=0; i<nb; ++i) {
411 fprintf(lfp, "%03o", (*wp++)&0377);
415 * Output blanks if required.
425 * DECIMAL output Option.
427 if (xflag == 2) { /* DECIMAL */
429 * Bound number of words to DECIMAL maximum per line.
437 for (i=0; i<nb; ++i) {
439 fprintf(lfp, "%03u", (*wp++)&0377);
443 * Output blanks if required.
454 /*)Function VOID list2(wpt)
456 * int * wpt pointer to relocation mode
458 * The function list2() outputs the selected
459 * relocation flag as specified by fflag.
462 * int c relocation flag character
463 * int t relocation mode
466 * int fflag -f(f), relocations flagged flag
469 * int putc() c_library
472 * Relocation flag output to listing file.
484 * Designate a relocatable word by `.
492 * Designate a relocatable word by its mode:
495 * operand offset p (q)
496 * relocatable symbol r (s)
500 if (t & (R_PAG0|R_PAG)) {
502 } else if (t & R_USGN) {
504 } else if (t & R_PCR) {
509 if (t & R_HIGH) c += 1;
514 * Output the selected mode.
519 /*)Function VOID slew(fp, flag)
521 * FILE * fp file handle for listing
522 * int flag enable pagination
524 * The function slew() increments the page line count.
525 * If the page overflows and pagination is enabled:
526 * 1) put out a page skip,
529 * 4) and reset the line count.
535 * char cpu[] cpu type string
536 * int lop current line number on page
537 * int page current page number
538 * char stb[] Subtitle string buffer
539 * char tb[] Title string buffer
542 * int fprintf() c_library
545 * Increments page line counter, on overflow
546 * a new page header is output to the listing file.
554 if ((lop++ >= NLPP) && flag) {
555 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
556 VERSION, cpu, ++page);
557 fprintf(fp, "%s\n", tb);
558 fprintf(fp, "%s\n\n", stb);
563 /*)Function VOID lstsym(fp)
565 * FILE * fp file handle for output
567 * The function lstsym() outputs alphabetically
568 * sorted symbol and area tables.
575 * int nmsym number of symbols
576 * int narea number of areas
577 * sym * sp pointer to symbol structure
578 * sym ** p pointer to an array of
579 * pointers to symbol structures
580 * area * ap pointer to an area structure
583 * area * areap pointer to an area structure
584 * char aretbl[] string "Area Table"
585 * sym dot defined as sym[0]
586 * char stb[] Subtitle string buffer
587 * sym * symhash[] array of pointers to NHASH
588 * linked symbol lists
589 * char symtbl[] string "Symbol Table"
590 * FILE * tfp symbol table output file handle
591 * int xflag -x, listing radix flag
594 * int fprintf() c_library
595 * int putc() c_library
596 * VOID slew() aslist.c
597 * int strcmp() c_library
598 * char * strcpy() c_library
601 * Symbol and area tables output.
607 register int c, i, j, k;
614 * Symbol Table Header
616 strcpy(stb, &symtbl[0]);
623 * Find number of symbols
626 for (i=0; i<NHASH; i++) {
638 * Allocate space for an array of pointers to symbols
641 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
643 fprintf(fp, "Insufficient space to build Symbol Table.\n");
647 for (i=0; i<NHASH; i++) {
657 * Bubble Sort on Symbol Table Array
663 for (i=0; i<c; ++i) {
664 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
674 * Symbol Table Output
676 for (i=0; i<nmsym;) {
679 j = sp->s_area->a_ref;
681 fprintf(fp, " %2X ", j);
684 fprintf(fp, "%3o ", j);
687 fprintf(fp, "%3u ", j);
692 fprintf(fp, "%-60s", sp->s_id);
693 if (sp->s_flag & S_ASG) {
698 if (sp->s_type == S_NEW) {
700 fprintf(fp, " **** ");
703 fprintf(fp, "****** ");
706 fprintf(fp, " ***** ");
711 fprintf(fp, " %04X ", j);
714 fprintf(fp, "%06o ", j);
717 fprintf(fp, " %05u ", j);
721 if (sp->s_flag & S_GBL) {
725 if (sp->s_area != NULL) {
729 if (sp->s_type == S_NEW) {
756 strcpy(stb, &aretbl[0]);
769 for (i=0; i<narea; ++i) {
771 for (j=i+1; j<narea; ++j)
775 fprintf(fp, " %2X ", j);
778 fprintf(fp, " %3o ", j);
781 fprintf(fp, " %3u ", j);
783 fprintf(fp, "%-60s", ap->a_id);
787 fprintf(fp, " size %4X flags %X\n", j, k);
790 fprintf(fp, " size %6o flags %o\n", j, k);
793 fprintf(fp, " size %5u flags %u\n", j, k);