diff lwasm/insn_gen.c @ 470:2c1c5dd84024

Add << prefix to force 5 bit offsets in indexed modes Rounding out the compliment of operand size prefixes, we now have "<<" to mean "force 5 bits". According to Steve Bjork, this was the "official" way to do this since 1980. However, I have no official Motorola source for that. It does suggest that the choice of "<<" is consistent with other (historical) assemblers, though. Either way, it seems the most logical choice while avoiding any conflicts with legal source code, so "<<" it is.
author William Astle <lost@l-w.ca>
date Mon, 23 Jul 2018 17:45:18 -0600
parents 3948c874901b
children eac8f5f0867d
line wrap: on
line diff
--- a/lwasm/insn_gen.c	Sun Mar 04 10:24:58 2018 -0700
+++ b/lwasm/insn_gen.c	Mon Jul 23 17:45:18 2018 -0600
@@ -65,6 +65,11 @@
 	{
 		(*p)++;
 		l -> lint2 = 0;
+		if (**p == '<')
+		{
+			*p = optr2;
+			goto indexed;
+		}
 	}
 	// for compatibility with asxxxx
 	// * followed by a digit, alpha, or _, or ., or ?, or another * is "f8"
@@ -175,7 +180,10 @@
 		}
 		else if (l -> lint2 == 1 && l -> lint != -1)
 		{
-			l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
+			if (l -> lint == 3)
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
+			else
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
 		}
 	}
 }
@@ -261,7 +269,10 @@
 		}
 		else if (l -> lint2 == 1 && l -> lint != -1)
 		{
-			l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
+			if (l -> lint == 3)
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
+			else
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
 		}
 	}
 }
@@ -278,6 +289,27 @@
 	
 	if (l -> lint2 == 1)
 	{
+		if (l -> lint == 3)
+		{
+			int offs;
+			if (lw_expr_istype(e, lw_expr_type_int))
+			{
+				offs = lw_expr_intval(e);
+				if ((offs >= -16 && offs <= 15) || offs >= 0xFFF0)
+				{
+					l -> pb |= offs & 0x1f;
+					l -> lint = 0;
+				}
+				else
+				{
+					lwasm_register_error(as, l, E_BYTE_OVERFLOW);
+				}
+			}
+			else
+			{
+				lwasm_register_error(as, l, E_EXPRESSION_NOT_RESOLVED);
+			}
+		}
 		lwasm_emit(l, l -> pb);
 		if (l -> lint > 0)
 		{
@@ -375,7 +407,10 @@
 		}
 		else if (l -> lint2 == 1 && l -> lint != -1)
 		{
-			l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
+			if (l -> lint == 3)
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
+			else
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
 		}
 	}
 }
@@ -447,7 +482,10 @@
 		}
 		else if (l -> lint2 == 1 && l -> lint != -1)
 		{
-			l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
+			if (l -> lint == 3)
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
+			else
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
 		}
 	}
 }
@@ -509,7 +547,10 @@
 		}
 		else if (l -> lint2 == 1 && l -> lint != -1)
 		{
-			l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
+			if (l -> lint == 3)
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
+			else
+				l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
 		}
 	}
 }