* src/ds390/gen.c (pushSide, genPcall),
[fw/sdcc] / src / mcs51 / gen.c
index d18f8e3e247afb1ecef2b14fb9607955090676e7..9db691c3917305b244b58a6d05f6645a4393de48 100644 (file)
@@ -28,7 +28,7 @@
       Made everything static
 -------------------------------------------------------------------------*/
 
-#define D(x) do if (!options.noGenComments) {x;} while(0)
+#define D(x) do if (options.verboseAsm) {x;} while(0)
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -119,7 +119,6 @@ static char *rb1regs[] = {
 };
 
 extern struct dbuf_s *codeOutBuf;
-static void saveRBank (int, iCode *, bool);
 
 #define RESULTONSTACK(x) \
                          (IC_RESULT(x) && IC_RESULT(x)->aop && \
@@ -182,19 +181,20 @@ emitcode (const char *inst, const char *fmt,...)
       lbp++;
     }
 
-  if (lbp && *lbp)
+  if (lbp)
     {
       rtrackUpdate (lbp);
 
       lineCurr = (lineCurr ?
                   connectLine (lineCurr, newLineNode (lb)) :
                   (lineHead = newLineNode (lb)));
+
+      lineCurr->isInline = _G.inLine;
+      lineCurr->isDebug = _G.debugLine;
+      lineCurr->ic = _G.current_iCode;
+      lineCurr->isComment = (*lbp==';');
     }
 
-  lineCurr->isInline = _G.inLine;
-  lineCurr->isDebug = _G.debugLine;
-  lineCurr->ic = _G.current_iCode;
-  lineCurr->isComment = (*lbp==';');
   va_end (ap);
 
   dbuf_destroy(&dbuf);
@@ -543,7 +543,7 @@ leftRightUseAcc(iCode *ic)
   if (ic->op == IFX)
     {
       op = IC_COND (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -554,7 +554,7 @@ leftRightUseAcc(iCode *ic)
   else if (ic->op == JUMPTABLE)
     {
       op = IC_JTCOND (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -565,7 +565,7 @@ leftRightUseAcc(iCode *ic)
   else
     {
       op = IC_LEFT (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -573,7 +573,7 @@ leftRightUseAcc(iCode *ic)
             accuseSize = size;
         }
       op = IC_RIGHT (ic);
-      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+      if (IS_OP_ACCUSE (op))
         {
           accuse = 1;
           size = getSize (OP_SYMBOL (op)->type);
@@ -712,7 +712,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
 }
 
 /*-----------------------------------------------------------------*/
-/* aopForRemat - rematerialzes an object                           */
+/* aopForRemat - rematerializes an object                          */
 /*-----------------------------------------------------------------*/
 static asmop *
 aopForRemat (symbol * sym)
@@ -728,13 +728,15 @@ aopForRemat (symbol * sym)
         val += (int) operandLitValue (IC_RIGHT (ic));
       else if (ic->op == '-')
         val -= (int) operandLitValue (IC_RIGHT (ic));
-      else if (IS_CAST_ICODE(ic)) {
-              sym_link *from_type = operandType(IC_RIGHT(ic));
-              aop->aopu.aop_immd.from_cast_remat = 1;
-              ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
-              ptr_type = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL);
-              continue;
-      } else break;
+      else if (IS_CAST_ICODE(ic))
+        {
+          sym_link *from_type = operandType(IC_RIGHT(ic));
+          aop->aopu.aop_immd.from_cast_remat = 1;
+          ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode;
+          ptr_type = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL);
+          continue;
+        }
+      else break;
 
       ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
     }
@@ -954,8 +956,8 @@ aopOp (operand * op, iCode * ic, bool result)
   /* if the type is a conditional */
   if (sym->regType == REG_CND)
     {
-      aop = op->aop = sym->aop = newAsmop (AOP_CRY);
-      aop->size = 0;
+      sym->aop = op->aop = aop = newAsmop (AOP_CRY);
+      aop->size = sym->ruonly ? 1 : 0;
       return;
     }
 
@@ -969,14 +971,14 @@ aopOp (operand * op, iCode * ic, bool result)
       if (sym->remat)
         {
           sym->aop = op->aop = aop = aopForRemat (sym);
-          aop->size = getSize (sym->type);
+          aop->size = operandSize (op);
           return;
         }
 
       if (sym->accuse)
         {
           int i;
-          aop = op->aop = sym->aop = newAsmop (AOP_ACC);
+          sym->aop = op->aop = aop = newAsmop (AOP_ACC);
           aop->size = getSize (sym->type);
           for (i = 0; i < 2; i++)
             aop->aopu.aop_str[i] = accUse[i];
@@ -987,7 +989,7 @@ aopOp (operand * op, iCode * ic, bool result)
         {
           unsigned i;
 
-          aop = op->aop = sym->aop = newAsmop (AOP_STR);
+          sym->aop = op->aop = aop = newAsmop (AOP_STR);
           aop->size = getSize (sym->type);
           for (i = 0; i < fReturnSizeMCS51; i++)
             aop->aopu.aop_str[i] = fReturn[i];
@@ -1004,8 +1006,7 @@ aopOp (operand * op, iCode * ic, bool result)
               oldAsmOp = sym->usl.spillLoc->aop;
               sym->usl.spillLoc->aop = NULL;
             }
-          sym->aop = op->aop = aop =
-                     aopForSym (ic, sym->usl.spillLoc, result);
+          sym->aop = op->aop = aop = aopForSym (ic, sym->usl.spillLoc, result);
           if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
             {
               /* Don't reuse the new aop, go with the last one */
@@ -1040,7 +1041,7 @@ aopOp (operand * op, iCode * ic, bool result)
 
 /*-----------------------------------------------------------------*/
 /* freeAsmop - free up the asmop given to an operand               */
-/*----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
 static void
 freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
 {
@@ -1492,6 +1493,7 @@ aopPut (operand * result, const char *s, int offset)
   bool bvolatile = isOperandVolatile (result, FALSE);
   bool accuse = FALSE;
   asmop * aop = AOP (result);
+  const char *d = NULL;
 
   if (aop->size && offset > (aop->size - 1))
     {
@@ -1667,28 +1669,40 @@ aopPut (operand * result, const char *s, int offset)
       break;
 
     case AOP_CRY:
-      /* if result no bit variable */
-      if (!aop->aopu.aop_dir)
-        {
-          assert (!strcmp (s, "c"));
-          /* inefficient: move carry into A and use jz/jnz */
-          emitcode ("clr", "a");
-          emitcode ("rlc", "a");
-          accuse = TRUE;
-        }
-      else if (s == zero)
-          emitcode ("clr", "%s", aop->aopu.aop_dir);
-      else if (s == one)
-          emitcode ("setb", "%s", aop->aopu.aop_dir);
-      else if (!strcmp (s, "c"))
-          emitcode ("mov", "%s,c", aop->aopu.aop_dir);
-      else if (strcmp (s, aop->aopu.aop_dir))
+      // destination is carry for return-use-only
+      d = (IS_OP_RUONLY (result)) ? "c" : aop->aopu.aop_dir;
+      // source is no literal and not in carry
+      if ((s != zero) && (s != one) && strcmp (s, "c"))
         {
           MOVA (s);
           /* set C, if a >= 1 */
           emitcode ("add", "a,#0xff");
-          emitcode ("mov", "%s,c", aop->aopu.aop_dir);
+          s = "c";
         }
+      // now source is zero, one or carry
+
+      /* if result no bit variable */
+      if (!d)
+        {
+          if (!strcmp (s, "c"))
+            {
+              /* inefficient: move carry into A and use jz/jnz */
+              emitcode ("clr", "a");
+              emitcode ("rlc", "a");
+              accuse = TRUE;
+            }
+          else
+            {
+              MOVA (s);
+              accuse = TRUE;
+            }
+        }
+      else if (s == zero)
+          emitcode ("clr", "%s", d);
+      else if (s == one)
+          emitcode ("setb", "%s", d);
+      else if (strcmp (s, d))
+          emitcode ("mov", "%s,c", d);
       break;
 
     case AOP_STR:
@@ -1839,9 +1853,10 @@ outBitC (operand * result)
   /* if the result is bit */
   if (AOP_TYPE (result) == AOP_CRY)
     {
-      aopPut (result, "c", 0);
+      if (!IS_OP_RUONLY (result))
+        aopPut (result, "c", 0);
     }
-  else
+  else if (AOP_TYPE (result) != AOP_DUMMY)
     {
       emitcode ("clr", "a");
       emitcode ("rlc", "a");
@@ -1992,7 +2007,7 @@ genNot (iCode * ic)
         }
       else
         {
-          emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+          toCarry (IC_LEFT (ic));
           emitcode ("cpl", "c");
           outBitC (IC_RESULT (ic));
         }
@@ -2235,6 +2250,7 @@ saveRegisters (iCode * lic)
           rsave = bitVectCplAnd (rsave, rsavebits);
           rsave = bitVectSetBit (rsave, bitVectFirstBit (rsavebits));
         }
+      freeBitVect (rsavebits);
 
       if (count == 1)
         {
@@ -2305,6 +2321,7 @@ saveRegisters (iCode * lic)
             }
         }
     }
+  freeBitVect (rsave);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2334,6 +2351,7 @@ unsaveRegisters (iCode * ic)
           rsave = bitVectCplAnd (rsave, rsavebits);
           rsave = bitVectSetBit (rsave, bitVectFirstBit (rsavebits));
         }
