annotate src/insn_rel.c @ 59:89657cb3fdf8

Moved insn_rel.c to simplified expression evaluation
author lost
date Mon, 05 Jan 2009 00:40:58 +0000
parents 538e15927776
children a338d496350e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
1 /*
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
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
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
4
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
5 This file is part of LWASM.
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
6
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
10 version.
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
11
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
15 more details.
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
16
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
19 */
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
20
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
21 /*
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
22 for handling relative mode instructions
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
23 */
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
24
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 29
diff changeset
25 #define __insn_rel_c_seen__
29
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
26
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
27 #include <stdlib.h>
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
28
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
29 #include "expr.h"
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
30 #include "lwasm.h"
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
31 #include "instab.h"
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
32
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
33 OPFUNC(insn_rel8)
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
34 {
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
35 int v;
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
36
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
37 lwasm_emitop(as, l, instab[opnum].ops[0]);
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
38
59
89657cb3fdf8 Moved insn_rel.c to simplified expression evaluation
lost
parents: 37
diff changeset
39 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0)
29
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
40 {
59
89657cb3fdf8 Moved insn_rel.c to simplified expression evaluation
lost
parents: 37
diff changeset
41 v = 0;
29
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
42 }
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
43 v -= as -> addr + 1;
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
44 if (v < -128 || v > 127)
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
45 register_error(as, l, 2, "Byte overflow");
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
46 lwasm_emit(as, l, v & 0xff);
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
47 }
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
48
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
49 OPFUNC(insn_rel16)
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
50 {
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
51 int v;
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
52
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
53 lwasm_emitop(as, l, instab[opnum].ops[0]);
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
54
59
89657cb3fdf8 Moved insn_rel.c to simplified expression evaluation
lost
parents: 37
diff changeset
55 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0)
89657cb3fdf8 Moved insn_rel.c to simplified expression evaluation
lost
parents: 37
diff changeset
56 v = 0;
29
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
57 v -= as -> addr + 2;
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
58 lwasm_emit(as, l, (v >> 8) & 0xff);
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
59 lwasm_emit(as, l, v & 0xff);
37aec845aef3 Added relative addressing handler
lost
parents:
diff changeset
60 }