changeset 373:8f9d72cfb897

Bugfixes for indexed addressing modes
author lost@starbug
date Thu, 22 Apr 2010 18:30:30 -0600
parents 90de73ba0cac
children d99322ef6f21 cf0324651d8f
files lwasm/insn_indexed.c
diffstat 1 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/insn_indexed.c	Thu Apr 22 18:19:06 2010 -0600
+++ b/lwasm/insn_indexed.c	Thu Apr 22 18:30:30 2010 -0600
@@ -292,15 +292,16 @@
 	// here, we have an expression which needs to be
 	// resolved; the post byte is determined here as well
 	lw_expr_t e;
-	
+	int pb = -1;
+	int v;
 	e = lwasm_fetch_expr(l, 0);
 	if (lw_expr_istype(e, lw_expr_type_int))
 	{
 		// we know how big it is
-		int v;
 		v = lw_expr_intval(e);
 		if (v < -128 || v > 127)
 		{
+		do16bit:
 			l -> lint = 2;
 			switch (l -> pb & 0x07)
 			{
@@ -308,19 +309,20 @@
 			case 1:
 			case 2:
 			case 3:
-				v = 0x89 | (l -> pb & 0x03) | (0x10 * (l -> pb & 0x80));
+				pb = 0x89 | (l -> pb & 0x03) | (0x10 * (l -> pb & 0x80));
 				break;
 			
 			case 4: // W
-				v = (l -> pb & 0x80) ? 0xD0 : 0xCF;
+				pb = (l -> pb & 0x80) ? 0xD0 : 0xCF;
 				break;
 				
 			case 5: // PCR
 			case 6: // PC
-				v = (l -> pb & 0x80) ? 0x9D : 0x8D;
+				pb = (l -> pb & 0x80) ? 0x9D : 0x8D;
 				break;
 			}
 			
+			l -> pb = pb;
 			return;
 		}
 		else if ((l -> pb & 0x80) || ((l -> pb & 0x07) > 3) || v < -16 || v > 15)
@@ -333,29 +335,30 @@
 			case 1:
 			case 2:
 			case 3:
-				v = 0x88 | (l -> pb & 0x03) | (0x10 * (l -> pb & 0x80));
+				pb = 0x88 | (l -> pb & 0x03) | (0x10 * (l -> pb & 0x80));
 				break;
 			
 			case 4: // W
 				// use 16 bit because W doesn't have 8 bit, unless 0
 				if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40))
 				{
-					v = (l -> pb & 0x80) ? 0x90 : 0x8F;
+					pb = (l -> pb & 0x80) ? 0x90 : 0x8F;
 					l -> lint = 0;
 				}
 				else
 				{
-					v = (l -> pb & 0x80) ? 0xD0 : 0xCF;
+					pb = (l -> pb & 0x80) ? 0xD0 : 0xCF;
 					l -> lint = 2;
 				}
 				break;
 				
 			case 5: // PCR
 			case 6: // PC
-				v = (l -> pb & 0x80) ? 0x9C : 0x8C;
+				pb = (l -> pb & 0x80) ? 0x9C : 0x8C;
 				break;
 			}
 			
+			l -> pb = pb;
 			return;
 		}
 		else
@@ -365,10 +368,11 @@
 			
 			if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40))
 			{
-				v = (l -> pb & 0x03) << 5 | v & 0x1F;
+				pb = (l -> pb & 0x03) << 5 | v & 0x1F;
 			}
 			else
-				v = (l -> pb & 0x03) << 5 | 0x84;
+				pb = (l -> pb & 0x03) << 5 | 0x84;
+			l -> pb = pb;
 			return;
 		}
 	}
@@ -379,6 +383,7 @@
 			return;
 		// force 16 bit if we don't know
 		l -> lint = 2;
+		goto do16bit;
 	}
 }