Mercurial > hg-old > index.cgi
annotate lwasm/insn_logicmem.c @ 439:b8549694b4c9 3.0
Fixed errors related to lw_expr_t; fixed saving expression in insn_parse_logicmem()
author | lost@l-w.ca |
---|---|
date | Sat, 30 Oct 2010 10:41:52 -0600 |
parents | eacdae8a1575 |
children |
rev | line source |
---|---|
339 | 1 /* |
2 insn_logicmem.c | |
3 Copyright © 2009 William Astle | |
4 | |
5 This file is part of LWASM. | |
6 | |
7 LWASM is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 Contains code for handling logic/mem instructions | |
21 */ | |
22 | |
23 #include <config.h> | |
24 #include <ctype.h> | |
25 #include <stdio.h> | |
26 #include <string.h> | |
27 | |
362 | 28 #include <lw_expr.h> |
29 | |
339 | 30 #include "lwasm.h" |
31 #include "instab.h" | |
32 | |
362 | 33 extern void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **optr); |
382 | 34 extern void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force, int elen); |
362 | 35 extern void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra); |
339 | 36 |
37 // for aim, oim, eim, tim | |
362 | 38 PARSEFUNC(insn_parse_logicmem) |
339 | 39 { |
40 const char *p2; | |
439
b8549694b4c9
Fixed errors related to lw_expr_t; fixed saving expression in insn_parse_logicmem()
lost@l-w.ca
parents:
382
diff
changeset
|
41 lw_expr_t s; |
339 | 42 |
43 if (**p == '#') | |
44 (*p)++; | |
45 | |
362 | 46 s = lwasm_parse_expr(as, p); |
47 if (!s) | |
48 { | |
49 lwasm_register_error(as, l, "Bad operand"); | |
50 return; | |
51 } | |
339 | 52 |
439
b8549694b4c9
Fixed errors related to lw_expr_t; fixed saving expression in insn_parse_logicmem()
lost@l-w.ca
parents:
382
diff
changeset
|
53 lwasm_save_expr(l, 100, s); |
339 | 54 if (**p != ',' && **p != ';') |
55 { | |
362 | 56 lwasm_register_error(as, l, "Bad operand"); |
339 | 57 return; |
58 } | |
59 | |
60 (*p)++; | |
61 | |
62 // now we have a general addressing mode - call for it | |
362 | 63 insn_parse_gen_aux(as, l, p); |
64 } | |
65 | |
66 RESOLVEFUNC(insn_resolve_logicmem) | |
67 { | |
68 if (l -> len != -1) | |
69 return; | |
70 | |
382 | 71 insn_resolve_gen_aux(as, l, force, 1); |
339 | 72 } |
362 | 73 |
74 EMITFUNC(insn_emit_logicmem) | |
75 { | |
76 lw_expr_t e; | |
77 int v; | |
78 | |
79 e = lwasm_fetch_expr(l, 100); | |
80 if (!lw_expr_istype(e, lw_expr_type_int)) | |
81 { | |
82 lwasm_register_error(as, l, "Immediate byte must be fully resolved"); | |
83 return; | |
84 } | |
85 | |
86 v = lw_expr_intval(e); | |
87 if (v < -128 || v > 255) | |
88 { | |
89 lwasm_register_error(as, l, "Byte overflow"); | |
90 return; | |
91 } | |
92 | |
93 insn_emit_gen_aux(as, l, v); | |
94 } |