comparison lwasm/insn_logicmem.c @ 0:2c24602be78f

Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author lost@l-w.ca
date Wed, 19 Jan 2011 22:27:17 -0700
parents
children 7317fbe024af
comparison
equal deleted inserted replaced
-1:000000000000 0:2c24602be78f
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 <ctype.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 #include <lw_expr.h>
28
29 #include "lwasm.h"
30 #include "instab.h"
31
32 extern void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **optr);
33 extern void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force, int elen);
34 extern void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra);
35
36 // for aim, oim, eim, tim
37 PARSEFUNC(insn_parse_logicmem)
38 {
39 const char *p2;
40 lw_expr_t s;
41
42 if (**p == '#')
43 (*p)++;
44
45 s = lwasm_parse_expr(as, p);
46 if (!s)
47 {
48 lwasm_register_error(as, l, "Bad operand");
49 return;
50 }
51
52 lwasm_save_expr(l, 100, s);
53 if (**p != ',' && **p != ';')
54 {
55 lwasm_register_error(as, l, "Bad operand");
56 return;
57 }
58
59 (*p)++;
60
61 // now we have a general addressing mode - call for it
62 insn_parse_gen_aux(as, l, p);
63 }
64
65 RESOLVEFUNC(insn_resolve_logicmem)
66 {
67 if (l -> len != -1)
68 return;
69
70 insn_resolve_gen_aux(as, l, force, 1);
71 }
72
73 EMITFUNC(insn_emit_logicmem)
74 {
75 lw_expr_t e;
76 int v;
77
78 e = lwasm_fetch_expr(l, 100);
79 if (!lw_expr_istype(e, lw_expr_type_int))
80 {
81 lwasm_register_error(as, l, "Immediate byte must be fully resolved");
82 return;
83 }
84
85 v = lw_expr_intval(e);
86 if (v < -128 || v > 255)
87 {
88 lwasm_register_error(as, l, "Byte overflow");
89 return;
90 }
91
92 insn_emit_gen_aux(as, l, v);
93 }