annotate src/index.c @ 8:f1df096aa76f 1.1

Tagged 1.1 bugfix release
author lost
date Sun, 04 Jan 2009 05:46:07 +0000
parents 34568fab6058
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
2 index.c, Copyright © 2008 William Astle
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
3
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19 Contains code for parsing indexed addressing modes
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
20
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
21 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
22
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23 #include <ctype.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 //#include <errno.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25 //#include <stdio.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 //#include <stdlib.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include <string.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
28 #define __index_c_seen__
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29 //#include "instab.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
31 #include "instab.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
33
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 int parse_index_expr(asmstate_t *as, sourceline_t *cl, char **optr, int *postbyte, int *opmode, int *v1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
35 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
36 static const char *regs = "X Y U S W PCRPC ";
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
37 static const struct { char *opstr; int pb; } simpleindex[] =
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
38 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
39 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
40 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
41 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
42 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
44 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
45 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
46 {"e,x", 0x87}, {"e,y", 0xa7}, {"e,u", 0xc7}, {"e,s", 0xe7},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 {"f,x", 0x8a}, {"f,y", 0xaa}, {"f,u", 0xca}, {"f,s", 0xea},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 {"w,x", 0x8e}, {"w,y", 0xae}, {"w,u", 0xce}, {"w,s", 0xee},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
50 {",w", 0x8f}, {",w++", 0xcf}, {",--w", 0xef},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
52 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
53 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
54 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
55 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57 {"[e,x]", 0x97}, {"[e,y]", 0xb7}, {"[e,u]", 0xd7}, {"[e,s]", 0xf7},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
58 {"[f,x]", 0x9a}, {"[f,y]", 0xba}, {"[f,u]", 0xda}, {"[f,s]", 0xfa},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
59 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
60 {"[w,x]", 0x9e}, {"[w,y]", 0xbe}, {"[w,u]", 0xde}, {"[w,s]", 0xfe},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
61 {"[,w]", 0x90}, {"[,w++]", 0xd0}, {"[,--w]", 0xf0},
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
62
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
63 { "", -1 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
64 };
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65 char stbuf[25];
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
66 int i;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
67 int f8 = 0, f16 = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
68 int rn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
69 int indir = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71 int f0 = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
72
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
73 for (i = 0; i < 24; i++)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
74 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 if (*((*optr) + i) && !isspace(*((*optr) + i)))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
76 stbuf[i] = *((*optr) + i);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
77 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
78 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
79 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
80 stbuf[i] = '\0';
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
81 if (!*((*optr) + i) || isspace(*((*optr) + i)))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
83 int j;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
84 // do simple lookup
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
85 for (j = 0; simpleindex[j].opstr[0]; j++)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
86 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
87 if (!strcasecmp(stbuf, simpleindex[j].opstr))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
88 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
89 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
90 if (simpleindex[j].opstr[0])
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
91 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
92 *postbyte = simpleindex[j].pb;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
93 *opmode = OPER_INDEX;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
94 (*optr) += i;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
95 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
96 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
97 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
98
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
99 // now we have the hard ones to work out here
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
100
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
101 if (**optr == '[')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
102 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
103 indir = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
104 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
105 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
106
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
107 rn = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
108 for (i = 0; (*optr)[i] && !isspace((*optr)[i]); i++)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
109 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
110 if ((*optr)[i] == ',')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
111 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
112 rn = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
113 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
114 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
115 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
116
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
117 if (!rn && indir)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
118 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
119 // extended indir
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
120 *postbyte = 0x9f;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
121 *opmode = OPER_EXTIND;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
122 rval = eval_expr(as, cl, optr, v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
123 if (**optr != ']')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
124 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
125 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
126 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
127 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
128 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
129 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
130
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
131 if (cl -> p1f16)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
132 f16 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
133 if (**optr == '<')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
134 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
135 f8 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
137 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
138 else if (**optr == '>')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
139 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
140 f16 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
141 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
142 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
143
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
144 if (**optr == '0' && *(*optr+1) == ',')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
145 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
146 f0 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
147 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
148
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
149 // now we have to evaluate the expression
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
150 rval = eval_expr(as, cl, optr, v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
151
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
152 if (cl -> undef && as -> passnum == 1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
153 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
154 cl -> p1f16 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
155 f16 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
157
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
158 // now look for a comma; if not present, explode
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
159 if (rval == -1 || *(*optr)++ != ',')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
160 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
161 // syntax error; force 0 bit
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162 *postbyte = -1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
163 *opmode = OPER_INDEX;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
164 return -2;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
166
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
167 // now get the register
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
168 rn = lookupreg3(regs, optr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
169 if (rn < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
170 goto reterr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
171
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
172 // debug("Reg: %d\n", rn);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
173
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
174 if (indir && **optr != ']')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
175 goto reterr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
176 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
177 (*optr)++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
178
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
179 // nnnn,W is only 16 bit
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
180 if (rn == 4)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
181 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
182 if (f8)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
183 goto reterr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
184 if (!f16 && !f0 && !(as -> pragmas & PRAGMA_NOINDEX0TONONE) && *v1 == 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
185 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
186 *opmode = OPER_INDEX;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
187 if (indir)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
188 *postbyte = 0x90;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
189 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
190 *postbyte = 0x8f;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
191 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
192 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
193 *opmode = OPER_INDEX16;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
194 if (indir)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
195 *postbyte = 0xb0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
196 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
197 *postbyte = 0xcf;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
198 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
199 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
200
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
201 if (indir) indir = 0x10;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
202
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
203 // forward ref; we can't figure anything
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
204 if (cl -> undef)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
205 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
206 f16 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
207 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
208
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
209 // PCR? redo v1, v2 relative to current address
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
210 if (rn == 5)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
211 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
212 *v1 -= as -> addr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
213
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
214 // we have a slight problem here
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
215 // PCR based on current insn loc is really
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
216 // -125 <= offset <= +130 (8 bit offset)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
217 if (f8 || (!f16 && *v1 >= -125 && *v1 <= 130))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
218 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
219 *opmode = OPER_INDEX8;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
220 *postbyte = indir | 0x8C;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
221 *v1 -= 3;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
222 if (*v1 < -128 || *v1 > 127)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
223 errorp2(ERR_OVERFLOW);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
224 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
225 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
226
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
227 // anything else is 16 bit offset
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
228 // need 16 bit
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
229 *opmode = OPER_INDEX16;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
230 *postbyte = indir | 0x8D;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
231 *v1 -= 4;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
232 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
233 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
234
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
235 // constant offset from PC
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
236 if (rn == 6)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
237 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
238 if (f8 || (!f16 && *v1 >= -128 && *v1 <= 127))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
239 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
240 *opmode = OPER_INDEX8;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
241 *postbyte = indir | 0x8C;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
242 if (*v1 < -128 || *v1 > 127)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
243 errorp2(ERR_OVERFLOW);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
244 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
245 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
246
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
247 // everything else must be 16 bit
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
248 // need 16 bit
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
249 *opmode = OPER_INDEX16;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
250 *postbyte = indir | 0x8D;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
251 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
252
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
253 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
254
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
255 // we only have to deal with x,y,u,s here
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
256 if (!f8 && !f16 && *v1 >= -16 && *v1 <= 15)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
257 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
258 if (*v1 == 0 && !f0 && !(as -> pragmas & PRAGMA_NOINDEX0TONONE))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
259 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
260 *postbyte = rn << 5 | indir | 0x80 | 0x04;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
261 *opmode = OPER_INDEX;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
262 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
263 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
264 // we pick the smallest value here
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
265 if (indir)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
266 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
267 f8 = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
268 goto no5bit;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
269 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
270 *postbyte = rn << 5 | (*v1 & 0x1F);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
271 *opmode = OPER_INDEX5;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
272 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
273 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
274 no5bit:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
275 if (f16 || (!f8 && (*v1 < -128 || *v1 > 127)))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
276 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
277 // must be a 16 bit offset here
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
278 *postbyte = rn << 5 | indir | 0x80 | 0x09;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
279 *opmode = OPER_INDEX16;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
280 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
281 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
282
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
283 // if we're here, we have an 8 bit offset
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
284 *postbyte = rn << 5 | indir | 0x80 | 0x08;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
285 *opmode = OPER_INDEX8;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
286 if (*v1 < -128 || *v1 > 127)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
287 errorp2(ERR_OVERFLOW);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
288 return 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
289 reterr:
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
290 *postbyte = -1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
291 *opmode = OPER_INDEX;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
292 return -2;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
293 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
294
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
295 void insn_indexed_aux(asmstate_t *as, sourceline_t *cl, char **optr, int *b1, int *b2, int *b3)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
296 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
297 int rval;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
298 int v1, pb = -1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
299
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
300 *b1 = *b2 = *b3 = -1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
301
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
302 rval = parse_index_expr(as, cl, optr, &pb, &(cl -> addrmode), &v1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
303 if (rval < 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
304 errorp1(ERR_BADOPER);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
305 *b1 = pb;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
306
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
307 if (cl -> addrmode == OPER_INDEX8)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
308 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
309 *b2 = v1 & 0xff;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
310 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
311 else if (cl -> addrmode == OPER_INDEX16 || cl -> addrmode == OPER_EXTIND)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
312 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
313 *b2 = (v1 & 0xffff) >> 8;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
314 *b3 = v1 & 0xff;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
315 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
316 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
317
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
318 void insn_indexed(asmstate_t *as, sourceline_t *cl, char **optr)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
319 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
320 int b1, b2, b3;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
321
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
322 emitop(instab[cl -> opcode].ops[0]);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
323 insn_indexed_aux(as, cl, optr, &b1, &b2, &b3);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
324 if (b1 != -1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
325 emit(b1);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
326 if (b2 != -1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
327 emit(b2);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
328 if (b3 != -1)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
329 emit(b3);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
330 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
331