Mercurial > hg-old > index.cgi
annotate src/insn_rel.c @ 74:c8c772ef5df9
Checkpointing object target implementation
author | lost |
---|---|
date | Thu, 08 Jan 2009 01:18:40 +0000 |
parents | 89657cb3fdf8 |
children | a338d496350e |
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 int v; | |
36 | |
37 lwasm_emitop(as, l, instab[opnum].ops[0]); | |
38 | |
59 | 39 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0) |
29 | 40 { |
59 | 41 v = 0; |
29 | 42 } |
43 v -= as -> addr + 1; | |
44 if (v < -128 || v > 127) | |
45 register_error(as, l, 2, "Byte overflow"); | |
46 lwasm_emit(as, l, v & 0xff); | |
47 } | |
48 | |
49 OPFUNC(insn_rel16) | |
50 { | |
51 int v; | |
52 | |
53 lwasm_emitop(as, l, instab[opnum].ops[0]); | |
54 | |
59 | 55 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0) |
56 v = 0; | |
29 | 57 v -= as -> addr + 2; |
58 lwasm_emit(as, l, (v >> 8) & 0xff); | |
59 lwasm_emit(as, l, v & 0xff); | |
60 } |