1 /*******************************************************
3 * a56 - a DSP56001 assembler
5 * Written by Quinn C. Jensen
8 *******************************************************\
11 * Copyright (C) 2008 Robert Millan <rmh@aybabtu.com>
13 * This file is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published
15 * by the Free Software Foundation, either version 3 of the License,
16 * or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see
25 * <http://www.gnu.org/licenses/>.
27 * This file incorporates work covered by the following copyright and
30 * Copyright (C) 1990-1994 Quinn C. Jensen
32 * Permission to use, copy, modify, distribute, and sell this software
33 * and its documentation for any purpose is hereby granted without fee,
34 * provided that the above copyright notice appear in all copies and
35 * that both that copyright notice and this permission notice appear
36 * in supporting documentation. The author makes no representations
37 * about the suitability of this software for any purpose. It is
38 * provided "as is" without express or implied warranty.
41 static char *Copyright = "Copyright (C) 1990-1994 Quinn C. Jensen";
44 * subs.c - Some subroutines for the assembler.
57 if(strcmp(file, "-") == 0)
59 else if ((fp = fopen(file, "r")) == NULL) {
66 FILE *open_write(file)
70 if ((fp = fopen(file, "w")) == NULL) {
77 FILE *open_append(file)
81 if ((fp = fopen(file, "a")) == NULL) {
88 fatal(c, a1, a2, a3, a4, a5, a6, a7, a8)
89 char *c, *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
91 fprintf(stderr, c, a1, a2, a3, a4, a5, a6, a7, a8);
98 char tabbuf[MAX_BUF], *untabn();
99 char *untab(s) /* expand tabs in s */
102 return untabn(s, TABS);
105 char *untabn(s, stops) /* expand tabs in s */
111 /* copy input string into buffer to scan while input string is modified */
113 register char *b = tabbuf;
115 strncpy(b, s, MAX_BUF);
117 /* iterate until the copy of the input string is depleted */
123 while ((++s - o) % stops);
130 /* null terminate the resultant string */
140 char *p = (char *)malloc(size);
142 fatal("alloc: insufficient virtual memory to allocate %d bytes\n",
148 ((c) >= 'a' ? (c) - 'a' + 10 : ((c) >= 'A' ? (c) - 'A' + 10 : (c) - '0'))
150 #define valid(c) ((c) >= '0' && (c) <= '9' || \
151 (c) >= 'A' && (c) <= 'Z' || \
152 (c) >= 'a' && (c) <= 'z')
155 register char *s, **p;
158 register long result = 0;
159 register int sign = 0;
161 while(*s == ' ' || *s == '\t')
170 register int dig = ascii2n(*s);
181 return sign ? -result : result;