fixed bug #741761
[fw/sdcc] / src / mcs51 / gen.c
index 0a5e3598970ecc4881ad3e96e3e6ec7852d27478..a9d6e638ace43bbf1b93ea630e415d4bcdeef612 100644 (file)
@@ -280,6 +280,29 @@ pointerCode (sym_link * etype)
 
 }
 
+
+/*-----------------------------------------------------------------*/
+/* leftRightUseAcc - returns size of accumulator use by operands   */
+/*-----------------------------------------------------------------*/
+static int
+leftRightUseAcc(iCode *ic)
+{
+  int accuse = 0;
+  
+  if (ic && IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))
+      && OP_SYMBOL (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->accuse)
+    accuse = (accuse < OP_SYMBOL (IC_LEFT (ic))->nRegs)
+             ? OP_SYMBOL (IC_LEFT (ic))->nRegs : accuse;
+    
+  if (ic && IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))
+      && OP_SYMBOL (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->accuse)
+    accuse = (accuse < OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+             ? OP_SYMBOL (IC_RIGHT (ic))->nRegs : accuse;
+
+  return accuse;
+}
+
+
 /*-----------------------------------------------------------------*/
 /* aopForSym - for a true symbol                                   */
 /*-----------------------------------------------------------------*/
@@ -314,7 +337,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
 
          if (sym->onStack)
            {
-             if (_G.accInUse)
+             if (_G.accInUse || leftRightUseAcc (ic))
                emitcode ("push", "acc");
 
              emitcode ("mov", "a,_bp");
@@ -325,7 +348,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
              emitcode ("mov", "%s,a",
                        aop->aopu.aop_ptr->name);
 
-             if (_G.accInUse)
+             if (_G.accInUse || leftRightUseAcc (ic))
                emitcode ("pop", "acc");
            }
          else