annotate src/insn_bitbit.c @ 76:2fe5fd7d65a3

Checkpointing object target implementation
author lost
date Thu, 08 Jan 2009 02:57:24 +0000
parents 538e15927776
children 8929e1ee99cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
1 /*
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
2 insn_bitbit.c
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 32
diff changeset
3 Copyright © 2009 William Astle
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
4
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
5 This file is part of LWASM.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
6
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
10 version.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
11
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
15 more details.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
16
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
19 */
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
20
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
21 /*
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
22 for handling inherent mode instructions
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
23 */
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
24
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
25 #define __insn_bitbit_c_seen__
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
26
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
27 #include <stdlib.h>
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
28
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
29 #include "lwasm.h"
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
30 #include "instab.h"
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
31 #include "expr.h"
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
33 OPFUNC(insn_bitbit)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
34 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
35 int r;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
36 lwasm_expr_stack_t *s;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
37 int v1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
38 int tv;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
39
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
40 lwasm_emitop(as, l, instab[opnum].ops[0]);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
41
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
42 r = toupper(*(*p)++);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
43 if (r == 'A')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
44 r = 1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
45 else if (r == 'B')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
46 r = 2;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
47 else if (r == 'C' && toupper(**p) == 'C')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
48 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
49 r = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
50 (*p)++;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
51 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
52 else
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
53 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
54 register_error(as, l, 1, "Bad register");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
55 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
56 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
57 if (*(*p)++ != ',')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
58 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
59 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
60 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
61 }
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 33
diff changeset
62 s = lwasm_evaluate_expr(as, l, *p, NULL);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
63 if (!s)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
64 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
65 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
66 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
67 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
68 if (!lwasm_expr_is_constant(s))
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
69 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
70 register_error(as, l, 2, "Incomplete reference");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
71 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
72 v1 = lwasm_expr_get_value(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
73 lwasm_expr_stack_free(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
74 if (v1 < 0 || v1 > 7)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
75 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
76 register_error(as, l, 2, "Invalid bit number");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
77 v1 = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
78 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
79 if (*(*p)++ != ',')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
80 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
81 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
82 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
83 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
84 r = (r << 6) | (v1 << 3);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
85
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 33
diff changeset
86 s = lwasm_evaluate_expr(as, l, *p, NULL);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
87 if (!s)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
88 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
89 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
90 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
91 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
92 if (!lwasm_expr_is_constant(s))
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
93 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
94 register_error(as, l, 1, "Incomplete reference");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
95 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
96 v1 = lwasm_expr_get_value(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
97 lwasm_expr_stack_free(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
98 if (v1 < 0 || v1 > 7)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
99 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
100 register_error(as, l, 2, "Invalid bit number");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
101 v1 = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
102 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
103 if (*(*p)++ != ',')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
104 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
105 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
106 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
107 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
108 r |= v1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
109
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
110 lwasm_emit(as, l, r);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
111
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
112 // ignore base page address modifier
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
113 if (**p == '<')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
114 (*p)++;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
115
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 33
diff changeset
116 s = lwasm_evaluate_expr(as, l, *p, NULL);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
117 if (!s)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
118 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
119 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
120 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
121 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
122 if (!lwasm_expr_is_constant(s))
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
123 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
124 register_error(as, l, 1, "Incomplete reference");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
125 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
126 v1 = lwasm_expr_get_value(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
127 lwasm_expr_stack_free(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
128 v1 &= 0xFFFF;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
129
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
130 tv = v1 - ((as -> dpval) << 8);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
131 if (tv > 0xFF || tv < 0)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
132 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
133 register_error(as, l, 2, "Byte overflow");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
134 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
135 lwasm_emit(as, l, tv & 0xff);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
136 }