Mercurial > hg-old > index.cgi
annotate src/insn_rel.c @ 37:538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
author | lost |
---|---|
date | Sat, 03 Jan 2009 04:20:49 +0000 |
parents | 74a3fef7c8d0 |
children | 89657cb3fdf8 |
rev | line source |
---|---|
29 | 1 /* |
2 insn_rel.c | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
32
diff
changeset
|
3 Copyright © 2009 William Astle |
29 | 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 | |
21 /* | |
22 for handling relative mode instructions | |
23 */ | |
24 | |
32 | 25 #define __insn_rel_c_seen__ |
29 | 26 |
27 #include <stdlib.h> | |
28 | |
29 #include "expr.h" | |
30 #include "lwasm.h" | |
31 #include "instab.h" | |
32 | |
33 OPFUNC(insn_rel8) | |
34 { | |
35 lwasm_expr_stack_t *s; | |
36 int v; | |
37 | |
38 lwasm_emitop(as, l, instab[opnum].ops[0]); | |
39 | |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
33
diff
changeset
|
40 s = lwasm_evaluate_expr(as, l, *p, NULL); |
29 | 41 if (!s) |
42 { | |
43 register_error(as, l, 1, "Bad operand"); | |
44 lwasm_emitop(as, l, 0); | |
45 return; | |
46 } | |
47 if (lwasm_expr_is_constant(s)) | |
48 register_error(as, l, 2, "Incomplete reference"); | |
49 v = lwasm_expr_get_value(s); | |
50 v -= as -> addr + 1; | |
51 if (v < -128 || v > 127) | |
52 register_error(as, l, 2, "Byte overflow"); | |
53 lwasm_emit(as, l, v & 0xff); | |
54 | |
55 lwasm_expr_stack_free(s); | |
56 } | |
57 | |
58 OPFUNC(insn_rel16) | |
59 { | |
60 lwasm_expr_stack_t *s; | |
61 int v; | |
62 | |
63 lwasm_emitop(as, l, instab[opnum].ops[0]); | |
64 | |
37
538e15927776
Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents:
33
diff
changeset
|
65 s = lwasm_evaluate_expr(as, l, *p, NULL); |
29 | 66 if (!s) |
67 { | |
68 register_error(as, l, 1, "Bad operand"); | |
69 lwasm_emitop(as, l, 0); | |
70 return; | |
71 } | |
72 if (lwasm_expr_is_constant(s)) | |
73 register_error(as, l, 2, "Incomplete reference"); | |
74 v = lwasm_expr_get_value(s); | |
75 v -= as -> addr + 2; | |
76 lwasm_emit(as, l, (v >> 8) & 0xff); | |
77 lwasm_emit(as, l, v & 0xff); | |
78 | |
79 lwasm_expr_stack_free(s); | |
80 } |