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/>. */
21 * - lstsym: show s_id as string rather than array [NCPS]
32 * The module aslist.c contains all the functions used
33 * to generate the assembler list and symbol output files.
35 * aslist.c contains the following functions:
42 * The module aslist.c contains no local/static variables
45 /*)Function VOID list()
47 * The function list() generates the listing output
48 * which includes the input source, line numbers,
49 * and generated code. Numerical output may be selected
50 * as hexadecimal, decimal, or octal.
53 * int * wp pointer to the assembled data bytes
54 * int * wpt pointer to the data byte mode
55 * int nb computed number of assembled bytes
58 * int cb[] array of assembler output values
59 * int cbt[] array of assembler relocation types
60 * describing the data in cb[]
61 * int * cp pointer to assembler output array cb[]
62 * int * cpt pointer to assembler relocation type
64 * char eb[] array of generated error codes
65 * char * ep pointer into error list
67 * char ib[] assembler-source text line
68 * FILE * lfp list output file handle
69 * int line current assembler source line number
70 * int lmode listing mode
71 * int xflag -x, listing radix flag
74 * int fprintf() c_library
75 * VOID list1() aslist.c
76 * int putc() c_library
77 * VOID slew() asslist.c
80 * Listing or symbol output updated.
90 if (lfp == NULL || lmode == NLIST)
94 * Get Correct Line Number
97 line = incline[incfil];
100 line = incline[incfil-1];
102 line = srcline[cfile];
106 line = srcline[cfile];
115 * Output a maximum of NERR error codes with listing.
117 while (ep < &eb[NERR])
119 fprintf(lfp, "%.2s", eb);
122 * Source listing only option.
124 if (lmode == SLIST) {
125 fprintf(lfp, "%24s%5u %s\n", "", line, ib);
128 if (lmode == ALIST) {
135 if (xflag == 0) { /* HEX */
139 if (lmode == ELIST) {
140 fprintf(lfp, "%18s%04X", "", laddr);
141 fprintf(lfp, " %5u %s\n", line, ib);
146 * Address (with allocation)
148 fprintf(lfp, " %04X", laddr);
149 if (lmode == ALIST || lmode == BLIST) {
150 fprintf(lfp, "%19s%5u %s\n", "", line, ib);
156 nb = (int) (cp - cb);
159 * First line of output for this source line with data.
161 list1(wp, wpt, nb, 1);
162 fprintf(lfp, " %5u %s\n", line, ib);
165 * Subsequent lines of output if more data.
167 while ((nb -= 6) > 0) {
171 fprintf(lfp, "%7s", "");
172 list1(wp, wpt, nb, 0);
177 * OCTAL output Option.
179 if (xflag == 1) { /* OCTAL */
183 if (lmode == ELIST) {
184 fprintf(lfp, "%16s%06o", "", laddr);
185 fprintf(lfp, " %5u %s\n", line, ib);
190 * Address (with allocation)
192 fprintf(lfp, " %06o", laddr);
193 if (lmode == ALIST || lmode == BLIST) {
194 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
200 nb = (int) (cp - cb);
203 * First line of output for this source line with data.
205 list1(wp, wpt, nb, 1);
206 fprintf(lfp, " %5u %s\n", line, ib);
209 * Subsequent lines of output if more data.
211 while ((nb -= 4) > 0) {
215 fprintf(lfp, "%9s", "");
216 list1(wp, wpt, nb, 0);
221 * DECIMAL output Option.
223 if (xflag == 2) { /* DECIMAL */
227 if (lmode == ELIST) {
228 fprintf(lfp, "%16s%05u", "", laddr);
229 fprintf(lfp, " %5u %s\n", line, ib);
234 * Address (with allocation)
236 fprintf(lfp, " %05u", laddr);
237 if (lmode == ALIST || lmode == BLIST) {
238 fprintf(lfp, "%17s%5u %s\n", "", line, ib);
244 nb = (int) (cp - cb);
247 * First line of output for this source line with data.
249 list1(wp, wpt, nb, 1);
250 fprintf(lfp, " %5u %s\n", line, ib);
253 * Subsequent lines of output if more data.
255 while ((nb -= 4) > 0) {
259 fprintf(lfp, "%9s", "");
260 list1(wp, wpt, nb, 0);
266 /*)Function VOID list1(wp, wpt, nw, f)
268 * int f fill blank fields (1)
269 * int nb number of data bytes
270 * int * wp pointer to data bytes
271 * int * wpt pointer to data byte mode
277 * int xflag -x, listing radix flag
280 * VOID list2() asslist.c
281 * int fprintf() c_library
284 * Data formatted and output to listing.
288 list1(wp, wpt, nb, f)
290 register int *wpt, nb, f;
297 if (xflag == 0) { /* HEX */
299 * Bound number of words to HEX maximum per line.
307 for (i=0; i<nb; ++i) {
309 fprintf(lfp, "%02X", (*wp++)&0377);
313 * Output blanks if required.
323 * OCTAL output Option.
325 if (xflag == 1) { /* OCTAL */
327 * Bound number of words to OCTAL maximum per line.
335 for (i=0; i<nb; ++i) {
337 fprintf(lfp, "%03o", (*wp++)&0377);
341 * Output blanks if required.
351 * DECIMAL output Option.
353 if (xflag == 2) { /* DECIMAL */
355 * Bound number of words to DECIMAL maximum per line.
363 for (i=0; i<nb; ++i) {
365 fprintf(lfp, "%03u", (*wp++)&0377);
369 * Output blanks if required.
380 /*)Function VOID list2(wpt)
382 * int * wpt pointer to relocation mode
384 * The function list2() outputs the selected
385 * relocation flag as specified by fflag.
388 * int c relocation flag character
389 * int t relocation mode
392 * int fflag -f(f), relocations flagged flag
395 * int putc() c_library
398 * Relocation flag output to listing file.
410 * Designate a relocatable word by `.
418 * Designate a relocatable word by its mode:
421 * operand offset p (q)
422 * relocatable symbol r (s)
426 if (t & (R_PAG0|R_PAG)) {
428 } else if (t & R_USGN) {
430 } else if (t & R_PCR) {
435 if (t & R_HIGH) c += 1;
440 * Output the selected mode.
445 /*)Function VOID slew(fp, flag)
447 * FILE * fp file handle for listing
448 * int flag enable pagination
450 * The function slew() increments the page line count.
451 * If the page overflows and pagination is enabled:
452 * 1) put out a page skip,
455 * 4) and reset the line count.
461 * char cpu[] cpu type string
462 * int lop current line number on page
463 * int page current page number
464 * char stb[] Subtitle string buffer
465 * char tb[] Title string buffer
468 * int fprintf() c_library
471 * Increments page line counter, on overflow
472 * a new page header is output to the listing file.
480 if ((lop++ >= NLPP) && flag) {
481 fprintf(fp, "\fASxxxx Assembler %s (%s), page %u.\n",
482 VERSION, cpu, ++page);
483 fprintf(fp, "%s\n", tb);
484 fprintf(fp, "%s\n\n", stb);
489 /* Used for qsort call in lstsym */
490 static int _cmpSym(const void *p1, const void *p2)
492 struct sym **s1 = (struct sym **)(p1);
493 struct sym **s2 = (struct sym **)(p2);
494 return strcmp((*s1)->s_id,(*s2)->s_id);
497 /*)Function VOID lstsym(fp)
499 * FILE * fp file handle for output
501 * The function lstsym() outputs alphabetically
502 * sorted symbol and area tables.
509 * char * ptr pointer to an id string
510 * int nmsym number of symbols
511 * int narea number of areas
512 * sym * sp pointer to symbol structure
513 * sym ** p pointer to an array of
514 * pointers to symbol structures
515 * area * ap pointer to an area structure
518 * area * areap pointer to an area structure
519 * char aretbl[] string "Area Table"
520 * sym dot defined as sym[0]
521 * char stb[] Subtitle string buffer
522 * sym * symhash[] array of pointers to NHASH
523 * linked symbol lists
524 * char symtbl[] string "Symbol Table"
525 * FILE * tfp symbol table output file handle
526 * int xflag -x, listing radix flag
529 * int fprintf() c_library
530 * int putc() c_library
531 * VOID slew() aslist.c
532 * int strcmp() c_library
533 * char * strcpy() c_library
536 * Symbol and area tables output.
543 register int c, i, j, k;
551 * Symbol Table Header
553 strcpy(stb, &symtbl[0]);
560 * Find number of symbols
563 for (i=0; i<NHASH; i++) {
575 * Allocate space for an array of pointers to symbols
578 if ((p = (struct sym **) malloc(sizeof((struct sym *) sp)*nmsym))
580 fprintf(fp, "Insufficient space to build Symbol Table.\n");
584 for (i=0; i<NHASH; i++) {
594 /* BUBBLE SORT?? WTF??? */
596 * Bubble Sort on Symbol Table Array
602 for (i=0; i<c; ++i) {
603 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
613 qsort(p, nmsym, sizeof(struct sym *), _cmpSym);
617 * Symbol Table Output
619 for (i=0; i<nmsym;) {
622 j = sp->s_area->a_ref;
624 fprintf(fp, " %2X ", j);
627 fprintf(fp, "%3o ", j);
630 fprintf(fp, "%3u ", j);
636 fprintf(fp, "%-60s", ptr ); /* JLH */
638 if (sp->s_flag & S_ASG) {
643 if (sp->s_type == S_NEW) {
645 fprintf(fp, " **** ");
648 fprintf(fp, "****** ");
651 fprintf(fp, " ***** ");
656 fprintf(fp, " %04X ", j);
659 fprintf(fp, "%06o ", j);
662 fprintf(fp, " %05u ", j);
666 if (sp->s_flag & S_GBL) {
670 if (sp->s_area != NULL) {
674 if (sp->s_type == S_NEW) {
701 strcpy(stb, &aretbl[0]);
714 for (i=0; i<narea; ++i) {
716 for (j=i+1; j<narea; ++j)
720 fprintf(fp, " %2X ", j);
723 fprintf(fp, " %3o ", j);
726 fprintf(fp, " %3u ", j);
729 while (ptr < &ap->a_id[NCPS]) {
730 if ((c = *ptr++) != 0) {
739 fprintf(fp, " size %4X flags %X\n", j, k);
742 fprintf(fp, " size %6o flags %o\n", j, k);
745 fprintf(fp, " size %5u flags %u\n", j, k);