]> git.gag.com Git - fw/sdcc/commitdiff
fix "inc sp"
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 2 Dec 2001 23:01:45 +0000 (23:01 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 2 Dec 2001 23:01:45 +0000 (23:01 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1659 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/mcs51/gen.c

index d91f0d4c205b7719bfe38176ed57b333aca7cd70..9a81b0cf89a13d9b950b56a970c8b83f82fbf817 100644 (file)
@@ -2171,6 +2171,7 @@ genFunction (iCode * ic)
   symbol *sym;
   sym_link *ftype;
   bool   switchedPSW = FALSE;
+  int calleesaves_saved_register = -1;
 
   _G.nRegsSaved = 0;
   /* create the function header */
@@ -2367,6 +2368,9 @@ genFunction (iCode * ic)
                  if (bitVectBitValue (sym->regsUsed, i) ||
                      (mcs51_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
                    {
+                     /* remember one saved register for later usage */
+                     if (calleesaves_saved_register < 0)
+                       calleesaves_saved_register = i;
                      emitcode ("push", "%s", mcs51_regWithIdx (i)->dname);
                      _G.nRegsSaved++;
                    }
@@ -2418,16 +2422,32 @@ genFunction (iCode * ic)
 
        }
       else if (i > 5)
-       {
-
-         /* ISRs will be handled by the code above, because they
-            can't have parameters. Therefore it's save to use r0 */
-         emitcode ("mov", "r0,a");
-         emitcode ("mov", "a,sp");
-         emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
-         emitcode ("mov", "sp,a");
-         emitcode ("mov", "a,r0");
-
+        {
+         if (IFFUNC_CALLEESAVES(sym->type))
+           {
+             /* if it's a callee-saves function we need a saved register */
+             if (calleesaves_saved_register >= 0)
+               {
+                 emitcode ("mov", "%s,a", mcs51_regWithIdx (calleesaves_saved_register)->dname);
+                 emitcode ("mov", "a,sp");
+                 emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+                 emitcode ("mov", "sp,a");
+                 emitcode ("mov", "a,%s", mcs51_regWithIdx (calleesaves_saved_register)->dname);
+               }
+             else
+               /* do it the hard way */
+               while (i--)
+                 emitcode ("inc", "sp");
+           }
+         else
+           {
+             /* not callee-saves, we can clobber ar0 */
+             emitcode ("mov", "ar0,a");
+             emitcode ("mov", "a,sp");
+             emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+             emitcode ("mov", "sp,a");
+             emitcode ("mov", "a,ar0");
+           }
        }
       else
        while (i--)