Mercurial > hg-old > index.cgi
comparison lwasm/insn_logicmem.c @ 362:4867f18c872f
Added logic memory operands
author | lost@starbug |
---|---|
date | Thu, 01 Apr 2010 20:56:19 -0600 |
parents | old-trunk/lwasm/old/insn_logicmem.c@eb230fa7d28e |
children | eacdae8a1575 |
comparison
equal
deleted
inserted
replaced
361:105393e31f20 | 362:4867f18c872f |
---|---|
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 | |
28 #include <lw_expr.h> | |
29 | |
30 #include "lwasm.h" | |
31 #include "instab.h" | |
32 | |
33 extern void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **optr); | |
34 extern void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force); | |
35 extern void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra); | |
36 | |
37 // for aim, oim, eim, tim | |
38 PARSEFUNC(insn_parse_logicmem) | |
39 { | |
40 const char *p2; | |
41 lw_expr_t *s; | |
42 | |
43 if (**p == '#') | |
44 (*p)++; | |
45 | |
46 s = lwasm_parse_expr(as, p); | |
47 if (!s) | |
48 { | |
49 lwasm_register_error(as, l, "Bad operand"); | |
50 return; | |
51 } | |
52 | |
53 lwasm_save_expr(l, 100, p); | |
54 if (**p != ',' && **p != ';') | |
55 { | |
56 lwasm_register_error(as, l, "Bad operand"); | |
57 return; | |
58 } | |
59 | |
60 (*p)++; | |
61 | |
62 // now we have a general addressing mode - call for it | |
63 insn_parse_gen_aux(as, l, p); | |
64 } | |
65 | |
66 RESOLVEFUNC(insn_resolve_logicmem) | |
67 { | |
68 if (l -> len != -1) | |
69 return; | |
70 | |
71 insn_resolve_gen_aux(as, l, force); | |
72 } | |
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 } |