diff lwasm/pseudo.c @ 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
line wrap: on
line diff
--- 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;