4 * (C) Copyright 1989-1995
12 * - lstsym: show s_id as string rather than array [NCPS]
23 * The module aslist.c contains all the functions used
24 * to generate the assembler list and symbol output files.
26 * aslist.c contains the following functions:
33 * The module aslist.c contains no local/static variables
36 /*)Function VOID list()
38 * The function list() generates the listing output
39 * which includes the input source, line numbers,
40 * and generated code. Numerical output may be selected
41 * as hexadecimal, decimal, or octal.
44 * int * wp pointer to the assembled data bytes
45 * int * wpt pointer to the data byte mode
46 * int nb computed number of assembled bytes
49 * int cb[] array of assembler output values
50 * int cbt[] array of assembler relocation types
51 * describing the data in cb[]
52 * int * cp pointer to assembler output array cb[]
53 * int * cpt pointer to assembler relocation type
55 * char eb[] array of generated error codes
56 * char * ep pointer into error list
58 * char ib[] assembler-source text line
59 * FILE * lfp list output file handle
60 * int line current assembler source line number
61 * int lmode listing mode
62 * int xflag -x, listing radix flag
65 * int fprintf() c_library
66 * VOID list1() aslist.c
67 * int putc() c_library
68 * VOID slew() asslist.c
71 * Listing or symbol output updated.
81 if (lfp == NULL || lmode == NLIST)
85 * Get Correct Line Number
88 line = incline[incfil];
91 line = incline[incfil-1];
93 line = srcline[cfile];
97 line = srcline[cfile];
106 * Output a maximum of NERR error codes with listing.
108 while (ep < &eb[NERR])
110 fprintf(lfp, "%.2s", eb);
113 * Source listing only option.
115 if (lmode == SLIST) {
116 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
119 if (lmode == ALIST) {
126 if (xflag == 0) { /* HEX */
130 if (lmode == ELIST) {
131 fprintf(lfp, "%18s%04X", "", laddr);
132 fprintf(lfp, " %5u %s\n", line, ib);
137 * Address (with allocation)
139 fprintf(lfp, " %04X", laddr);
140 if (lmode == ALIST || lmode == BLIST) {
141 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
147 nb = (int) (cp - cb);
150 * First line of output for this source line with data.
152 list1(wp, wpt, nb, 1);
153 fprintf(lfp, " %5u %s\n", line, ib);
156 * Subsequent lines of output if more data.
158 while ((nb -= 6) > 0) {
162 fprintf(lfp, "%7s", "");
163 list1(wp, wpt, nb, 0);
168 * OCTAL output Option.
170 if (xflag == 1) { /* OCTAL */
174 if (lmode == ELIST) {
175 fprintf(lfp, "%16s%06o", "", laddr);
176 fprintf(lfp, " %5u %s\n", line, ib);
181 * Address (with allocation)
183 fprintf(lfp, " %06o", laddr);
184 if (lmode == ALIST || lmode == BLIST) {
185 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
191 nb = (int) (cp - cb);
194 * First line of output for this source line with data.
196 list1(wp, wpt, nb, 1);
197 fprintf(lfp, " %5u %s\n", line, ib);
200 * Subsequent lines of output if more data.
202 while ((nb -= 4) > 0) {
206 fprintf(lfp, "%9s", "");
207 list1(wp, wpt, nb, 0);
212 * DECIMAL output Option.
214 if (xflag == 2) { /* DECIMAL */
218 if (lmode == ELIST) {
219 fprintf(lfp, "%16s%05u", "", laddr);
220 fprintf(lfp, " %5u %s\n", line, ib);
225 * Address (with allocation)
227 fprintf(lfp, " %05u", laddr);
228 if (lmode == ALIST || lmode == BLIST) {
229 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
235 nb = (int) (cp - cb);
238 * First line of output for this source line with data.
240 list1(wp, wpt, nb, 1);
241 fprintf(lfp, " %5u %s\n", line, ib);
244 * Subsequent lines of output if more data.
246 while ((nb -= 4) > 0) {
250 fprintf(lfp, "%9s", "");
251 list1(wp, wpt, nb, 0);
257 /*)Function VOID list1(wp, wpt, nw, f)
259 * int f fill blank fields (1)
260 * int nb number of data bytes
261 * int * wp pointer to data bytes
262 * int * wpt pointer to data byte mode
268 * int xflag -x, listing radix flag
271 * VOID list2() asslist.c
272 * int fprintf() c_library
275 * Data formatted and output to listing.
279 list1(wp, wpt, nb, f)
281 register int *wpt, nb, f;
288 if (xflag == 0) { /* HEX */
290 * Bound number of words to HEX maximum per line.
298 for (i=0; i<nb; ++i) {
300 fprintf(lfp, "%02X", (*wp++)&0377);
304 * Output blanks if required.
314 * OCTAL output Option.
316 if (xflag == 1) { /* OCTAL */
318 * Bound number of words to OCTAL maximum per line.
326 for (i=0; i<nb; ++i) {
328 fprintf(lfp, "%03o", (*wp++)&0377);
332 * Output blanks if required.
342 * DECIMAL output Option.
344 if (xflag == 2) { /* DECIMAL */
346 * Bound number of words to DECIMAL maximum per line.
354 for (i=0; i<nb; ++i) {
356 fprintf(lfp, "%03u", (*wp++)&0377);
360 * Output blanks if required.
371 /*)Function VOID list2(wpt)
373 * int * wpt pointer to relocation mode
375 * The function list2() outputs the selected
376 * relocation flag as specified by fflag.
379 * int c relocation flag character
380 * int t relocation mode
383 * int fflag -f(f), relocations flagged flag
386 * int putc() c_library
389 * Relocation flag output to listing file.
401 * Designate a relocatable word by `.
409 * Designate a relocatable word by its mode:
412 * operand offset p (q)
413 * relocatable symbol r (s)
417 if (t & (R_PAG0|R_PAG)) {
419 } else if (t & R_USGN) {
421 } else if (t & R_PCR) {
426 if (t & R_HIGH) c += 1;
431 * Output the selected mode.
436 /*)Function VOID slew(fp, flag)
438 * FILE * fp file handle for listing
439 * int flag enable pagination
441 * The function slew() increments the page line count.
442 * If the page overflows and pagination is enabled:
443 * 1) put out a page skip,
446 * 4) and reset the line count.
452 * char cpu[] cpu type string
453 * int lop current line number on page
454 * int page current page number
455 * char stb[] Subtitle string buffer
456 * char tb[] Title string buffer
459 * int fprintf() c_library
462 * Increments page line counter, on overflow
463 * a new page header is output to the listing file.
471 if ((lop++ >= NLPP) && flag) {
472 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
473 VERSION, cpu, ++page);
474 fprintf(fp, "%s\n", tb);
475 fprintf(fp, "%s\n\n", stb);
480 /* Used for qsort call in lstsym */
481 static int _cmpSym(const void *p1, const void *p2)
483 struct sym **s1 = (struct sym **)(p1);
484 struct sym **s2 = (struct sym **)(p2);
485 return strcmp((*s1)->s_id,(*s2)->s_id);
488 /*)Function VOID lstsym(fp)
490 * FILE * fp file handle for output
492 * The function lstsym() outputs alphabetically
493 * sorted symbol and area tables.
500 * char * ptr pointer to an id string
501 * int nmsym number of symbols
502 * int narea number of areas
503 * sym * sp pointer to symbol structure
504 * sym ** p pointer to an array of
505 * pointers to symbol structures
506 * area * ap pointer to an area structure
509 * area * areap pointer to an area structure
510 * char aretbl[] string "Area Table"
511 * sym dot defined as sym[0]
512 * char stb[] Subtitle string buffer
513 * sym * symhash[] array of pointers to NHASH
514 * linked symbol lists
515 * char symtbl[] string "Symbol Table"
516 * FILE * tfp symbol table output file handle
517 * int xflag -x, listing radix flag
520 * int fprintf() c_library
521 * int putc() c_library
522 * VOID slew() aslist.c
523 * int strcmp() c_library
524 * char * strcpy() c_library
527 * Symbol and area tables output.
534 register int c, i, j, k;
542 * Symbol Table Header
544 strcpy(stb, &symtbl[0]);
551 * Find number of symbols
554 for (i=0; i<NHASH; i++) {
566 * Allocate space for an array of pointers to symbols
569 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
571 fprintf(fp, "Insufficient space to build Symbol Table.\n");
575 for (i=0; i<NHASH; i++) {
585 /* BUBBLE SORT?? WTF??? */
587 * Bubble Sort on Symbol Table Array
593 for (i=0; i<c; ++i) {
594 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
604 qsort(p, nmsym, sizeof(struct sym *), _cmpSym);
608 * Symbol Table Output
610 for (i=0; i<nmsym;) {
613 j = sp->s_area->a_ref;
615 fprintf(fp, " %2X ", j);
618 fprintf(fp, "%3o ", j);
621 fprintf(fp, "%3u ", j);
627 fprintf(fp, "%-60s", ptr ); /* JLH */
629 if (sp->s_flag & S_ASG) {
634 if (sp->s_type == S_NEW) {
636 fprintf(fp, " **** ");
639 fprintf(fp, "****** ");
642 fprintf(fp, " ***** ");
647 fprintf(fp, " %04X ", j);
650 fprintf(fp, "%06o ", j);
653 fprintf(fp, " %05u ", j);
657 if (sp->s_flag & S_GBL) {
661 if (sp->s_area != NULL) {
665 if (sp->s_type == S_NEW) {
692 strcpy(stb, &aretbl[0]);
705 for (i=0; i<narea; ++i) {
707 for (j=i+1; j<narea; ++j)
711 fprintf(fp, " %2X ", j);
714 fprintf(fp, " %3o ", j);
717 fprintf(fp, " %3u ", j);
720 while (ptr < &ap->a_id[NCPS]) {
721 if ((c = *ptr++) != 0) {
730 fprintf(fp, " size %4X flags %X\n", j, k);
733 fprintf(fp, " size %6o flags %o\n", j, k);
736 fprintf(fp, " size %5u flags %u\n", j, k);