# HG changeset patch # User lost # Date 1230873420 0 # Node ID b29eec6f381970f63d5cd9f6afcbc4af39de524e # Parent 74a3fef7c8d0309558a3a64429d2a76b75a0619c Finished adding addressing mode handlers diff -r 74a3fef7c8d0 -r b29eec6f3819 src/Makefile.am --- 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 diff -r 74a3fef7c8d0 -r b29eec6f3819 src/insn_gen.c --- 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) diff -r 74a3fef7c8d0 -r b29eec6f3819 src/insn_logicmem.c --- /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 . + +Contains code for handling logic/mem instructions +*/ + +#include +#include +#include + +#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); +} diff -r 74a3fef7c8d0 -r b29eec6f3819 src/insn_misc.c --- 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 . - -Contains code for parsing miscelaneous addressing modes -*/ - -#include -#include -#include -#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); - } -}