]> Shamusworld >> Repos - rmac/blobdiff - mach.c
Fix for bug #165: apply checks when transforming adda to lea, and also negate value...
[rmac] / mach.c
diff --git a/mach.c b/mach.c
index 1309fae048d9843349977e95a2f5fad0e5e0031f..eec74f72b2d2c9d9343adf319049fe057827e88a 100644 (file)
--- a/mach.c
+++ b/mach.c
@@ -465,11 +465,16 @@ int m_adda(WORD inst, WORD siz)
                                // Immediate is between 1 and 8 so let's convert to addq
                                return m_addq(B16(01010000, 00000000), siz);
        if (CHECK_OPTS(OPT_ADDA_LEA))
-               if (a0exval > 8)
+               if (a0exval > 8 && (a0exval+0x8000)<0x10000)
                {
-                       // Immediate is larger than 8 so let's convert to lea
+                       // Immediate is larger than 8 and word size so let's convert to lea
                        am0 = ADISP;    // Change addressing mode
                        a0reg = a1reg;  // In ADISP a0reg is used instead of a1reg!
+                       if (!(inst & (1 << 14)))
+                       {
+                               // We have a suba #x,AREG so let's negate the value
+                               a0exval = -a0exval;
+                       }
                        return m_lea(B16(01000001, 11011000), SIZW);
                }
        }