Disable test for -mmcs51 --stack-auto, due to bug #3804.
[sdcc.git] / sdcc / sdas / as6808 / m08adr.c
blobfc61c107da10e2404139beaa91959a32700a4b4e
1 /* m08adr.c */
3 /*
4 * Copyright (C) 1989-2021 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
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/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
25 #include "asxxxx.h"
26 #include "m6808.h"
28 int
29 addr(esp)
30 struct expr *esp;
32 int c;
33 char *tcp;
34 char *p;
36 /* fix order of '<', '>', and '#' */
37 p = ip;
38 if (((c = getnb()) == '<') || (c == '>')) {
39 p = ip-1;
40 if (getnb() == '#') {
41 *p = *(ip-1);
42 *(ip-1) = c;
45 ip = p;
47 if ((c = getnb()) == '#') {
48 expr(esp, 0);
49 esp->e_mode = S_IMMED;
50 } else if (c == ',') {
51 switch(admode(axs)) {
52 default:
53 xerr('a', "Register S, X, or X+ Required, Not A.");
55 case S_X:
56 c = S_IX;
57 break;
59 case S_S:
60 c = S_IS;
61 break;
63 case S_XP:
64 c = S_IXP;
65 break;
67 esp->e_mode = c;
68 } else if (c == '*') {
69 expr(esp, 0);
70 esp->e_mode = S_DIR;
71 if (more()) {
72 comma(1);
73 tcp = ip;
74 switch(admode(axs)) {
75 case S_X:
76 esp->e_mode = S_IX1;
77 break;
79 case S_S:
80 esp->e_mode = S_SP1;
81 break;
83 case S_XP:
84 esp->e_mode = S_IX1P;
85 break;
87 default:
88 ip = --tcp;
89 break;
92 } else {
93 unget(c);
94 if ((esp->e_mode = admode(axs)) != 0) {
96 } else {
97 expr(esp, 0);
98 if ((!esp->e_flag)
99 && (esp->e_base.e_ap == NULL)
100 && !(esp->e_addr & ~0xFF)) {
101 esp->e_mode = S_DIR;
103 if ((!esp->e_flag)
104 && (zpg != NULL)
105 && (esp->e_base.e_ap == zpg)) {
106 esp->e_mode = S_DIR;
108 if ((esp->e_mode == S_DIR) && more()) {
109 comma(1);
110 tcp = ip;
111 switch(admode(axs)) {
112 case S_X:
113 esp->e_mode = S_IX1;
114 break;
116 case S_S:
117 esp->e_mode = S_SP1;
118 break;
120 case S_XP:
121 esp->e_mode = S_IX1P;
122 break;
124 default:
125 ip = --tcp;
126 break;
128 } else
129 if ((esp->e_mode != S_DIR) && more()) {
130 comma(1);
131 switch(admode(axs)) {
132 default:
133 xerr('a', "Register S, X, or X+ Required, Not A.");
135 case S_X:
136 esp->e_mode = S_IX2;
137 break;
139 case S_S:
140 esp->e_mode = S_SP2;
141 break;
143 case S_XP:
144 esp->e_mode = S_IX2P;
145 break;
147 } else
148 if (esp->e_mode != S_DIR) {
149 esp->e_mode = S_EXT;
153 return (esp->e_mode);
157 * When building a table that has variations of a common
158 * symbol always start with the most complex symbol first.
159 * for example if x, x+, and x++ are in the same table
160 * the order should be x++, x+, and then x. The search
161 * order is then most to least complex.
165 * When searching symbol tables that contain characters
166 * not of type LTR16, eg with '-' or '+', always search
167 * the more complex symbol tables first. For example:
168 * searching for x+ will match the first part of x++,
169 * a false match if the table with x+ is searched
170 * before the table with x++.
174 * Enter admode() to search a specific addressing mode table
175 * for a match. Return the addressing value on a match or
176 * zero for no match.
179 admode(sp)
180 struct adsym *sp;
182 char *ptr;
183 int i;
184 char *ips;
186 ips = ip;
187 unget(getnb());
189 i = 0;
190 while ( *(ptr = &sp[i].a_str[0]) ) {
191 if (srch(ptr)) {
192 return(sp[i].a_val);
194 i++;
196 ip = ips;
197 return(0);
201 * srch --- does string match ?
204 srch(str)
205 char *str;
207 char *ptr;
208 ptr = ip;
210 while (*ptr && *str) {
211 if(ccase[*ptr & 0x007F] != ccase[*str & 0x007F])
212 break;
213 ptr++;
214 str++;
216 if (ccase[*ptr & 0x007F] == ccase[*str & 0x007F]) {
217 ip = ptr;
218 return(1);
221 if (!*str)
222 if (!(ctype[*ptr & 0x007F] & LTR16)) {
223 ip = ptr;
224 return(1);
226 return(0);
229 struct adsym axs[] = { /* a, x, or s registers */
230 { "x+", S_XP },
231 { "a", S_A },
232 { "x", S_X },
233 { "s", S_S },
234 { "", 0x00 }