Mercurial > hg-old > index.cgi
changeset 34:b29eec6f3819
Finished adding addressing mode handlers
author | lost |
---|---|
date | Fri, 02 Jan 2009 05:17:00 +0000 |
parents | 74a3fef7c8d0 |
children | 39d750ee8d34 |
files | src/Makefile.am src/insn_gen.c src/insn_logicmem.c src/insn_misc.c |
diffstat | 4 files changed, 81 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.am Fri Jan 02 05:02:47 2009 +0000 +++ b/src/Makefile.am Fri Jan 02 05:17:00 2009 +0000 @@ -1,3 +1,3 @@ bin_PROGRAMS = lwasm -lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c +lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c EXTRA_DIST = instab.h lwasm.h expr.h util.h
--- a/src/insn_gen.c Fri Jan 02 05:02:47 2009 +0000 +++ b/src/insn_gen.c Fri Jan 02 05:17:00 2009 +0000 @@ -28,7 +28,8 @@ extern void insn_indexed_aux(asmstate_t *as, lwasm_line_t *l, const char **p, int *b1, int *b2, int *b3); -void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum) +// "extra" is required due to the way OIM, EIM, TIM, and AIM work +void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum, int extra) { int b1 = -1, b2 = -1, b3 = -1; @@ -85,6 +86,8 @@ } v1 = v1 & 0xff; lwasm_emitop(as, l, instab[opnum].ops[0]); + if (extra != -1) + lwasm_emit(as, l, extra); lwasm_emit(as, l, v1 & 0xff); return; } @@ -92,6 +95,8 @@ { // everything else is 16 bit.... lwasm_emitop(as, l, instab[opnum].ops[2]); + if (extra != -1) + lwasm_emit(as, l, extra); lwasm_emit(as, l, v1 >> 8); lwasm_emit(as, l, v1 & 0xff); return; @@ -99,6 +104,8 @@ } lwasm_emitop(as, l, instab[opnum].ops[1]); + if (extra != -1) + lwasm_emit(as, l, extra); insn_indexed_aux(as, l, (const char **)optr, &b1, &b2, &b3); if (b1 != -1) lwasm_emit(as, l, b1); @@ -119,7 +126,7 @@ } // handle non-immediate - insn_gen_aux(as, l, p, opnum); + insn_gen_aux(as, l, p, opnum, -1); } OPFUNC(insn_gen8) @@ -150,7 +157,7 @@ return; } - insn_gen_aux(as, l, p, opnum); + insn_gen_aux(as, l, p, opnum, -1); } OPFUNC(insn_gen16) @@ -180,7 +187,7 @@ return; } - insn_gen_aux(as, l, p, opnum); + insn_gen_aux(as, l, p, opnum, -1); } OPFUNC(insn_gen32) @@ -212,7 +219,7 @@ return; } - insn_gen_aux(as, l, p, opnum); + insn_gen_aux(as, l, p, opnum, -1); } OPFUNC(insn_imm8)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insn_logicmem.c Fri Jan 02 05:17:00 2009 +0000 @@ -0,0 +1,68 @@ +/* +insn_logicmem.c +Copyright © 2009 William Astle + +This file is part of LWASM. + +LWASM is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see <http://www.gnu.org/licenses/>. + +Contains code for handling logic/mem instructions +*/ + +#include <ctype.h> +#include <stdio.h> +#include <string.h> + +#include "lwasm.h" +#include "instab.h" +#include "expr.h" + +extern void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum, int extra); + +// for aim, oim, eim, tim +OPFUNC(insn_logicmem) +{ + int rval, v1; + const char *p2; + lwasm_expr_stack_t *s; + + if (**p == '#') + (*p)++; + + s = lwasm_expr_eval(*p, &p2); + *p = (char *)p2; + + if (!s) + { + register_error(as, l, 1, "Bad expression"); + return; + } + + if (v1 < -128 || v1 > 255) + { + register_error(as, l, 2, "Byte overflow"); + v1 &= 0xff; + } + + if (**p != ',' && **p != ';') + { + register_error(as, l, 1, "Bad operand"); + return; + } + + (*p)++; + + // now we have a general addressing mode - call for it + insn_gen_aux(as, l, p, opnum, v1 & 0xff); +}
--- a/src/insn_misc.c Fri Jan 02 05:02:47 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* -insn_misc.c -Copyright © 2008 William Astle - -This file is part of LWASM. - -LWASM is free software: you can redistribute it and/or modify it under the -terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Contains code for parsing miscelaneous addressing modes -*/ - -#include <ctype.h> -#include <stdio.h> -#include <string.h> -#include "lwasm.h" -#include "instab.h" - -extern void insn_gen_aux(asmstate_t *as, sourceline_t *cl, char **optr, int *b1, int *b2, int *b3, int *op); - -// for aim, oim, eim, tim -void insn_logicmem(asmstate_t *as, sourceline_t *cl, char **optr) -{ - int rval, v1; - int b1, b2, b3, op; - - if (**optr == '#') - (*optr)++; - - rval = eval_expr(as, cl, optr, &v1); - if (rval < 0) - return; - - if (v1 < -128 || v1 > 255) - { - errorp2(ERR_OVERFLOW); - v1 = 0; - } - - if (**optr != ',' && **optr != ';') - { - errorp1(ERR_BADOPER); - return; - } - - (*optr)++; - - // now we have a general addressing mode - call for it - insn_gen_aux(as, cl, optr, &b1, &b2, &b3, &op); - - emitop(op); - emit(v1 & 0xff); - if (b1 != -1) - { - emit(b1); - } - if (b2 != -1) - { - emit(b2); - } - if (b3 != -1) - { - emit(b3); - } -}