Mercurial > hg-old > index.cgi
comparison lwasm/insn_rel.c @ 357:0cf4948d53b4
Checkpoint - adding actual cpu instructions
author | lost@starbug |
---|---|
date | Wed, 31 Mar 2010 20:12:20 -0600 |
parents | old-trunk/lwasm/old/insn_rel.c@eb230fa7d28e |
children | 9c24d9d485b9 |
comparison
equal
deleted
inserted
replaced
356:7166254491ed | 357:0cf4948d53b4 |
---|---|
1 /* | |
2 insn_rel.c | |
3 Copyright © 2009 William Astle | |
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 | |
25 #include <config.h> | |
26 #include <stdlib.h> | |
27 | |
28 #include <lw_expr.h> | |
29 | |
30 #include "lwasm.h" | |
31 #include "instab.h" | |
32 | |
33 PARSEFUNC(insn_parse_rel8) | |
34 { | |
35 int v; | |
36 lw_expr_t t, e1, e2; | |
37 int r; | |
38 | |
39 // sometimes there is a "#", ignore if there | |
40 if (**p == '#') | |
41 (*p)++; | |
42 | |
43 t = lwasm_parse_expr(as, p); | |
44 if (!t) | |
45 { | |
46 lwasm_register_error(as, l, "Bad operand"); | |
47 return; | |
48 } | |
49 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1; | |
50 | |
51 e1 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l); | |
52 e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, e1, l -> addr); | |
53 lw_expr_destroy(e1); | |
54 e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, t, e2); | |
55 lw_expr_destroy(e2); | |
56 lwasm_save_expr(l, 0, e2); | |
57 } | |
58 | |
59 EMITFUNC(insn_emit_rel8) | |
60 { | |
61 lw_expr_t e; | |
62 int offs; | |
63 | |
64 e = lwasm_fetch_expr(l, 0); | |
65 if (!lw_expr_istype(e, lw_expr_type_int)) | |
66 { | |
67 lwasm_register_error(as, l, "Illegal non-constant expression"); | |
68 return; | |
69 } | |
70 | |
71 offs = lw_expr_intval(e); | |
72 if (offs < -128 || offs > 127) | |
73 { | |
74 lwasm_register_error(as, l, "Byte overflow"); | |
75 return; | |
76 } | |
77 | |
78 lwasm_emitop(l, instab[l -> insn].ops[0]); | |
79 lwasm_emit(l, offs); | |
80 } | |
81 | |
82 PARSEFUNC(insn_parse_rel16) | |
83 { | |
84 int v; | |
85 lw_expr_t t, e1, e2; | |
86 int r; | |
87 | |
88 // sometimes there is a "#", ignore if there | |
89 if (**p == '#') | |
90 (*p)++; | |
91 | |
92 t = lwasm_parse_expr(as, p); | |
93 if (!t) | |
94 { | |
95 lwasm_register_error(as, l, "Bad operand"); | |
96 return; | |
97 } | |
98 l -> len = OPLEN(instab[l -> insn].ops[0]) + 2; | |
99 | |
100 e1 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l); | |
101 e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, e1, l -> addr); | |
102 lw_expr_destroy(e1); | |
103 e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, t, e2); | |
104 lw_expr_destroy(e2); | |
105 lwasm_save_expr(l, 0, e2); | |
106 } | |
107 | |
108 EMITFUNC(insn_emit_rel16) | |
109 { | |
110 lw_expr_t e; | |
111 int offs; | |
112 | |
113 e = lwasm_fetch_expr(l, 0); | |
114 | |
115 lwasm_emitop(l, instab[l -> insn].ops[0]); | |
116 lwasm_emitexpr(l, e, 2); | |
117 } |