another possible impedance mismatch in genPlus/genMinus
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 21 Sep 2000 21:17:41 +0000 (21:17 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 21 Sep 2000 21:17:41 +0000 (21:17 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@399 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/ds390/gen.c

index 6edba6ff2533295f8a7c962119128e315e4e7903..527200a4bd3693baa95b40a9ac37a5e7248bd540 100644 (file)
@@ -2786,6 +2786,7 @@ static void genPlus (iCode *ic)
 {
     int size, offset = 0;
     bool pushResult = FALSE;
+    int  rSize;
 
     D(emitcode(";", "genPlus "););
 
@@ -2883,19 +2884,33 @@ static void genPlus (iCode *ic)
         aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
 
         size = getDataSize(IC_LEFT(ic));
-
+       rSize = getDataSize(IC_RESULT(ic));
+       
        /* If the pushed data is bigger than the result,
         * simply discard unused bytes. Icky, but works.
         *
         * Should we throw a warning here? We're losing data...
         */
-       while (size > getDataSize(IC_RESULT(ic)))
+       while (size > rSize)
        {
-          emitcode(";", "discarding unused result byte.");
+          D(emitcode(";", "discarding unused result byte."););
           emitcode("pop", "acc");
           size--;
           offset--; 
        }
+       if (size < rSize)
+       {
+           emitcode("clr", "a");
+           /* Conversly, we haven't pushed enough here.
+            * just zero-pad, and all is well. 
+            */
+           while (size < rSize)
+           {
+               emitcode("push", "acc");
+               size++;
+               offset++;
+           }
+       }
 
         while(size--)
         {
@@ -3083,6 +3098,7 @@ static void genMinusBits (iCode *ic)
 static void genMinus (iCode *ic)
 {
     int size, offset = 0;
+    int rSize;
     unsigned long lit = 0L;
     bool pushResult = FALSE;
 
@@ -3157,6 +3173,7 @@ static void genMinus (iCode *ic)
         aopOp (IC_RESULT(ic),ic,TRUE, FALSE);
 
         size = getDataSize(IC_LEFT(ic));
+        rSize = getDataSize(IC_RESULT(ic));
 
        /* If the pushed data is bigger than the result,
         * simply discard unused bytes. Icky, but works.
@@ -3170,6 +3187,19 @@ static void genMinus (iCode *ic)
           size--;
           offset--; 
        }
+       if (size < rSize)
+       {
+           emitcode("clr", "a");
+           /* Conversly, we haven't pushed enough here.
+            * just zero-pad, and all is well. 
+            */
+           while (size < rSize)
+           {
+               emitcode("push", "acc");
+               size++;
+               offset++;
+           }
+       }
 
         while(size--)
         {