4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber
26 * The module aslist.c contains all the functions used
27 * to generate the assembler list and symbol output files.
29 * aslist.c contains the following functions:
36 * The module aslist.c contains no local/static variables
39 /*)Function VOID list()
41 * The function list() generates the listing output
42 * which includes the input source, line numbers,
43 * and generated code. Numerical output may be selected
44 * as hexadecimal, decimal, or octal.
47 * int * wp pointer to the assembled data bytes
48 * int * wpt pointer to the data byte mode
49 * int nb computed number of assembled bytes
52 * int cb[] array of assembler output values
53 * int cbt[] array of assembler relocation types
54 * describing the data in cb[]
55 * int * cp pointer to assembler output array cb[]
56 * int * cpt pointer to assembler relocation type
58 * char eb[] array of generated error codes
59 * char * ep pointer into error list
61 * char ib[] assembler-source text line
62 * FILE * lfp list output file handle
63 * int line current assembler source line number
64 * int lmode listing mode
65 * int xflag -x, listing radix flag
68 * int fprintf() c_library
69 * VOID list1() aslist.c
70 * int putc() c_library
71 * VOID slew() asslist.c
74 * Listing or symbol output updated.
85 if (lfp == NULL || lmode == NLIST)
89 * Get Correct Line Number
92 line = incline[incfil];
95 line = incline[incfil-1];
97 line = srcline[cfile];
101 line = srcline[cfile];
110 * Output a maximum of NERR error codes with listing.
112 while (ep < &eb[NERR])
114 fprintf(lfp, "%.2s", eb);
117 * Source listing only option.
119 if (lmode == SLIST) {
120 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
124 if (lmode == ALIST) {
132 if (xflag == 0) { /* HEX */
136 if (lmode == ELIST) {
137 fprintf(lfp, "%18s%04X", "", laddr);
138 fprintf(lfp, " %5u %s\n", line, ib);
143 * Address (with allocation)
145 fprintf(lfp, " %04X", laddr);
146 if (lmode == ALIST || lmode == BLIST) {
147 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
155 nb = (int) (cp - cb);
158 * First line of output for this source line with data.
160 list1(wp, wpt, nb, 1);
161 fprintf(lfp, " %5u %s\n", line, ib);
164 * Subsequent lines of output if more data.
166 while ((nb -= 6) > 0) {
170 fprintf(lfp, "%7s", "");
171 list1(wp, wpt, nb, 0);
176 * OCTAL output Option.
178 if (xflag == 1) { /* OCTAL */
182 if (lmode == ELIST) {
183 fprintf(lfp, "%16s%06o", "", laddr);
184 fprintf(lfp, " %5u %s\n", line, ib);
189 * Address (with allocation)
191 fprintf(lfp, " %06o", laddr);
192 if (lmode == ALIST || lmode == BLIST) {
193 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
201 nb = (int) (cp - cb);
204 * First line of output for this source line with data.
206 list1(wp, wpt, nb, 1);
207 fprintf(lfp, " %5u %s\n", line, ib);
210 * Subsequent lines of output if more data.
212 while ((nb -= 4) > 0) {
216 fprintf(lfp, "%9s", "");
217 list1(wp, wpt, nb, 0);
222 * DECIMAL output Option.
224 if (xflag == 2) { /* DECIMAL */
228 if (lmode == ELIST) {
229 fprintf(lfp, "%16s%05u", "", laddr);
230 fprintf(lfp, " %5u %s\n", line, ib);
235 * Address (with allocation)
237 fprintf(lfp, " %05u", laddr);
238 if (lmode == ALIST || lmode == BLIST) {
239 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
247 nb = (int) (cp - cb);
250 * First line of output for this source line with data.
252 list1(wp, wpt, nb, 1);
253 fprintf(lfp, " %5u %s\n", line, ib);
256 * Subsequent lines of output if more data.
258 while ((nb -= 4) > 0) {
262 fprintf(lfp, "%9s", "");
263 list1(wp, wpt, nb, 0);
276 if (lfp == NULL || lmode == NLIST)
280 * Get Correct Line Number
283 line = incline[incfil];
286 line = incline[incfil-1];
288 line = srcline[cfile];
292 line = srcline[cfile];
298 /* Output filename relative_address line_number */
301 fprintf(lfp, "%s ", incfn[incfil]);
304 fprintf(lfp, "%s ", srcfn[cfile]);
306 fprintf(lfp, "%u %04X\n", line, laddr);
310 nb = (int) (cp - cb);
313 * First line of output for this source line with data.
315 list1(wp, wpt, nb, 1);
316 fprintf(lfp, " %5u %s\n", line, ib);
319 * Subsequent lines of output if more data.
321 while ((nb -= 6) > 0) {
325 fprintf(lfp, "%7s", "");
326 list1(wp, wpt, nb, 0);
333 /*)Function VOID list1(wp, wpt, nw, f)
335 * int f fill blank fields (1)
336 * int nb number of data bytes
337 * int * wp pointer to data bytes
338 * int * wpt pointer to data byte mode
344 * int xflag -x, listing radix flag
347 * VOID list2() asslist.c
348 * int fprintf() c_library
351 * Data formatted and output to listing.
355 list1(wp, wpt, nb, f)
357 register int *wpt, nb, f;
364 if (xflag == 0) { /* HEX */
366 * Bound number of words to HEX maximum per line.
374 for (i=0; i<nb; ++i) {
376 fprintf(lfp, "%02X", (*wp++)&0377);
380 * Output blanks if required.
390 * OCTAL output Option.
392 if (xflag == 1) { /* OCTAL */
394 * Bound number of words to OCTAL maximum per line.
402 for (i=0; i<nb; ++i) {
404 fprintf(lfp, "%03o", (*wp++)&0377);
408 * Output blanks if required.
418 * DECIMAL output Option.
420 if (xflag == 2) { /* DECIMAL */
422 * Bound number of words to DECIMAL maximum per line.
430 for (i=0; i<nb; ++i) {
432 fprintf(lfp, "%03u", (*wp++)&0377);
436 * Output blanks if required.
447 /*)Function VOID list2(wpt)
449 * int * wpt pointer to relocation mode
451 * The function list2() outputs the selected
452 * relocation flag as specified by fflag.
455 * int c relocation flag character
456 * int t relocation mode
459 * int fflag -f(f), relocations flagged flag
462 * int putc() c_library
465 * Relocation flag output to listing file.
477 * Designate a relocatable word by `.
485 * Designate a relocatable word by its mode:
488 * operand offset p (q)
489 * relocatable symbol r (s)
493 if (t & (R_PAG0|R_PAG)) {
495 } else if (t & R_USGN) {
497 } else if (t & R_PCR) {
502 if (t & R_HIGH) c += 1;
507 * Output the selected mode.
512 /*)Function VOID slew(fp, flag)
514 * FILE * fp file handle for listing
515 * int flag enable pagination
517 * The function slew() increments the page line count.
518 * If the page overflows and pagination is enabled:
519 * 1) put out a page skip,
522 * 4) and reset the line count.
528 * char cpu[] cpu type string
529 * int lop current line number on page
530 * int page current page number
531 * char stb[] Subtitle string buffer
532 * char tb[] Title string buffer
535 * int fprintf() c_library
538 * Increments page line counter, on overflow
539 * a new page header is output to the listing file.
547 if ((lop++ >= NLPP) && flag) {
548 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
549 VERSION, cpu, ++page);
550 fprintf(fp, "%s\n", tb);
551 fprintf(fp, "%s\n\n", stb);
556 /*)Function VOID lstsym(fp)
558 * FILE * fp file handle for output
560 * The function lstsym() outputs alphabetically
561 * sorted symbol and area tables.
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.
600 register int c, i, j, k;
607 * Symbol Table Header
609 strcpy(stb, &symtbl[0]);
616 * Find number of symbols
619 for (i=0; i<NHASH; i++) {
631 * Allocate space for an array of pointers to symbols
634 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
636 fprintf(fp, "Insufficient space to build Symbol Table.\n");
640 for (i=0; i<NHASH; i++) {
650 * Bubble Sort on Symbol Table Array
656 for (i=0; i<c; ++i) {
657 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
667 * Symbol Table Output
669 for (i=0; i<nmsym;) {
672 j = sp->s_area->a_ref;
674 fprintf(fp, " %2X ", j);
677 fprintf(fp, "%3o ", j);
680 fprintf(fp, "%3u ", j);
685 fprintf(fp, "%-60s", sp->s_id);
686 if (sp->s_flag & S_ASG) {
691 if (sp->s_type == S_NEW) {
693 fprintf(fp, " **** ");
696 fprintf(fp, "****** ");
699 fprintf(fp, " ***** ");
704 fprintf(fp, " %04X ", j);
707 fprintf(fp, "%06o ", j);
710 fprintf(fp, " %05u ", j);
714 if (sp->s_flag & S_GBL) {
718 if (sp->s_area != NULL) {
722 if (sp->s_type == S_NEW) {
749 strcpy(stb, &aretbl[0]);
762 for (i=0; i<narea; ++i) {
764 for (j=i+1; j<narea; ++j)
768 fprintf(fp, " %2X ", j);
771 fprintf(fp, " %3o ", j);
774 fprintf(fp, " %3u ", j);
776 fprintf(fp, "%-60s", ap->a_id);
780 fprintf(fp, " size %4X flags %X\n", j, k);
783 fprintf(fp, " size %6o flags %o\n", j, k);
786 fprintf(fp, " size %5u flags %u\n", j, k);