changeset 362:4867f18c872f

Added logic memory operands
author lost@starbug
date Thu, 01 Apr 2010 20:56:19 -0600
parents 105393e31f20
children d96c30e60ddf
files lwasm/Makefile.am lwasm/insn_gen.c lwasm/insn_logicmem.c
diffstat 3 files changed, 104 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)
--- /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 <http://www.gnu.org/licenses/>.
+
+Contains code for handling logic/mem instructions
+*/
+
+#include <config.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <lw_expr.h>
+
+#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);
+}