# HG changeset patch
# User lost@starbug
# Date 1270176979 21600
# Node ID 4867f18c872fc7bd63623e4fa0cf2c6a07b3dc60
# Parent 105393e31f2095738a3a04623320ff1df96261fe
Added logic memory operands
diff -r 105393e31f20 -r 4867f18c872f lwasm/Makefile.am
--- a/lwasm/Makefile.am Thu Apr 01 20:44:57 2010 -0600
+++ b/lwasm/Makefile.am Thu Apr 01 20:56:19 2010 -0600
@@ -3,7 +3,7 @@
lwasm_SOURCES = main.c pragma.c input.c pass1.c lwasm.c \
instab.c symbol.c macro.c \
insn_inh.c insn_rtor.c insn_tfm.c insn_rlist.c insn_rel.c \
- insn_bitbit.c insn_indexed.c insn_gen.c \
+ insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c \
pseudo.c section.c os9.c
lwasm_LDADD = -L$(top_builddir)/lib -L$(top_srcdir)/lib -L$(top_builddir)/lwlib -L$(top_srcdir)/lwlib -lgnu -llw
EXTRA_DIST = lwasm.h input.h instab.h
diff -r 105393e31f20 -r 4867f18c872f lwasm/insn_gen.c
--- a/lwasm/insn_gen.c Thu Apr 01 20:44:57 2010 -0600
+++ b/lwasm/insn_gen.c Thu Apr 01 20:56:19 2010 -0600
@@ -177,12 +177,16 @@
}
}
-void insn_emit_gen_aux(asmstate_t *as, line_t *l)
+void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra)
{
lw_expr_t e;
e = lwasm_fetch_expr(l, 0);
lwasm_emitop(l, instab[l -> insn].ops[l -> lint2]);
+
+ if (extra != -1)
+ lwasm_emit(l, extra);
+
if (l, l -> lint2 == 1)
{
lwasm_emit(l, l -> pb);
@@ -220,7 +224,7 @@
EMITFUNC(insn_emit_gen0)
{
- insn_emit_gen_aux(as, l);
+ insn_emit_gen_aux(as, l, -1);
}
PARSEFUNC(insn_parse_gen8)
@@ -281,7 +285,7 @@
return;
}
- insn_emit_gen_aux(as, l);
+ insn_emit_gen_aux(as, l, -1);
}
PARSEFUNC(insn_parse_gen16)
@@ -342,7 +346,7 @@
return;
}
- insn_emit_gen_aux(as, l);
+ insn_emit_gen_aux(as, l, -1);
}
PARSEFUNC(insn_parse_gen32)
@@ -403,7 +407,7 @@
return;
}
- insn_emit_gen_aux(as, l);
+ insn_emit_gen_aux(as, l, -1);
}
PARSEFUNC(insn_parse_imm8)
diff -r 105393e31f20 -r 4867f18c872f lwasm/insn_logicmem.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lwasm/insn_logicmem.c Thu Apr 01 20:56:19 2010 -0600
@@ -0,0 +1,94 @@
+/*
+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
+
+#include
+
+#include "lwasm.h"
+#include "instab.h"
+
+extern void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **optr);
+extern void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force);
+extern void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra);
+
+// for aim, oim, eim, tim
+PARSEFUNC(insn_parse_logicmem)
+{
+ const char *p2;
+ lw_expr_t *s;
+
+ if (**p == '#')
+ (*p)++;
+
+ s = lwasm_parse_expr(as, p);
+ if (!s)
+ {
+ lwasm_register_error(as, l, "Bad operand");
+ return;
+ }
+
+ lwasm_save_expr(l, 100, p);
+ if (**p != ',' && **p != ';')
+ {
+ lwasm_register_error(as, l, "Bad operand");
+ return;
+ }
+
+ (*p)++;
+
+ // now we have a general addressing mode - call for it
+ insn_parse_gen_aux(as, l, p);
+}
+
+RESOLVEFUNC(insn_resolve_logicmem)
+{
+ if (l -> len != -1)
+ return;
+
+ insn_resolve_gen_aux(as, l, force);
+}
+
+EMITFUNC(insn_emit_logicmem)
+{
+ lw_expr_t e;
+ int v;
+
+ e = lwasm_fetch_expr(l, 100);
+ if (!lw_expr_istype(e, lw_expr_type_int))
+ {
+ lwasm_register_error(as, l, "Immediate byte must be fully resolved");
+ return;
+ }
+
+ v = lw_expr_intval(e);
+ if (v < -128 || v > 255)
+ {
+ lwasm_register_error(as, l, "Byte overflow");
+ return;
+ }
+
+ insn_emit_gen_aux(as, l, v);
+}