+      freeBitVect (rsavebits);
 
       if (count == 1)
         {
@@ -2393,6 +2411,7 @@ unsaveRegisters (iCode * ic)
             }
         }
     }
+  freeBitVect (rsave);
 }
 
 
@@ -2400,9 +2419,29 @@ unsaveRegisters (iCode * ic)
 /* pushSide -                                                      */
 /*-----------------------------------------------------------------*/
 static void
-pushSide (operand * oper, int size)
+pushSide (operand * oper, int size, iCode * ic)
 {
   int offset = 0;
+  int nPushed = _G.r0Pushed + _G.r1Pushed;
+
+  aopOp (oper, ic, FALSE);
+
+  if (nPushed != _G.r0Pushed + _G.r1Pushed)
+    {
+      while (offset < size)
+        {
+          char *l = aopGet (oper, offset, FALSE, TRUE);
+          emitcode ("mov", "%s,%s", fReturn[offset++], l);
+        }
+      freeAsmop (oper, NULL, ic, TRUE);
+      offset = 0;
+      while (offset < size)
+        {
+          emitcode ("push", "%s", fReturn[offset++]);
+        }
+      return;
+    }
+
   while (size--)
     {
       char *l = aopGet (oper, offset++, FALSE, TRUE);
@@ -2418,6 +2457,8 @@ pushSide (operand * oper, int size)
           emitcode ("push", "%s", l);
         }
     }
+
+  freeAsmop (oper, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2606,7 +2647,7 @@ static void
 saveRBank (int bank, iCode * ic, bool pushPsw)
 {
   int i;
-  int count = 8 + ((mcs51_nRegs > 8) ? 1 : 0) + (pushPsw ? 1 : 0);
+  int count = 8 + (pushPsw ? 1 : 0);
   asmop *aop = NULL;
   regs *r = NULL;
 
@@ -2615,7 +2656,7 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
       if (!ic)
         {
           /* Assume r0 is available for use. */
-          r = REG_WITH_INDEX (R0_IDX);;
+          r = REG_WITH_INDEX (R0_IDX);
         }
       else
         {
@@ -2644,22 +2685,6 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
                   regs8051[i].base, 8 * bank + regs8051[i].offset);
     }
 
-  if (mcs51_nRegs > 8)
-    {
-      if (options.useXstack)
-        {
-          emitcode ("mov", "a,bits");
-          emitcode ("movx", "@%s,a", r->name);
-          if (--count)
-            emitcode ("inc", "%s", r->name);
-        }
-      else
-        {
-          emitcode ("push", "bits");
-        }
-      BitBankUsed = 1;
-    }
-
   if (pushPsw)
     {
       if (options.useXstack)
@@ -2681,9 +2706,9 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
     }
 
   if (ic)
-  {
-    ic->bankSaved = 1;
-  }
+    {
+      ic->bankSaved = 1;
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -2725,20 +2750,6 @@ unsaveRBank (int bank, iCode * ic, bool popPsw)
         }
     }
 
