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 /*)Function VOID lstsym(fp)
482 * FILE * fp file handle for output
484 * The function lstsym() outputs alphabetically
485 * sorted symbol and area tables.
492 * char * ptr pointer to an id string
493 * int nmsym number of symbols
494 * int narea number of areas
495 * sym * sp pointer to symbol structure
496 * sym ** p pointer to an array of
497 * pointers to symbol structures
498 * area * ap pointer to an area structure
501 * area * areap pointer to an area structure
502 * char aretbl[] string "Area Table"
503 * sym dot defined as sym[0]
504 * char stb[] Subtitle string buffer
505 * sym * symhash[] array of pointers to NHASH
506 * linked symbol lists
507 * char symtbl[] string "Symbol Table"
508 * FILE * tfp symbol table output file handle
509 * int xflag -x, listing radix flag
512 * int fprintf() c_library
513 * int putc() c_library
514 * VOID slew() aslist.c
515 * int strcmp() c_library
516 * char * strcpy() c_library
519 * Symbol and area tables output.
526 register int c, i, j, k;
534 * Symbol Table Header
536 strcpy(stb, &symtbl[0]);
543 * Find number of symbols
546 for (i=0; i<NHASH; i++) {
558 * Allocate space for an array of pointers to symbols
561 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
563 fprintf(fp, "Insufficient space to build Symbol Table.\n");
567 for (i=0; i<NHASH; i++) {
577 * Bubble Sort on Symbol Table Array
583 for (i=0; i<c; ++i) {
584 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
594 * Symbol Table Output
596 for (i=0; i<nmsym;) {
599 j = sp->s_area->a_ref;
601 fprintf(fp, " %2X ", j);
604 fprintf(fp, "%3o ", j);
607 fprintf(fp, "%3u ", j);
613 fprintf(fp, "%-60s", ptr ); /* JLH */
615 if (sp->s_flag & S_ASG) {
620 if (sp->s_type == S_NEW) {
622 fprintf(fp, " **** ");
625 fprintf(fp, "****** ");
628 fprintf(fp, " ***** ");
633 fprintf(fp, " %04X ", j);
636 fprintf(fp, "%06o ", j);
639 fprintf(fp, " %05u ", j);
643 if (sp->s_flag & S_GBL) {
647 if (sp->s_area != NULL) {
651 if (sp->s_type == S_NEW) {
678 strcpy(stb, &aretbl[0]);
691 for (i=0; i<narea; ++i) {
693 for (j=i+1; j<narea; ++j)
697 fprintf(fp, " %2X ", j);
700 fprintf(fp, " %3o ", j);
703 fprintf(fp, " %3u ", j);
706 while (ptr < &ap->a_id[NCPS]) {
707 if ((c = *ptr++) != 0) {
716 fprintf(fp, " size %4X flags %X\n", j, k);
719 fprintf(fp, " size %6o flags %o\n", j, k);
722 fprintf(fp, " size %5u flags %u\n", j, k);