1 /*******************************************************
3 * a56 - a DSP56001 assembler
5 * Written by Quinn C. Jensen
8 *******************************************************\
11 * Copyright (C) 1990-1994 Quinn C. Jensen
13 * Permission to use, copy, modify, distribute, and sell this software
14 * and its documentation for any purpose is hereby granted without fee,
15 * provided that the above copyright notice appear in all copies and
16 * that both that copyright notice and this permission notice appear
17 * in supporting documentation. The author makes no representations
18 * about the suitability of this software for any purpose. It is
19 * provided "as is" without express or implied warranty.
22 static char *Copyright = "Copyright (C) 1990-1994 Quinn C. Jensen";
25 * subs.c - Some subroutines for the assembler.
40 if(strcmp(file, "-") == 0)
42 else if ((fp = fopen(file, "r")) == NULL) {
49 FILE *open_write(file)
53 if ((fp = fopen(file, "w")) == NULL) {
60 FILE *open_append(file)
64 if ((fp = fopen(file, "a")) == NULL) {
71 fatal(c, a1, a2, a3, a4, a5, a6, a7, a8)
72 char *c, *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
74 fprintf(stderr, c, a1, a2, a3, a4, a5, a6, a7, a8);
81 char tabbuf[MAX_BUF], *untabn();
82 char *untab(s) /* expand tabs in s */
85 return untabn(s, TABS);
88 char *untabn(s, stops) /* expand tabs in s */
94 /* copy input string into buffer to scan while input string is modified */
96 register char *b = tabbuf;
98 strncpy(b, s, MAX_BUF);
100 /* iterate until the copy of the input string is depleted */
106 while ((++s - o) % stops);
113 /* null terminate the resultant string */
123 char *p = (char *)malloc(size);
125 fatal("alloc: insufficient virtual memory to allocate %d bytes\n",
131 ((c) >= 'a' ? (c) - 'a' + 10 : ((c) >= 'A' ? (c) - 'A' + 10 : (c) - '0'))
133 #define valid(c) ((c) >= '0' && (c) <= '9' || \
134 (c) >= 'A' && (c) <= 'Z' || \
135 (c) >= 'a' && (c) <= 'z')
138 register char *s, **p;
141 register long result = 0;
142 register int sign = 0;
144 while(*s == ' ' || *s == '\t')
153 register int dig = ascii2n(*s);
164 return sign ? -result : result;