annotate lwasm/insn_gen.c @ 208:06effa2faea1

Added some info on building gcc6809 to use lwtools
author lost
date Tue, 21 Apr 2009 02:57:37 +0000
parents 048ebb85f6ef
children bae1e3ecdce1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
21
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
31 // "extra" is required due to the way OIM, EIM, TIM, and AIM work
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
32 void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum, int extra)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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;
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 62
diff changeset
41 int isdp = 0;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
42
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43 optr2 = *optr;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
44 while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
45 /* do nothing */ ;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
46
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 if (*optr2 != ',' && **optr != '[')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 // not indexed
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
50 if (l -> fsize == 1)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
51 f8 = 1;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
52 else if (l -> fsize == 2)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
53 f16 = 1;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
54
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
55 if (**optr == '<')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57 (*optr)++;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
58 f8 = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
59 }
163
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
60 // for compatibility with asxxxx
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
61 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8"
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
62 else if (**optr == '*')
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
63 {
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
64 tv = *(*optr + 1);
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
65 if (isdigit(tv) || isalpha(tv) || tv == '_' || tv == '.' || tv == '?' || tv == '@' || tv == '*' || tv == '+' || tv == '-')
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
66 {
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
67 f8 = 1;
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
68 (*optr)++;
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
69 }
2e6a1e914104 Added ability to use * as a direct page indicator
lost
parents: 151
diff changeset
70 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71 else if (**optr == '>')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
72 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
73 (*optr)++;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
74 f16 = 1;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
75 }
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
76 rval = lwasm_expr_result2(as, l, optr, 0, &v1, 0);
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
77 if (rval != 0)
33
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 f16 = 1;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
80 v1 = 0;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
81 l -> fsize = 2;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
82 }
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 62
diff changeset
83
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 62
diff changeset
84 if (((v1 >> 8) & 0xff) == (as -> dpval & 0xff))
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 62
diff changeset
85 isdp = 1;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
86
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
87 // disallow non-explicit DP in obj target
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
88 if (as -> outformat == OUTPUT_OBJ && !f8)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
89 f16 = 1;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
90
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 62
diff changeset
91 if (f8 || (!f16 && isdp))
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
92 {
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
93 v1 = v1 & 0xffff;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
94 tv = v1 - ((as -> dpval) << 8);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
95 if (tv < 0 || tv > 0xff)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
96 {
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
97 register_error(as, l, 2, "Byte overflow");
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
98 }
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
99 v1 = v1 & 0xff;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
100 lwasm_emitop(as, l, instab[opnum].ops[0]);
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
101 if (extra != -1)
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
102 lwasm_emit(as, l, extra);
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
103 lwasm_emit(as, l, v1 & 0xff);
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 163
diff changeset
104 l -> relocoff = as -> addr - l -> codeaddr;
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 163
diff changeset
105 l -> reloc8bit = 1;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
106 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
107 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
108 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
109 {
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
110 // everything else is 16 bit....
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
111 lwasm_emitop(as, l, instab[opnum].ops[2]);
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
112 if (extra != -1)
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
113 lwasm_emit(as, l, extra);
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
114 l -> relocoff = as -> addr - l -> codeaddr;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
115 lwasm_emit(as, l, v1 >> 8);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
116 lwasm_emit(as, l, v1 & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
117 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
118 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
119 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
120
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
121 lwasm_emitop(as, l, instab[opnum].ops[1]);
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
122 if (extra != -1)
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
123 lwasm_emit(as, l, extra);
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
124 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
125 if (b1 != -1)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
126 lwasm_emit(as, l, b1);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
127 if (b2 != -1)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
128 lwasm_emit(as, l, b2);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
129 if (b3 != -1)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
130 lwasm_emit(as, l, b3);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
131 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
132 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
133
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
134 // 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
135 OPFUNC(insn_gen0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 {
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
137 if (**p == '#')
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
138 {
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
139 register_error(as, l, 1, "Immediate mode not allowed");
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
140 return;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
141 }
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
142
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
143 // handle non-immediate
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
144 insn_gen_aux(as, l, p, opnum, -1);
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
145 }
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
146
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
147 OPFUNC(insn_gen8)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
148 {
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
149 int rval;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
150 int r;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
151
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
152 if (**p == '#')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
153 {
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
154 lwasm_emitop(as, l, instab[opnum].ops[3]);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
155 (*p)++;
98
81fc353d4d69 Cleaned up old lwasm_expr_result() function and unused EXPR_* flags
lost
parents: 77
diff changeset
156 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
157 if (r != 0)
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
158 rval = 0;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
159 if (r == 1 && as -> passnum == 2)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
160 register_error(as, l, 2, "Illegal external or intersegment reference");
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
161 lwasm_emit(as, l, rval & 0xff);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
163 }
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
164
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
165 insn_gen_aux(as, l, p, opnum, -1);
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
166 }
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 OPFUNC(insn_gen16)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
169 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
170 int rval, r;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
171
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
172 if (**p == '#')
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
173 {
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
174 lwasm_emitop(as, l, instab[opnum].ops[3]);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
175 (*p)++;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
176
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
177 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
178 if (r != 0)
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
179 rval = 0;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
180 if (r == 1 && as -> passnum == 2)
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
181 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
182 l -> relocoff = as -> addr - l -> codeaddr;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
183 }
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
184 lwasm_emit(as, l, (rval >> 8) & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
185 lwasm_emit(as, l, rval & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
186 return;
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
187 }
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
188
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
189 insn_gen_aux(as, l, p, opnum, -1);
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
190 }
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 OPFUNC(insn_gen32)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
193 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
194 int r, rval;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
195
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
196 if (**p == '#')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
197 {
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
198 lwasm_emitop(as, l, instab[opnum].ops[3]);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
199 (*p)++;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
200
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
201 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
202 if (r != 0)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
203 rval = 0;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
204 if (r == 1 && as -> passnum == 2)
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
205 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
206 register_error(as, l, 2, "Illegal external or intersegment reference");
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
207 }
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
208
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
209 lwasm_emit(as, l, (rval >> 24) & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
210 lwasm_emit(as, l, (rval >> 16) & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
211 lwasm_emit(as, l, (rval >> 8) & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
212 lwasm_emit(as, l, rval & 0xff);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
213 return;
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
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents: 33
diff changeset
216 insn_gen_aux(as, l, p, opnum, -1);
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
217 }
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
218
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
219 OPFUNC(insn_imm8)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
220 {
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
221 int r, rval;
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
222
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
223 if (**p == '#')
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 lwasm_emitop(as, l, instab[opnum].ops[0]);
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
226 (*p)++;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
227
98
81fc353d4d69 Cleaned up old lwasm_expr_result() function and unused EXPR_* flags
lost
parents: 77
diff changeset
228 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
229 if (r != 0)
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
230 rval = 0;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
231 if (r == 1 && as -> passnum == 2)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
232 register_error(as, l, 2, "Illegal external or intersegment reference");
a338d496350e Checkpointing conversion to allow object target
lost
parents: 65
diff changeset
233
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
234 if (rval < -128 || rval > 255)
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
235 register_error(as, l, 2, "Byte overflow");
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
236 lwasm_emit(as, l, rval & 0xff);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
237 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
238 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
239
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 4
diff changeset
240 register_error(as, l, 1, "Bad operand");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
241 }