-  if (mcs51_nRegs > 8)
-    {
-      if (options.useXstack)
-        {
-          emitcode ("dec", "%s", r->name);
-          emitcode ("movx", "a,@%s", r->name);
-          emitcode ("mov", "bits,a");
-        }
-      else
-        {
-          emitcode ("pop", "bits");
-        }
-    }
-
   for (i = 7; i >= 0; i--)
     {
       if (options.useXstack)
@@ -3057,7 +3068,7 @@ genPcall (iCode * ic)
   /* if we are calling a not _naked function that is not using
      the same register bank then we need to save the
      destination registers on the stack */
-  if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) &&
+  if (currFunc && dtype && !IFFUNC_ISNAKED (dtype) &&
       (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) &&
       !IFFUNC_ISISR (dtype))
     {
@@ -3079,12 +3090,12 @@ genPcall (iCode * ic)
       if (swapBanks)
         {
           emitcode ("mov", "psw,#0x%02x",
-           ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+           ((FUNC_REGBANK (dtype)) << 3) & 0xff);
         }
 
-      if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype)))
+      if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT (getSpec(dtype)))
         {
-          if (IFFUNC_CALLEESAVES(dtype))
+          if (IFFUNC_CALLEESAVES (dtype))
             {
               werror (E_BANKED_WITH_CALLEESAVES);
             }
@@ -3105,9 +3116,9 @@ genPcall (iCode * ic)
     }
   else
     {
-      if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype)))
+      if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT (getSpec(dtype)))
         {
-          if (IFFUNC_CALLEESAVES(dtype))
+          if (IFFUNC_CALLEESAVES (dtype))
             {
               werror (E_BANKED_WITH_CALLEESAVES);
             }
@@ -3142,7 +3153,7 @@ genPcall (iCode * ic)
               if (swapBanks)
                 {
                   emitcode ("mov", "psw,#0x%02x",
-                   ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+                   ((FUNC_REGBANK (dtype)) << 3) & 0xff);
                 }
 
               /* make the call */
@@ -3157,14 +3168,10 @@ genPcall (iCode * ic)
           emitcode ("mov", "a,#(%05d$ >> 8)", (rlbl->key + 100));
           emitcode ("push", "acc");
 
-          /* now push the calling address */
-          aopOp (IC_LEFT (ic), ic, FALSE);
-
-          pushSide (IC_LEFT (ic), FPTRSIZE);
-
-          freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
+          /* now push the function address */
+          pushSide (IC_LEFT (ic), FPTRSIZE, ic);
 
-          /* if send set is not empty the assign */
+          /* if send set is not empty then assign */
           if (_G.sendSet)
             {
               genSend(reverseSet(_G.sendSet));
@@ -3174,7 +3181,7 @@ genPcall (iCode * ic)
           if (swapBanks)
             {
               emitcode ("mov", "psw,#0x%02x",
-               ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+               ((FUNC_REGBANK (dtype)) << 3) & 0xff);
             }
 
           /* make the call */
@@ -3207,7 +3214,7 @@ genPcall (iCode * ic)
           if (swapBanks)
             {
               emitcode ("mov", "psw,#0x%02x",
-               ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+               ((FUNC_REGBANK (dtype)) << 3) & 0xff);
             }
 
           /* make the call */
@@ -3216,7 +3223,7 @@ genPcall (iCode * ic)
     }
   if (swapBanks)
     {
-      selectRegBank (FUNC_REGBANK(currFunc->type), IS_BIT (etype));
+      selectRegBank (FUNC_REGBANK (currFunc->type), IS_BIT (etype));
     }
 
   /* if we need assign a result value */
@@ -3263,7 +3270,7 @@ genPcall (iCode * ic)
 //    unsaveRBank (FUNC_REGBANK (dtype), ic, TRUE);
 
   /* if we had saved some registers then unsave them */
-  if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
+  if (ic->regsSaved && !IFFUNC_CALLEESAVES (dtype))
     unsaveRegisters (ic);
 
   if (IS_BIT (OP_SYM_ETYPE (IC_RESULT (ic))))
@@ -3377,6 +3384,16 @@ genFunction (iCode * ic)
      save acc, b, dpl, dph  */
   if (IFFUNC_ISISR (sym->type))
     {
+      bitVect *rsavebits;
+
+      rsavebits = bitVectIntersect (bitVectCopy (mcs51_allBitregs ()), sym->regsUsed);
+      if (IFFUNC_HASFCALL(sym->type) || !bitVectIsZero (rsavebits))
+        {
+          emitcode ("push", "bits");
+          BitBankUsed = 1;
+        }
+      freeBitVect (rsavebits);
+
       if (!inExcludeList ("acc"))
         emitcode ("push", "acc");
       if (!inExcludeList ("b"))
@@ -3400,12 +3417,11 @@ genFunction (iCode * ic)
               /* if any registers used */
               if (sym->regsUsed)
                 {
-                  bool bits_pushed = FALSE;
                   /* save the registers used */
                   for (i = 0; i < sym->regsUsed->size; i++)
                     {
                       if (bitVectBitValue (sym->regsUsed, i))
-                        bits_pushed = pushReg (i, bits_pushed);
+                        pushReg (i, TRUE);
                     }
                 }
             }
@@ -3422,7 +3438,7 @@ genFunction (iCode * ic)
                 }
             }
         }
-        else
+      else
         {
             /* This ISR uses a non-zero bank.
              *
@@ -3607,7 +3623,7 @@ genFunction (iCode * ic)
           int ofs;
 
           _G.current_iCode = ric;
-          D(emitcode (";     genReceive",""));
+          D(emitcode (";", "genReceive"));
           for (ofs=0; ofs < sym->recvSize; ofs++)
             {
               if (!strcmp (fReturn[ofs], "a"))
@@ -3632,7 +3648,7 @@ genFunction (iCode * ic)
           int ofs;
 
           _G.current_iCode = ric;
-          D(emitcode (";     genReceive",""));
+          D(emitcode (";", "genReceive"));
           for (ofs=0; ofs < sym->recvSize; ofs++)
             {
               emitcode ("mov", "%s,%s", rsym->regs[ofs]->name, fReturn[ofs]);
@@ -3811,6 +3827,7 @@ genEndFunction (iCode * ic)
 
   if (IFFUNC_ISISR (sym->type))
     {
+      bitVect *rsavebits;
 
       /* now we need to restore the registers */
       /* if this isr has no bank i.e. is going to
@@ -3827,12 +3844,11 @@ genEndFunction (iCode * ic)
               /* if any registers used */
               if (sym->regsUsed)
                 {
-                  bool bits_popped = FALSE;
                   /* save the registers used */
                   for (i = sym->regsUsed->size; i >= 0; i--)
                     {
                       if (bitVectBitValue (sym->regsUsed, i))
-                        bits_popped = popReg (i, bits_popped);
+                        popReg (i, TRUE);
                     }
                 }
             }
@@ -3843,8 +3859,8 @@ genEndFunction (iCode * ic)
                       emitcode ("pop","%s",rb1regs[i]);
                   }
               }
-              /* this function has  a function call cannot
-                 determines register usage so we will have to pop the
+              /* this function has a function call. We cannot
+                 determine register usage so we will have to pop the
                  entire bank */
               unsaveRBank (0, ic, FALSE);
             }
@@ -3885,6 +3901,11 @@ genEndFunction (iCode * ic)
       if (!inExcludeList ("acc"))
         emitcode ("pop", "acc");
 
