Mercurial > hg-old > index.cgi
annotate src/insn_gen.c @ 59:89657cb3fdf8
Moved insn_rel.c to simplified expression evaluation
author | lost |
---|---|
date | Mon, 05 Jan 2009 00:40:58 +0000 |
parents | 538e15927776 |
children | da1337724ecd |
rev | line source |
---|---|
0 | 1 /* |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
2 insn_gen.c, Copyright © 2009 William Astle |
4
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 general addressing modes (IMM+DIR+EXT+IND) |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
20 */ |
0 | 21 |
22 #include <ctype.h> | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
23 #include <stdlib.h> |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
24 |
0 | 25 #include "lwasm.h" |
26 #include "instab.h" | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
27 #include "expr.h" |
0 | 28 |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
29 extern void insn_indexed_aux(asmstate_t *as, lwasm_line_t *l, const char **p, int *b1, int *b2, int *b3); |
0 | 30 |
34 | 31 // "extra" is required due to the way OIM, EIM, TIM, and AIM work |
32 void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum, int extra) | |
0 | 33 { |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
34 int b1 = -1, b2 = -1, b3 = -1; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
35 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
36 const char *optr2; |
0 | 37 int v1, tv, rval; |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
38 lwasm_expr_stack_t *s; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
39 int f8 = 0; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
40 int f16 = 0; |
0 | 41 |
42 optr2 = *optr; | |
43 while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++ | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
44 /* do nothing */ ; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
45 |
0 | 46 if (*optr2 != ',' && **optr != '[') |
47 { | |
48 // not indexed | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
49 if (l -> fsize == 1) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
50 f8 = 1; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
51 else if (l -> fsize == 2) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
52 f16 = 1; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
53 |
0 | 54 if (**optr == '<') |
55 { | |
56 (*optr)++; | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
57 f8 = 1; |
0 | 58 } |
59 else if (**optr == '>') | |
60 { | |
61 (*optr)++; | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
62 f16 = 1; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
63 } |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
34
diff
changeset
|
64 s = lwasm_evaluate_expr(as, l, *optr, NULL); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
65 if (!s) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
66 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
67 register_error(as, l, 1, "Bad expression"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
68 return; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
69 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
70 if (!lwasm_expr_is_constant(s)) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
71 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
72 f16 = 1; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
73 l -> fsize = 2; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
74 register_error(as, l, 2, "Incomplete reference"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
75 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
76 v1 = lwasm_expr_get_value(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
77 lwasm_expr_stack_free(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
78 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
79 if (f8 || (!f16 && v1 >= -128 && v1 <= 255)) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
80 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
81 v1 = v1 & 0xffff; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
82 tv = v1 - ((as -> dpval) << 8); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
83 if (tv < 0 || tv > 0xff) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
84 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
85 register_error(as, l, 2, "Byte overflow"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
86 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
87 v1 = v1 & 0xff; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
88 lwasm_emitop(as, l, instab[opnum].ops[0]); |
34 | 89 if (extra != -1) |
90 lwasm_emit(as, l, extra); | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
91 lwasm_emit(as, l, v1 & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
92 return; |
0 | 93 } |
94 else | |
95 { | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
96 // everything else is 16 bit.... |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
97 lwasm_emitop(as, l, instab[opnum].ops[2]); |
34 | 98 if (extra != -1) |
99 lwasm_emit(as, l, extra); | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
100 lwasm_emit(as, l, v1 >> 8); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
101 lwasm_emit(as, l, v1 & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
102 return; |
0 | 103 } |
104 } | |
105 | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
106 lwasm_emitop(as, l, instab[opnum].ops[1]); |
34 | 107 if (extra != -1) |
108 lwasm_emit(as, l, extra); | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
109 insn_indexed_aux(as, l, (const char **)optr, &b1, &b2, &b3); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
110 if (b1 != -1) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
111 lwasm_emit(as, l, b1); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
112 if (b2 != -1) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
113 lwasm_emit(as, l, b2); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
114 if (b3 != -1) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
115 lwasm_emit(as, l, b3); |
0 | 116 return; |
117 } | |
118 | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
119 // the various insn_gen? functions have an immediate mode of ? bits |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
120 OPFUNC(insn_gen0) |
0 | 121 { |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
122 if (**p == '#') |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
123 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
124 register_error(as, l, 1, "Immediate mode not allowed"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
125 return; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
126 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
127 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
128 // handle non-immediate |
34 | 129 insn_gen_aux(as, l, p, opnum, -1); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
130 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
131 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
132 OPFUNC(insn_gen8) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
133 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
134 lwasm_expr_stack_t *s; |
0 | 135 int rval; |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
136 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
137 if (**p == '#') |
0 | 138 { |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
139 lwasm_emitop(as, l, instab[opnum].ops[3]); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
140 (*p)++; |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
34
diff
changeset
|
141 s = lwasm_evaluate_expr(as, l, *p, NULL); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
142 if (!s) |
0 | 143 { |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
144 register_error(as, l, 1, "Bad expression"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
145 rval = 0; |
0 | 146 } |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
147 else |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
148 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
149 if (!lwasm_expr_is_constant(s)) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
150 register_error(as, l, 2, "Incomplete reference"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
151 rval = lwasm_expr_get_value(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
152 lwasm_expr_stack_free(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
153 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
154 if (rval < -128 || rval > 255) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
155 register_error(as, l, 2, "Byte overflow"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
156 lwasm_emit(as, l, rval & 0xff); |
0 | 157 return; |
158 } | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
159 |
34 | 160 insn_gen_aux(as, l, p, opnum, -1); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
161 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
162 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
163 OPFUNC(insn_gen16) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
164 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
165 lwasm_expr_stack_t *s; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
166 int rval; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
167 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
168 if (**p == '#') |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
169 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
170 lwasm_emitop(as, l, instab[opnum].ops[3]); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
171 (*p)++; |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
34
diff
changeset
|
172 s = lwasm_evaluate_expr(as, l, *p, NULL); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
173 if (!s) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
174 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
175 register_error(as, l, 1, "Bad expression"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
176 rval = 0; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
177 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
178 else |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
179 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
180 if (!lwasm_expr_is_constant(s)) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
181 register_error(as, l, 2, "Incomplete reference"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
182 rval = lwasm_expr_get_value(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
183 lwasm_expr_stack_free(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
184 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
185 lwasm_emit(as, l, (rval >> 8) & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
186 lwasm_emit(as, l, rval & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
187 return; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
188 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
189 |
34 | 190 insn_gen_aux(as, l, p, opnum, -1); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
191 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
192 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
193 OPFUNC(insn_gen32) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
194 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
195 lwasm_expr_stack_t *s; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
196 int rval; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
197 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
198 if (**p == '#') |
0 | 199 { |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
200 lwasm_emitop(as, l, instab[opnum].ops[3]); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
201 (*p)++; |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
34
diff
changeset
|
202 s = lwasm_evaluate_expr(as, l, *p, NULL); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
203 if (!s) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
204 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
205 register_error(as, l, 1, "Bad expression"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
206 rval = 0; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
207 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
208 else |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
209 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
210 if (!lwasm_expr_is_constant(s)) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
211 register_error(as, l, 2, "Incomplete reference"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
212 rval = lwasm_expr_get_value(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
213 lwasm_expr_stack_free(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
214 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
215 lwasm_emit(as, l, (rval >> 24) & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
216 lwasm_emit(as, l, (rval >> 16) & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
217 lwasm_emit(as, l, (rval >> 8) & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
218 lwasm_emit(as, l, rval & 0xff); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
219 return; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
220 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
221 |
34 | 222 insn_gen_aux(as, l, p, opnum, -1); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
223 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
224 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
225 OPFUNC(insn_imm8) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
226 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
227 lwasm_expr_stack_t *s; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
228 int rval; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
229 |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
230 if (**p == '#') |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
231 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
232 lwasm_emitop(as, l, instab[opnum].ops[0]); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
233 (*p)++; |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
34
diff
changeset
|
234 s = lwasm_evaluate_expr(as, l, *p, NULL); |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
235 if (!s) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
236 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
237 register_error(as, l, 1, "Bad expression"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
238 rval = 0; |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
239 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
240 else |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
241 { |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
242 if (!lwasm_expr_is_constant(s)) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
243 register_error(as, l, 2, "Incomplete reference"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
244 rval = lwasm_expr_get_value(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
245 lwasm_expr_stack_free(s); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
246 } |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
247 if (rval < -128 || rval > 255) |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
248 register_error(as, l, 2, "Byte overflow"); |
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
249 lwasm_emit(as, l, rval & 0xff); |
0 | 250 return; |
251 } | |
252 | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
4
diff
changeset
|
253 register_error(as, l, 1, "Bad operand"); |
0 | 254 } |