4 * (C) Copyright 1989-1995
12 * - lstsym: show s_id as string rather than array [NCPS]
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.
82 if (lfp == NULL || lmode == NLIST)
86 * Get Correct Line Number
89 line = incline[incfil];
92 line = incline[incfil-1];
94 line = srcline[cfile];
98 line = srcline[cfile];
107 * Output a maximum of NERR error codes with listing.
109 while (ep < &eb[NERR])
111 fprintf(lfp, "%.2s", eb);
114 * Source listing only option.
116 if (lmode == SLIST) {
117 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
120 if (lmode == ALIST) {
127 if (xflag == 0) { /* HEX */
131 if (lmode == ELIST) {
132 fprintf(lfp, "%18s%04X", "", laddr);
133 fprintf(lfp, " %5u %s\n", line, ib);
138 * Address (with allocation)
140 fprintf(lfp, " %04X", laddr);
141 if (lmode == ALIST || lmode == BLIST) {
142 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
148 nb = (int) (cp - cb);
151 * First line of output for this source line with data.
153 list1(wp, wpt, nb, 1);
154 fprintf(lfp, " %5u %s\n", line, ib);
157 * Subsequent lines of output if more data.
159 while ((nb -= 6) > 0) {
163 fprintf(lfp, "%7s", "");
164 list1(wp, wpt, nb, 0);
169 * OCTAL output Option.
171 if (xflag == 1) { /* OCTAL */
175 if (lmode == ELIST) {
176 fprintf(lfp, "%16s%06o", "", laddr);
177 fprintf(lfp, " %5u %s\n", line, ib);
182 * Address (with allocation)
184 fprintf(lfp, " %06o", laddr);
185 if (lmode == ALIST || lmode == BLIST) {
186 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
192 nb = (int) (cp - cb);
195 * First line of output for this source line with data.
197 list1(wp, wpt, nb, 1);
198 fprintf(lfp, " %5u %s\n", line, ib);
201 * Subsequent lines of output if more data.
203 while ((nb -= 4) > 0) {
207 fprintf(lfp, "%9s", "");
208 list1(wp, wpt, nb, 0);
213 * DECIMAL output Option.
215 if (xflag == 2) { /* DECIMAL */
219 if (lmode == ELIST) {
220 fprintf(lfp, "%16s%05u", "", laddr);
221 fprintf(lfp, " %5u %s\n", line, ib);
226 * Address (with allocation)
228 fprintf(lfp, " %05u", laddr);
229 if (lmode == ALIST || lmode == BLIST) {
230 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
236 nb = (int) (cp - cb);
239 * First line of output for this source line with data.
241 list1(wp, wpt, nb, 1);
242 fprintf(lfp, " %5u %s\n", line, ib);
245 * Subsequent lines of output if more data.
247 while ((nb -= 4) > 0) {
251 fprintf(lfp, "%9s", "");
252 list1(wp, wpt, nb, 0);
258 /*)Function VOID list1(wp, wpt, nw, f)
260 * int f fill blank fields (1)
261 * int nb number of data bytes
262 * int * wp pointer to data bytes
263 * int * wpt pointer to data byte mode
269 * int xflag -x, listing radix flag
272 * VOID list2() asslist.c
273 * int fprintf() c_library
276 * Data formatted and output to listing.
280 list1(wp, wpt, nb, f)
282 register int *wpt, nb, f;
289 if (xflag == 0) { /* HEX */
291 * Bound number of words to HEX maximum per line.
299 for (i=0; i<nb; ++i) {
301 fprintf(lfp, "%02X", (*wp++)&0377);
305 * Output blanks if required.
315 * OCTAL output Option.
317 if (xflag == 1) { /* OCTAL */
319 * Bound number of words to OCTAL maximum per line.
327 for (i=0; i<nb; ++i) {
329 fprintf(lfp, "%03o", (*wp++)&0377);
333 * Output blanks if required.
343 * DECIMAL output Option.
345 if (xflag == 2) { /* DECIMAL */
347 * Bound number of words to DECIMAL maximum per line.
355 for (i=0; i<nb; ++i) {
357 fprintf(lfp, "%03u", (*wp++)&0377);
361 * Output blanks if required.
372 /*)Function VOID list2(wpt)
374 * int * wpt pointer to relocation mode
376 * The function list2() outputs the selected
377 * relocation flag as specified by fflag.
380 * int c relocation flag character
381 * int t relocation mode
384 * int fflag -f(f), relocations flagged flag
387 * int putc() c_library
390 * Relocation flag output to listing file.
402 * Designate a relocatable word by `.
410 * Designate a relocatable word by its mode:
413 * operand offset p (q)
414 * relocatable symbol r (s)
418 if (t & (R_PAG0|R_PAG)) {
420 } else if (t & R_USGN) {
422 } else if (t & R_PCR) {
427 if (t & R_HIGH) c += 1;
432 * Output the selected mode.
437 /*)Function VOID slew(fp, flag)
439 * FILE * fp file handle for listing
440 * int flag enable pagination
442 * The function slew() increments the page line count.
443 * If the page overflows and pagination is enabled:
444 * 1) put out a page skip,
447 * 4) and reset the line count.
453 * char cpu[] cpu type string
454 * int lop current line number on page
455 * int page current page number
456 * char stb[] Subtitle string buffer
457 * char tb[] Title string buffer
460 * int fprintf() c_library
463 * Increments page line counter, on overflow
464 * a new page header is output to the listing file.
472 if ((lop++ >= NLPP) && flag) {
473 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
474 VERSION, cpu, ++page);
475 fprintf(fp, "%s\n", tb);
476 fprintf(fp, "%s\n\n", stb);
481 /* Used for qsort call in lstsym */
482 static int _cmpSym(const void *p1, const void *p2)
484 struct sym **s1 = (struct sym **)(p1);
485 struct sym **s2 = (struct sym **)(p2);
486 return strcmp((*s1)->s_id,(*s2)->s_id);
489 /*)Function VOID lstsym(fp)
491 * FILE * fp file handle for output
493 * The function lstsym() outputs alphabetically
494 * sorted symbol and area tables.
501 * char * ptr pointer to an id string
502 * int nmsym number of symbols
503 * int narea number of areas
504 * sym * sp pointer to symbol structure
505 * sym ** p pointer to an array of
506 * pointers to symbol structures
507 * area * ap pointer to an area structure
510 * area * areap pointer to an area structure
511 * char aretbl[] string "Area Table"
512 * sym dot defined as sym[0]
513 * char stb[] Subtitle string buffer
514 * sym * symhash[] array of pointers to NHASH
515 * linked symbol lists
516 * char symtbl[] string "Symbol Table"
517 * FILE * tfp symbol table output file handle
518 * int xflag -x, listing radix flag
521 * int fprintf() c_library
522 * int putc() c_library
523 * VOID slew() aslist.c
524 * int strcmp() c_library
525 * char * strcpy() c_library
528 * Symbol and area tables output.
535 register int c, i, j, k;
543 * Symbol Table Header
545 strcpy(stb, &symtbl[0]);
552 * Find number of symbols
555 for (i=0; i<NHASH; i++) {
567 * Allocate space for an array of pointers to symbols
570 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
572 fprintf(fp, "Insufficient space to build Symbol Table.\n");
576 for (i=0; i<NHASH; i++) {
586 /* BUBBLE SORT?? WTF??? */
588 * Bubble Sort on Symbol Table Array
594 for (i=0; i<c; ++i) {
595 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
605 qsort(p, nmsym, sizeof(struct sym *), _cmpSym);
609 * Symbol Table Output
611 for (i=0; i<nmsym;) {
614 j = sp->s_area->a_ref;
616 fprintf(fp, " %2X ", j);
619 fprintf(fp, "%3o ", j);
622 fprintf(fp, "%3u ", j);
628 fprintf(fp, "%-60s", ptr ); /* JLH */
630 if (sp->s_flag & S_ASG) {
635 if (sp->s_type == S_NEW) {
637 fprintf(fp, " **** ");
640 fprintf(fp, "****** ");
643 fprintf(fp, " ***** ");
648 fprintf(fp, " %04X ", j);
651 fprintf(fp, "%06o ", j);
654 fprintf(fp, " %05u ", j);
658 if (sp->s_flag & S_GBL) {
662 if (sp->s_area != NULL) {
666 if (sp->s_type == S_NEW) {
693 strcpy(stb, &aretbl[0]);
706 for (i=0; i<narea; ++i) {
708 for (j=i+1; j<narea; ++j)
712 fprintf(fp, " %2X ", j);
715 fprintf(fp, " %3o ", j);
718 fprintf(fp, " %3u ", j);
721 while (ptr < &ap->a_id[NCPS]) {
722 if ((c = *ptr++) != 0) {
731 fprintf(fp, " size %4X flags %X\n", j, k);
734 fprintf(fp, " size %6o flags %o\n", j, k);
737 fprintf(fp, " size %5u flags %u\n", j, k);