+      rsavebits = bitVectIntersect (bitVectCopy (mcs51_allBitregs ()), sym->regsUsed);
+      if (IFFUNC_HASFCALL(sym->type) || !bitVectIsZero (rsavebits))
+        emitcode ("pop", "bits");
+      freeBitVect (rsavebits);
+
       /* if debug then send end of function */
       if (options.debug && currFunc)
         {
@@ -4051,7 +4072,8 @@ genRet (iCode * ic)
 
   if (IS_BIT(_G.currentFunc->etype))
     {
-      toCarry (IC_LEFT (ic));
+      if (!IS_OP_RUONLY (IC_LEFT (ic)))
+        toCarry (IC_LEFT (ic));
     }
   else
     {
@@ -4163,12 +4185,12 @@ genPlusIncr (iCode * ic)
   if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
     return FALSE;
 
-  icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+  icount = (unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
 
   D(emitcode (";","genPlusIncr"));
 
   /* if increment >=16 bits in register or direct space */
-  if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || 
+  if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG ||
         AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ||
         (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) &&
       sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
@@ -4488,7 +4510,7 @@ genPlus (iCode * ic)
       /* if result in bit space */
       if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
         {
-          if ((unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L)
+          if (ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L)
             emitcode ("cpl", "c");
           outBitC (IC_RESULT (ic));
         }
@@ -4525,7 +4547,7 @@ genPlus (iCode * ic)
        && (SPEC_ADDR (OP_SYM_ETYPE (op)) & 0xff) == 0
      )
     {
-      D(emitcode (";     genPlus aligned array",""));
+      D(emitcode (";", "genPlus aligned array"));
       aopPut (IC_RESULT (ic),
               aopGet (rightOp, 0, FALSE, FALSE),
               0);
@@ -4548,13 +4570,13 @@ genPlus (iCode * ic)
   /* if the lower bytes of a literal are zero skip the addition */
   if (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT )
     {
-       while ((0 == ((unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) & (0xff << skip_bytes*8))) &&
+       while ((0 == ((unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) & (0xff << skip_bytes*8))) &&
               (skip_bytes+1 < size))
          {
            skip_bytes++;
          }
        if (skip_bytes)
-         D(emitcode (";     genPlus shortcut",""));
+         D(emitcode (";", "genPlus shortcut"));
     }
 
   while (size--)
@@ -4631,13 +4653,13 @@ genMinusDec (iCode * ic)
 
   /* if the literal value of the right hand side
      is greater than 4 then it is not worth it */
-  if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
+  if ((icount = (unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
     return FALSE;
 
   D (emitcode (";", "genMinusDec"));
 
   /* if decrement >=16 bits in register or direct space */
-  if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || 
+  if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG ||
         AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ||
         (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) &&
       sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
@@ -4855,7 +4877,7 @@ genMinus (iCode * ic)
       unsigned long lit = 0L;
       bool useCarry = FALSE;
 
-      lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+      lit = ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
       lit = -(long) lit;
 
       while (size--)
@@ -5055,7 +5077,7 @@ genMultOneByte (operand * left,
       if (AOP_TYPE(left) == AOP_LIT)
         {
           /* signed literal */
-          signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+          signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit);
           if (val < 0)
             compiletimeSign = TRUE;
         }
@@ -5069,7 +5091,7 @@ genMultOneByte (operand * left,
       if (AOP_TYPE(right) == AOP_LIT)
         {
           /* signed literal */
-          signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit);
+          signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit);
           if (val < 0)
             compiletimeSign ^= TRUE;
         }
@@ -5090,7 +5112,7 @@ genMultOneByte (operand * left,
   /* save the signs of the operands */
   if (AOP_TYPE(right) == AOP_LIT)
     {
-      signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit);
+      signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit);
 
       if (!rUnsigned && val < 0)
         emitcode ("mov", "b,#0x%02x", -val);
@@ -5116,7 +5138,7 @@ genMultOneByte (operand * left,
 
   if (AOP_TYPE(left) == AOP_LIT)
     {
-      signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+      signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit);
 
       if (!lUnsigned && val < 0)
         emitcode ("mov", "a,#0x%02x", -val);
@@ -5225,7 +5247,7 @@ genDivbits (operand * left,
   char *l;
   bool pushedB;
 
-  D(emitcode (";     genDivbits",""));
+  D(emitcode (";", "genDivbits"));
 
   pushedB = pushB ();
 
@@ -5258,7 +5280,7 @@ genDivOneByte (operand * left,
   symbol *lbl;
   int size, offset;
 
-  D(emitcode (";     genDivOneByte",""));
+  D(emitcode (";", "genDivOneByte"));
 
   /* Why is it necessary that genDivOneByte() can return an int result?
      Have a look at:
@@ -5323,7 +5345,7 @@ genDivOneByte (operand * left,
       if (AOP_TYPE(left) == AOP_LIT)
         {
           /* signed literal */
-          signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+          signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit);
           if (val < 0)
             compiletimeSign = TRUE;
         }
@@ -5337,7 +5359,7 @@ genDivOneByte (operand * left,
       if (AOP_TYPE(right) == AOP_LIT)
         {
           /* signed literal */
-          signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit);
+          signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit);
           if (val < 0)
             compiletimeSign ^= TRUE;
         }
@@ -5358,7 +5380,7 @@ genDivOneByte (operand * left,
   /* save the signs of the operands */
   if (AOP_TYPE(right) == AOP_LIT)
     {
-      signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit);
+      signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit);
 
       if (!rUnsigned && val < 0)
         emitcode ("mov", "b,#0x%02x", -val);
@@ -5384,7 +5406,7 @@ genDivOneByte (operand * left,
 
   if (AOP_TYPE(left) == AOP_LIT)
     {
-      signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+      signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit);
 
       if (!lUnsigned && val < 0)
         emitcode ("mov", "a,#0x%02x", -val);
@@ -5470,7 +5492,7 @@ genDiv (iCode * ic)
 
   D (emitcode (";", "genDiv"));
 
-  /* assign the amsops */
+  /* assign the asmops */
   aopOp (left, ic, FALSE);
   aopOp (right, ic, FALSE);
   aopOp (result, ic, TRUE);
@@ -5661,7 +5683,7 @@ genModOneByte (operand * left,
   /* sign adjust left side */
   if (AOP_TYPE(left) == AOP_LIT)
     {
-      signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+      signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit);
 
       if (!lUnsigned && val < 0)
         {
@@ -5854,7 +5876,7 @@ genCmp (operand * left, operand * right,
         {
           if (AOP_TYPE (right) == AOP_LIT)
             {
-              lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+              lit = ulFromVal (AOP (right)->aopu.aop_lit);
               /* optimize if(x < 0) or if(x >= 0) */
               if (lit == 0L)
                 {
@@ -5989,7 +6011,7 @@ genCmpGt (iCode * ic, iCode * ifx)
   retype = getSpec (operandType (right));
   sign = !((SPEC_USIGN (letype) && !(IS_CHAR (letype) && IS_LITERAL (letype))) ||
            (SPEC_USIGN (retype) && !(IS_CHAR (retype) && IS_LITERAL (retype))));
-  /* assign the amsops */
+  /* assign the asmops */
   aopOp (result, ic, TRUE);
   aopOp (left, ic, FALSE);
   aopOp (right, ic, FALSE);
@@ -6019,7 +6041,7 @@ genCmpLt (iCode * ic, iCode * ifx)
   retype = getSpec (operandType (right));
   sign = !((SPEC_USIGN (letype) && !(IS_CHAR (letype) && IS_LITERAL (letype))) ||
            (SPEC_USIGN (retype) && !(IS_CHAR (retype) && IS_LITERAL (retype))));
-  /* assign the amsops */
+  /* assign the asmops */
   aopOp (result, ic, TRUE);
   aopOp (left, ic, FALSE);
   aopOp (right, ic, FALSE);
@@ -6044,8 +6066,9 @@ gencjneshort (operand * left, operand * right, symbol * lbl)
   /* if the left side is a literal or
      if the right is in a pointer register and left
      is not */
-  if ((AOP_TYPE (left) == AOP_LIT) ||
+  if ((AOP_TYPE (left) == AOP_LIT)  ||
       (AOP_TYPE (left) == AOP_IMMD) ||
+      (AOP_TYPE (left) == AOP_DIR)  ||
       (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
     {
       operand *t = right;
@@ -6054,7 +6077,7 @@ gencjneshort (operand * left, operand * right, symbol * lbl)
     }
 
   if (AOP_TYPE (right) == AOP_LIT)
-    lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+    lit = ulFromVal (AOP (right)->aopu.aop_lit);
 
   /* if the right side is a literal then anything goes */
   if (AOP_TYPE (right) == AOP_LIT &&
@@ -6112,7 +6135,7 @@ gencjneshort (operand * left, operand * right, symbol * lbl)
 /* gencjne - compare and jump if not equal                         */
 /*-----------------------------------------------------------------*/
 static void
-gencjne (operand * left, operand * right, symbol * lbl)
+gencjne (operand * left, operand * right, symbol * lbl, bool useCarry)
 {
   symbol *tlbl = newiTempLabel (NULL);
 
@@ -6120,10 +6143,16 @@ gencjne (operand * left, operand * right, symbol * lbl)
 
   gencjneshort (left, right, lbl);
 
-  emitcode ("mov", "a,%s", one);
+  if (useCarry)
+      SETC;
+  else
+      MOVA (one);
   emitcode ("sjmp", "%05d$", tlbl->key + 100);
   emitLabel (lbl);
-  emitcode ("clr", "a");
+  if (useCarry)
+      CLRC;
+  else
+      MOVA (zero);
   emitLabel (tlbl);
 }
 
@@ -6163,7 +6192,7 @@ genCmpEq (iCode * ic, iCode * ifx)
         {
           if (AOP_TYPE (right) == AOP_LIT)
             {
-              unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+              unsigned long lit = ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
               if (lit == 0L)
                 {
                   emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
@@ -6243,7 +6272,7 @@ genCmpEq (iCode * ic, iCode * ifx)
     {
       if (AOP_TYPE (right) == AOP_LIT)
         {
-          unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+          unsigned long lit = ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
           if (lit == 0L)
             {
               emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
@@ -6284,12 +6313,13 @@ genCmpEq (iCode * ic, iCode * ifx)
     }
   else
     {
-      gencjne (left, right, newiTempLabel (NULL));
       if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
         {
-          aopPut (result, "a", 0);
+          gencjne (left, right, newiTempLabel (NULL), TRUE);
+          aopPut (result, "c", 0);
           goto release;
         }
+      gencjne (left, right, newiTempLabel (NULL), FALSE);
       if (ifx)
         {
           genIfxJump (ifx, "a", left, right, result);
@@ -6550,10 +6580,10 @@ genAnd (iCode * ic, iCode * ifx)
   aopOp ((result = IC_RESULT (ic)), ic, TRUE);
 
 #ifdef DEBUG_TYPE
-  emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+  emitcode (";", "Type res[%d] = l[%d]&r[%d]",
             AOP_TYPE (result),
             AOP_TYPE (left), AOP_TYPE (right));
-  emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+  emitcode (";", "Size res[%d] = l[%d]&r[%d]",
             AOP_SIZE (result),
             AOP_SIZE (left), AOP_SIZE (right));
 #endif
@@ -6584,7 +6614,7 @@ genAnd (iCode * ic, iCode * ifx)
       left = tmp;
     }
   if (AOP_TYPE (right) == AOP_LIT)
-    lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+    lit = ulFromVal (AOP (right)->aopu.aop_lit);
 
   size = AOP_SIZE (result);
 
@@ -6623,8 +6653,15 @@ genAnd (iCode * ic, iCode * ifx)
           if (AOP_TYPE (right) == AOP_CRY)
             {
               // c = bit & bit;
-              emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
-              emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+              if (IS_OP_ACCUSE (left))
+                {
+                  emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
+                }
+              else
+                {
+                  emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+                  emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir);
+                }
             }
           else
             {
@@ -6974,10 +7011,10 @@ genOr (iCode * ic, iCode * ifx)
   aopOp ((result = IC_RESULT (ic)), ic, TRUE);
 
 #ifdef DEBUG_TYPE
-  emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+  emitcode (";", "Type res[%d] = l[%d]&r[%d]",
             AOP_TYPE (result),
             AOP_TYPE (left), AOP_TYPE (right));
-  emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+  emitcode (";", "Size res[%d] = l[%d]&r[%d]",
             AOP_SIZE (result),
             AOP_SIZE (left), AOP_SIZE (right));
 #endif
@@ -7008,7 +7045,7 @@ genOr (iCode * ic, iCode * ifx)
       left = tmp;
     }
   if (AOP_TYPE (right) == AOP_LIT)
-    lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+    lit = ulFromVal (AOP (right)->aopu.aop_lit);
 
   size = AOP_SIZE (result);
 
@@ -7045,28 +7082,33 @@ genOr (iCode * ic, iCode * ifx)
           if (AOP_TYPE (right) == AOP_CRY)
             {
               // c = bit | bit;
-              emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
-              emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
+              if (IS_OP_ACCUSE (left))
+                {
+                  emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir);
+                }
+              else
+                {
+                  emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+                  emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
+                }
             }
           else
             {
               // c = bit | val;
-              symbol *tlbl = newiTempLabel (NULL);
-              if (!((AOP_TYPE (result) == AOP_CRY) && ifx))
-                emitcode ("setb", "c");
-              emitcode ("jb", "%s,%05d$",
-                        AOP (left)->aopu.aop_dir, tlbl->key + 100);
-              toBoolean (right);
-              emitcode ("jnz", "%05d$", tlbl->key + 100);
               if ((AOP_TYPE (result) == AOP_CRY) && ifx)
                 {
+                  symbol *tlbl = newiTempLabel (NULL);
+                  emitcode ("jb", "%s,%05d$",
+                            AOP (left)->aopu.aop_dir, tlbl->key + 100);
+                  toBoolean (right);
+                  emitcode ("jnz", "%05d$", tlbl->key + 100);
                   jmpTrueOrFalse (ifx, tlbl, left, right, result);
                   goto release;
                 }
               else
                 {
-                  CLRC;
-                  emitLabel (tlbl);
+                  toCarry (right);
+                  emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir);
                 }
             }
         }
@@ -7351,10 +7393,10 @@ genXor (iCode * ic, iCode * ifx)
   aopOp ((result = IC_RESULT (ic)), ic, TRUE);
 
 #ifdef DEBUG_TYPE
-  emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+  emitcode (";", "Type res[%d] = l[%d]&r[%d]",
             AOP_TYPE (result),
             AOP_TYPE (left), AOP_TYPE (right));
-  emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+  emitcode (";", "Size res[%d] = l[%d]&r[%d]",
             AOP_SIZE (result),
             AOP_SIZE (left), AOP_SIZE (right));
 #endif
@@ -7385,8 +7427,9 @@ genXor (iCode * ic, iCode * ifx)
       right = left;
       left = tmp;
     }
+
   if (AOP_TYPE (right) == AOP_LIT)
-    lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+    lit = ulFromVal (AOP (right)->aopu.aop_lit);
 
   size = AOP_SIZE (result);
 
@@ -7443,25 +7486,21 @@ genXor (iCode * ic, iCode * ifx)
           if (AOP_TYPE (right) == AOP_CRY)
             {
               // c = bit ^ bit;
-              emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+              if (IS_OP_ACCUSE (left))
+                {// left already is in the carry
+                  operand *tmp = right;
+                  right = left;
+                  left = tmp;
+                }
+              else
+                {
+                  toCarry (right);
+                }
             }
           else
             {
-              int sizer = AOP_SIZE (right);
               // c = bit ^ val
-              // if val>>1 != 0, result = 1
-              emitcode ("setb", "c");
-              while (sizer)
-                {
-                  MOVA (aopGet (right, sizer - 1, FALSE, FALSE));
-                  if (sizer == 1)
-                    // test the msb of the lsb
-                    emitcode ("anl", "a,#0xfe");
-                  emitcode ("jnz", "%05d$", tlbl->key + 100);
-                  sizer--;
-                }
-              // val = (0,1)
-              emitcode ("rrc", "a");
+              toCarry (right);
             }
           emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
           emitcode ("cpl", "c");
@@ -7471,7 +7510,7 @@ genXor (iCode * ic, iCode * ifx)
       // val = c
       if (size)
         outBitC (result);
-      // if(bit | ...)
+      // if(bit ^ ...)
       else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
         genIfxJump (ifx, "c", left, right, result);
       goto release;
@@ -7689,40 +7728,51 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   D (emitcode (";", "genInline"));
 
   _G.inLine += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_strdup(IC_INLINE(ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
 
   /* emit each line as a code */
   while (*bp)
     {
-      if (*bp == '\n')
+      switch (*bp)
         {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
           *bp++ = '\0';
           emitcode (bp1, "");
           bp1 = bp;
-        }
-      else
-        {
+          break;
+
+        default:
           /* Add \n for labels, not dirs such as c:\mydir */
-          if ( (*bp == ':') && (isspace((unsigned char)bp[1])) )
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
             {
-              bp++;
+              ++bp;
               *bp = '\0';
-              bp++;
+              ++bp;
               emitcode (bp1, "");
               bp1 = bp;
             }
           else
-            bp++;
+            ++bp;
+          break;
         }
     }
   if (bp1 != bp)
     emitcode (bp1, "");
-  /*     emitcode("",buffer); */
+
+  Safe_free (buffer);
+
   _G.inLine -= (!options.asmpeep);
 }
 
@@ -7885,7 +7935,7 @@ genGetAbit (iCode * ic)
   aopOp (right, ic, FALSE);
   aopOp (result, ic, FALSE);
 
-  shCount = (int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+  shCount = (int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
 
   /* get the needed byte into a */
   MOVA (aopGet (left, shCount / 8, FALSE, FALSE));
@@ -7957,7 +8007,7 @@ genGetByte (iCode * ic)
   aopOp (right, ic, FALSE);
   aopOp (result, ic, FALSE);
 
-  offset = (int)floatFromVal (AOP (right)->aopu.aop_lit) / 8;
+  offset = (int) ulFromVal (AOP (right)->aopu.aop_lit) / 8;
   aopPut (result,
           aopGet (left, offset, FALSE, FALSE),
           0);
@@ -7985,7 +8035,7 @@ genGetWord (iCode * ic)
   aopOp (right, ic, FALSE);
   aopOp (result, ic, FALSE);
 
-  offset = (int)floatFromVal (AOP (right)->aopu.aop_lit) / 8;
+  offset = (int) ulFromVal (AOP (right)->aopu.aop_lit) / 8;
   aopPut (result,
           aopGet (left, offset, FALSE, FALSE),
           0);
@@ -8006,7 +8056,7 @@ genSwap (iCode * ic)
 {
   operand *left, *result;
 
-  D(emitcode (";     genSwap",""));
+  D(emitcode (";", "genSwap"));
 
   left = IC_LEFT (ic);
   result = IC_RESULT (ic);
@@ -8922,7 +8972,7 @@ genLeftShiftLiteral (operand * left,
                      operand * result,
                      iCode * ic)
 {
-  int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+  int shCount = (int) ulFromVal (AOP (right)->aopu.aop_lit);
   int size;
 
   D (emitcode (";", "genLeftShiftLiteral"));
@@ -9314,7 +9364,7 @@ genRightShiftLiteral (operand * left,
                       iCode * ic,
                       int sign)
 {
-  int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+  int shCount = (int) ulFromVal (AOP (right)->aopu.aop_lit);
   int size;
 
   D (emitcode (";", "genRightShiftLiteral"));
@@ -9696,7 +9746,7 @@ emitPtrByteSet (char *rname, int p_type, char *src)
 /*-----------------------------------------------------------------*/
 /* genUnpackBits - generates code for unpacking bits               */
 /*-----------------------------------------------------------------*/
-static void
+static char*
 genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx)
 {
   int offset = 0;       /* result byte offset */
@@ -9705,9 +9755,10 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx)
   sym_link *etype;      /* bitfield type information */
   int blen;             /* bitfield length */
   int bstr;             /* bitfield starting bit within byte */
-  char buffer[10];
+  static char* const accBits[] = {"acc.0", "acc.1", "acc.2", "acc.3",
+                                  "acc.4", "acc.5", "acc.6", "acc.7"};
 
-  D(emitcode (";     genUnpackBits",""));
+  D(emitcode (";", "genUnpackBits"));
 
   etype = getSpec (operandType (result));
   rsize = getSize (operandType (result));
@@ -9719,18 +9770,15 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx)
       emitPtrByteGet (rname, ptype, FALSE);
       if (blen == 1)
         {
-          SNPRINTF (buffer, sizeof(buffer),
-                    "acc.%d", bstr);
-          genIfxJump (ifx, buffer, NULL, NULL, NULL);
+          return accBits[bstr];;
         }
       else
         {
           if (blen < 8)
             emitcode ("anl", "a,#0x%02x",
                       (((unsigned char) -1) >> (8 - blen)) << bstr);
-          genIfxJump (ifx, "a", NULL, NULL, NULL);
+          return "a";
         }
-      return;
     }
   wassert (!ifx);
 
@@ -9799,6 +9847,7 @@ finish:
       while (rsize--)
         aopPut (result, source, offset++);
     }
+  return NULL;
 }
 
 
@@ -9852,9 +9901,9 @@ genNearPointerGet (operand * left,
   asmop *aop = NULL;
   regs *preg = NULL;
   char *rname;
+  char *ifxCond = "a";
   sym_link *rtype, *retype;
   sym_link *ltype = operandType (left);
-  char buffer[80];
 
   D (emitcode (";", "genNearPointerGet"));
 
@@ -9875,6 +9924,9 @@ genNearPointerGet (operand * left,
       return;
     }
 
+  //aopOp (result, ic, FALSE);
+  aopOp (result, ic, result?TRUE:FALSE);
+
  /* if the value is already in a pointer register
      then don't need anything more */
   if (!AOP_INPREG (AOP (left)))
@@ -9909,12 +9961,9 @@ genNearPointerGet (operand * left,
   else
     rname = aopGet (left, 0, FALSE, FALSE);
 
-  //aopOp (result, ic, FALSE);
-  aopOp (result, ic, result?TRUE:FALSE);
-
   /* if bitfield then unpack the bits */
   if (IS_BITFIELD (retype))
-    genUnpackBits (result, rname, POINTER, ifx);
+    ifxCond = genUnpackBits (result, rname, POINTER, ifx);
   else
     {
       /* we have can just get the values */
@@ -9932,6 +9981,8 @@ genNearPointerGet (operand * left,
             }
           else
             {
+              char buffer[80];
+
               SNPRINTF (buffer, sizeof(buffer), "@%s", rname);
               aopPut (result, buffer, offset);
             }
@@ -9970,7 +10021,7 @@ genNearPointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   /* done */
@@ -9992,6 +10043,7 @@ genPagedPointerGet (operand * left,
   asmop *aop = NULL;
   regs *preg = NULL;
   char *rname;
+  char *ifxCond = "a";
   sym_link *rtype, *retype;
 
   D (emitcode (";", "genPagedPointerGet"));
@@ -10001,6 +10053,8 @@ genPagedPointerGet (operand * left,
 
   aopOp (left, ic, FALSE);
 
+  aopOp (result, ic, FALSE);
+
   /* if the value is already in a pointer register
      then don't need anything more */
   if (!AOP_INPREG (AOP (left)))
@@ -10016,11 +10070,9 @@ genPagedPointerGet (operand * left,
   else
     rname = aopGet (left, 0, FALSE, FALSE);
 
-  aopOp (result, ic, FALSE);
-
   /* if bitfield then unpack the bits */
   if (IS_BITFIELD (retype))
-    genUnpackBits (result, rname, PPOINTER, ifx);
+    ifxCond = genUnpackBits (result, rname, PPOINTER, ifx);
   else
     {
       /* we have can just get the values */
@@ -10069,7 +10121,7 @@ genPagedPointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   /* done */
@@ -10097,7 +10149,7 @@ loadDptrFromOperand (operand *op, bool loadBToo)
               else
                 {
                   wassertl(FALSE, "need pointerCode");
-                  emitcode ("", "; mov b,???");
+                  emitcode (";", "mov b,???");
                   /* genPointerGet and genPointerSet originally did different
                   ** things for this case. Both seem wrong.
                   ** from genPointerGet:
@@ -10146,6 +10198,7 @@ genFarPointerGet (operand * left,
                   operand * result, iCode * ic, iCode * pi, iCode * ifx)
 {
   int size, offset;
+  char *ifxCond = "a";
   sym_link *retype = getSpec (operandType (result));
 
   D (emitcode (";", "genFarPointerGet"));
@@ -10158,7 +10211,7 @@ genFarPointerGet (operand * left,
 
   /* if bit then unpack */
   if (IS_BITFIELD (retype))
-    genUnpackBits (result, "dptr", FPOINTER, ifx);
+    ifxCond = genUnpackBits (result, "dptr", FPOINTER, ifx);
   else
     {
       size = AOP_SIZE (result);
@@ -10183,7 +10236,7 @@ genFarPointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   freeAsmop (result, NULL, ic, TRUE);
@@ -10198,6 +10251,7 @@ genCodePointerGet (operand * left,
                     operand * result, iCode * ic, iCode *pi, iCode *ifx)
 {
   int size, offset;
+  char *ifxCond = "a";
   sym_link *retype = getSpec (operandType (result));
 
   D (emitcode (";", "genCodePointerGet"));
@@ -10210,7 +10264,7 @@ genCodePointerGet (operand * left,
 
   /* if bit then unpack */
   if (IS_BITFIELD (retype))
-    genUnpackBits (result, "dptr", CPOINTER, ifx);
+    ifxCond = genUnpackBits (result, "dptr", CPOINTER, ifx);
   else
     {
       size = AOP_SIZE (result);
@@ -10236,7 +10290,7 @@ genCodePointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   freeAsmop (result, NULL, ic, TRUE);
@@ -10251,6 +10305,7 @@ genGenPointerGet (operand * left,
                   operand * result, iCode * ic, iCode *pi, iCode *ifx)
 {
   int size, offset;
+  char *ifxCond = "a";
   sym_link *retype = getSpec (operandType (result));
 
   D (emitcode (";", "genGenPointerGet"));
@@ -10264,7 +10319,7 @@ genGenPointerGet (operand * left,
   /* if bit then unpack */
   if (IS_BITFIELD (retype))
     {
-      genUnpackBits (result, "dptr", GPOINTER, ifx);
+      ifxCond = genUnpackBits (result, "dptr", GPOINTER, ifx);
     }
   else
     {
@@ -10290,7 +10345,7 @@ genGenPointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   freeAsmop (result, NULL, ic, TRUE);
@@ -10321,7 +10376,9 @@ genPointerGet (iCode * ic, iCode *pi, iCode *ifx)
   etype = getSpec (type);
   /* if left is of type of pointer then it is simple */
   if (IS_PTR (type) && !IS_FUNC (type->next))
-    p_type = DCL_TYPE (type);
+    {
+      p_type = DCL_TYPE (type);
+    }
   else
     {
       /* we have to go by the storage class */
@@ -10380,7 +10437,7 @@ genPackBits (sym_link * etype,
   int litval;           /* source literal value (if AOP_LIT) */
   unsigned char mask;   /* bitmask within current byte */
 
-  D(emitcode (";     genPackBits",""));
+  D(emitcode (";", "genPackBits"));
 
   blen = SPEC_BLEN (etype);
   bstr = SPEC_BSTR (etype);
@@ -10395,7 +10452,7 @@ genPackBits (sym_link * etype,
         {
           /* Case with a bitfield length <8 and literal source
           */
-          litval = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+          litval = (int) ulFromVal (AOP (right)->aopu.aop_lit);
           litval <<= bstr;
           litval &= (~mask) & 0xff;
           emitPtrByteGet (rname, p_type, FALSE);
@@ -10466,7 +10523,7 @@ genPackBits (sym_link * etype,
         {
           /* Case with partial byte and literal source
           */
-          litval = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+          litval = (int) ulFromVal (AOP (right)->aopu.aop_lit);
           litval >>= (blen-rlen);
           litval &= (~mask) & 0xff;
           emitPtrByteGet (rname, p_type, FALSE);
@@ -10516,7 +10573,7 @@ genDataPointerSet (operand * right,
 
   l = aopGet (result, 0, FALSE, TRUE);
   l++; //remove #
-  size = AOP_SIZE (right);
+  size = max (AOP_SIZE (right), AOP_SIZE (result));
   while (size--)
     {
       if (offset)
@@ -10527,12 +10584,12 @@ genDataPointerSet (operand * right,
                 aopGet (right, offset++, FALSE, FALSE));
     }
 
-  freeAsmop (result, NULL, ic, TRUE);
   freeAsmop (right, NULL, ic, TRUE);
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
-/* genNearPointerSet - emitcode for near pointer put                */
+/* genNearPointerSet - emitcode for near pointer put               */
 /*-----------------------------------------------------------------*/
 static void
 genNearPointerSet (operand * right,
@@ -10568,39 +10625,36 @@ genNearPointerSet (operand * right,
      then don't need anything more */
   if (!AOP_INPREG (AOP (result)))
     {
-        if (
-            //AOP_TYPE (result) == AOP_STK
-            IS_AOP_PREG(result)
-            )
+      if (IS_AOP_PREG (result))
         {
-            // Aha, it is a pointer, just in disguise.
-            rname = aopGet (result, 0, FALSE, FALSE);
-            if (*rname != '@')
+          // Aha, it is a pointer, just in disguise.
+          rname = aopGet (result, 0, FALSE, FALSE);
+          if (*rname != '@')
             {
-                fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n",
-                        __FILE__, __LINE__);
+              fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n",
+                      __FILE__, __LINE__);
             }
-            else
+          else
             {
-                // Expected case.
-                emitcode ("mov", "a%s,%s", rname + 1, rname);
-                rname++;  // skip the '@'.
+              // Expected case.
+              emitcode ("mov", "a%s,%s", rname + 1, rname);
+              rname++;  // skip the '@'.
             }
         }
-        else
+      else
         {
-            /* otherwise get a free pointer register */
-            aop = newAsmop (0);
-            preg = getFreePtr (ic, &aop, FALSE);
-            emitcode ("mov", "%s,%s",
-                      preg->name,
-                      aopGet (result, 0, FALSE, TRUE));
-            rname = preg->name;
+          /* otherwise get a free pointer register */
+          aop = newAsmop (0);
+          preg = getFreePtr (ic, &aop, FALSE);
+          emitcode ("mov", "%s,%s",
+                    preg->name,
+                    aopGet (result, 0, FALSE, TRUE));
+          rname = preg->name;
         }
     }
-    else
+  else
     {
-        rname = aopGet (result, 0, FALSE, FALSE);
+      rname = aopGet (result, 0, FALSE, FALSE);
     }
 
   aopOp (right, ic, FALSE);
@@ -10657,9 +10711,10 @@ genNearPointerSet (operand * right,
     }
 
   /* done */
-  if (pi) pi->generated = 1;
-  freeAsmop (result, NULL, ic, TRUE);
+  if (pi)
+    pi->generated = 1;
   freeAsmop (right, NULL, ic, TRUE);
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -10687,16 +10742,37 @@ genPagedPointerSet (operand * right,
      then don't need anything more */
   if (!AOP_INPREG (AOP (result)))
     {
-      /* otherwise get a free pointer register */
-      aop = newAsmop (0);
-      preg = getFreePtr (ic, &aop, FALSE);
-      emitcode ("mov", "%s,%s",
-                preg->name,
-                aopGet (result, 0, FALSE, TRUE));
-      rname = preg->name;
+      if (IS_AOP_PREG (result))
+        {
+          // Aha, it is a pointer, just in disguise.
+          rname = aopGet (result, 0, FALSE, FALSE);
+          if (*rname != '@')
+            {
+              fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n",
+                      __FILE__, __LINE__);
+            }
+          else
+            {
+              // Expected case.
+              emitcode ("mov", "a%s,%s", rname + 1, rname);
+              rname++;  // skip the '@'.
+            }
+        }
+      else
+        {
+          /* otherwise get a free pointer register */
+          aop = newAsmop (0);
+          preg = getFreePtr (ic, &aop, FALSE);
+          emitcode ("mov", "%s,%s",
+                    preg->name,
+                    aopGet (result, 0, FALSE, TRUE));
+          rname = preg->name;
+        }
     }
   else
-    rname = aopGet (result, 0, FALSE, FALSE);
+    {
+      rname = aopGet (result, 0, FALSE, FALSE);
+    }
 
   aopOp (right, ic, FALSE);
 
@@ -10705,7 +10781,7 @@ genPagedPointerSet (operand * right,
     genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, rname, PPOINTER);
   else
     {
-      /* we have can just get the values */
+      /* we can just get the values */
       int size = AOP_SIZE (right);
       int offset = 0;
 
@@ -10714,10 +10790,8 @@ genPagedPointerSet (operand * right,
           l = aopGet (right, offset, FALSE, TRUE);
           MOVA (l);
           emitcode ("movx", "@%s,a", rname);
-
           if (size || pi)
             emitcode ("inc", "%s", rname);
-
           offset++;
         }
     }
@@ -10738,8 +10812,8 @@ genPagedPointerSet (operand * right,
          belongs */
       if (AOP_SIZE (right) > 1 &&
           !OP_SYMBOL (result)->remat &&
-          (OP_SYMBOL (result)->liveTo > ic->seq ||
-           ic->depth))
+          (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth) &&
+          !pi)
         {
           int size = AOP_SIZE (right) - 1;
           while (size--)
@@ -10748,9 +10822,10 @@ genPagedPointerSet (operand * right,
     }
 
   /* done */
-  if (pi) pi->generated = 1;
-  freeAsmop (result, NULL, ic, TRUE);
+  if (pi)
+    pi->generated = 1;
   freeAsmop (right, NULL, ic, TRUE);
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -10764,7 +10839,7 @@ genFarPointerSet (operand * right,
   sym_link *retype = getSpec (operandType (right));
   sym_link *letype = getSpec (operandType (result));
 
-  D(emitcode (";     genFarPointerSet",""));
+  D(emitcode (";", "genFarPointerSet"));
 
   aopOp (result, ic, FALSE);
   loadDptrFromOperand (result, FALSE);
@@ -11120,7 +11195,7 @@ genAssign (iCode * ic)
   size = AOP_SIZE (result);
   offset = 0;
   if (AOP_TYPE (right) == AOP_LIT)
-    lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+    lit = ulFromVal (AOP (right)->aopu.aop_lit);
 
   if ((size > 1) &&
       (AOP_TYPE (result) != AOP_REG) &&
@@ -11596,7 +11671,10 @@ genReceive (iCode * ic)
     }
   else if (ic->argreg > 12)
     { /* bit parameters */
-      if (OP_SYMBOL (IC_RESULT (ic))->regs[0]->rIdx != ic->argreg-5)
+      regs *reg = OP_SYMBOL (IC_RESULT (ic))->regs[0];
+
+      BitBankUsed = 1;
+      if (!reg || reg->rIdx != ic->argreg-5)
         {
           aopOp (IC_RESULT (ic), ic, FALSE);
           emitcode ("mov", "c,%s", rb1regs[ic->argreg-5]);
@@ -11713,7 +11791,7 @@ genCritical (iCode *ic)
 static void
 genEndCritical (iCode *ic)
 {
-  D(emitcode(";     genEndCritical",""));
+  D(emitcode(";", "genEndCritical"));
 
   if (IC_RIGHT (ic))
     {
@@ -11778,7 +11856,7 @@ gen51Code (iCode * lic)
               debugFile->writeCLine (ic);
             }
           if (!options.noCcodeInAsm) {
-            emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno,
+            emitcode (";", "%s:%d: %s", ic->filename, ic->lineno,
                       printCLine(ic->filename, ic->lineno));
           }
           cln = ic->lineno;
@@ -11786,14 +11864,14 @@ gen51Code (iCode * lic)
       #if 0
       if (ic->seqPoint && ic->seqPoint != cseq)
         {
-          emitcode ("", "; sequence point %d", ic->seqPoint);
+          emitcode (";", "sequence point %d", ic->seqPoint);
           cseq = ic->seqPoint;
         }
       #endif
       if (options.iCodeInAsm) {
         char regsInUse[80];
         int i;
-        char *iLine;
+        const char *iLine;
 
         #if 0
         for (i=0; i<8; i++) {
@@ -11811,7 +11889,7 @@ gen51Code (iCode * lic)
         #endif
         }
         iLine = printILine(ic);
-        emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+        emitcode(";", "[%s] ic:%d: %s", regsInUse, ic->seq, iLine);
         dbuf_free(iLine);
       }
       /* if the result is marked as