changeset 218:b0c9df865b25

Add FDBS pseudo op. Add FDBS pseudo op which is just like FDB but it swaps the bytes of the operands. It is undocumented intentionally.
author William Astle <lost@l-w.ca>
date Sun, 10 Jun 2012 14:55:27 -0600
parents f87c86668d6b
children afd50d6b4113
files lwasm/instab.c lwasm/pseudo.c
diffstat 2 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/instab.c	Sun Jun 10 14:14:43 2012 -0600
+++ b/lwasm/instab.c	Sun Jun 10 14:55:27 2012 -0600
@@ -136,6 +136,10 @@
 #define pseudo_resolve_fdb NULL
 extern EMITFUNC(pseudo_emit_fdb);
 
+extern PARSEFUNC(pseudo_parse_fdbs);
+#define pseudo_resolve_fdbs NULL
+extern EMITFUNC(pseudo_emit_fdbs);
+
 extern PARSEFUNC(pseudo_parse_fqb);
 #define pseudo_resolve_fqb NULL
 extern EMITFUNC(pseudo_emit_fqb);
@@ -610,6 +614,7 @@
 
 	{ "fcb",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_fcb,		pseudo_resolve_fcb,				pseudo_emit_fcb,			lwasm_insn_normal},
 	{ "fdb",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_fdb,		pseudo_resolve_fdb,				pseudo_emit_fdb,			lwasm_insn_normal},
+	{ "fdbs",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_fdbs,		pseudo_resolve_fdbs,			pseudo_emit_fdbs,			lwasm_insn_normal},
 	{ "fqb",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_fqb,		pseudo_resolve_fqb,				pseudo_emit_fqb,			lwasm_insn_normal},
 	{ "end", 		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_end,		pseudo_resolve_end,				pseudo_emit_end,			lwasm_insn_normal},
 
--- a/lwasm/pseudo.c	Sun Jun 10 14:14:43 2012 -0600
+++ b/lwasm/pseudo.c	Sun Jun 10 14:55:27 2012 -0600
@@ -198,6 +198,49 @@
 	}
 }
 
+PARSEFUNC(pseudo_parse_fdbs)
+{
+	int i = 0;
+	lw_expr_t e;
+	
+	for (;;)
+	{
+		e = lwasm_parse_expr(as, p);
+		if (!e)
+		{
+			lwasm_register_error(as, l, "Bad expression (#%d)", i);
+			break;
+		}
+		lwasm_save_expr(l, i++, e);
+		if (**p != ',')
+			break;
+		(*p)++;
+	}
+	
+	l -> len = i * 2;
+}
+
+EMITFUNC(pseudo_emit_fdbs)
+{
+	int i;
+	lw_expr_t e;
+	lw_expr_t t;
+	lw_expr_t t2;
+//	int v;
+	
+	for (i = 0; i < (l -> len)/2; i++)
+	{
+		e = lwasm_fetch_expr(l, i);
+		t = lw_expr_build(lw_expr_type_int, 256);
+		t2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_divide, e, t);
+		lwasm_reduce_expr(as, t2);
+		lw_expr_destroy(t);
+		lwasm_emitexpr(l, e, 1);
+		lwasm_emitexpr(l, t2, 1);
+		lw_expr_destroy(t2);
+	}
+}
+
 PARSEFUNC(pseudo_parse_fqb)
 {
 	int i = 0;