annotate src/insn_logicmem.c @ 34:b29eec6f3819

Finished adding addressing mode handlers
author lost
date Fri, 02 Jan 2009 05:17:00 +0000
parents
children 538e15927776
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
1 /*
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
2 insn_logicmem.c
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
4
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
5 This file is part of LWASM.
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
6
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
10 version.
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
11
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
15 more details.
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
16
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
19
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
20 Contains code for handling logic/mem instructions
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
21 */
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
22
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
23 #include <ctype.h>
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
24 #include <stdio.h>
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
25 #include <string.h>
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
26
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
27 #include "lwasm.h"
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
28 #include "instab.h"
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
29 #include "expr.h"
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
30
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
31 extern void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum, int extra);
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
32
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
33 // for aim, oim, eim, tim
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
34 OPFUNC(insn_logicmem)
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
35 {
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
36 int rval, v1;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
37 const char *p2;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
38 lwasm_expr_stack_t *s;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
39
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
40 if (**p == '#')
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
41 (*p)++;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
42
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
43 s = lwasm_expr_eval(*p, &p2);
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
44 *p = (char *)p2;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
45
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
46 if (!s)
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
47 {
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
48 register_error(as, l, 1, "Bad expression");
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
49 return;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
50 }
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
51
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
52 if (v1 < -128 || v1 > 255)
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
53 {
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
54 register_error(as, l, 2, "Byte overflow");
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
55 v1 &= 0xff;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
56 }
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
57
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
58 if (**p != ',' && **p != ';')
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
59 {
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
60 register_error(as, l, 1, "Bad operand");
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
61 return;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
62 }
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
63
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
64 (*p)++;
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
65
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
66 // now we have a general addressing mode - call for it
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
67 insn_gen_aux(as, l, p, opnum, v1 & 0xff);
b29eec6f3819 Finished adding addressing mode handlers
lost
parents:
diff changeset
68 }