* src/ds390/gen.c (pushSide, genPcall),
[fw/sdcc] / src / mcs51 / gen.c
index a36937f2b817765617bed83f1104f2b910f8858e..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>
@@ -181,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);
@@ -542,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);
@@ -553,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);
@@ -564,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);
@@ -572,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);
@@ -711,7 +712,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
 }
 
 /*-----------------------------------------------------------------*/
-/* aopForRemat - rematerialzes an object                           */
+/* aopForRemat - rematerializes an object                          */
 /*-----------------------------------------------------------------*/
 static asmop *
 aopForRemat (symbol * sym)
@@ -727,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;
     }
@@ -968,7 +971,7 @@ 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;
         }
 
@@ -1003,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 */
@@ -1039,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)
 {
@@ -1491,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))
     {
@@ -1666,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:
@@ -1838,10 +1853,10 @@ outBitC (operand * result)
   /* if the result is bit */
   if (AOP_TYPE (result) == AOP_CRY)
     {
-      if (!OP_SYMBOL (result)->ruonly)
+      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));
         }
@@ -2404,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);
@@ -2422,6 +2457,8 @@ pushSide (operand * oper, int size)
           emitcode ("push", "%s", l);
         }
     }
+
+  freeAsmop (oper, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2669,9 +2706,9 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
     }
 
   if (ic)
-  {
-    ic->bankSaved = 1;
-  }
+    {
+      ic->bankSaved = 1;
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -3131,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);
+          /* now push the function address */
+          pushSide (IC_LEFT (ic), FPTRSIZE, ic);
 
-          freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
-
-          /* if send set is not empty the assign */
+          /* if send set is not empty then assign */
           if (_G.sendSet)
             {
               genSend(reverseSet(_G.sendSet));
@@ -3405,7 +3438,7 @@ genFunction (iCode * ic)
                 }
             }
         }
-        else
+      else
         {
             /* This ISR uses a non-zero bank.
              *
@@ -3590,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"))
@@ -3615,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]);
@@ -4039,7 +4072,7 @@ genRet (iCode * ic)
 
   if (IS_BIT(_G.currentFunc->etype))
     {
-      if (!OP_SYMBOL (IC_LEFT (ic))->ruonly)
+      if (!IS_OP_RUONLY (IC_LEFT (ic)))
         toCarry (IC_LEFT (ic));
     }
   else
@@ -4152,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))) &&
@@ -4477,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));
         }
@@ -4514,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);
@@ -4537,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--)
@@ -4620,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))) &&
@@ -4844,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--)
@@ -5044,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;
         }
@@ -5058,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;
         }
@@ -5079,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);
@@ -5105,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);
@@ -5214,7 +5247,7 @@ genDivbits (operand * left,
   char *l;
   bool pushedB;
 
-  D(emitcode (";     genDivbits",""));
+  D(emitcode (";", "genDivbits"));
 
   pushedB = pushB ();
 
@@ -5247,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:
@@ -5312,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;
         }
@@ -5326,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;
         }
@@ -5347,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);
@@ -5373,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);
@@ -5459,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);
@@ -5650,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)
         {
@@ -5843,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)
                 {
@@ -5978,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);
@@ -6008,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);
@@ -6033,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;
@@ -6043,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 &&
@@ -6101,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);
 
@@ -6109,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);
 }
 
@@ -6152,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);
@@ -6232,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);
@@ -6273,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);
@@ -6539,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
@@ -6573,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);
 
@@ -6612,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
             {
@@ -6963,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
@@ -6997,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);
 
@@ -7034,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);
                 }
             }
         }
@@ -7340,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
@@ -7374,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);
 
@@ -7432,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");
@@ -7678,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);
 }
 
@@ -7874,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));
@@ -7946,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);
@@ -7974,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);
@@ -7995,7 +8056,7 @@ genSwap (iCode * ic)
 {
   operand *left, *result;
 
-  D(emitcode (";     genSwap",""));
+  D(emitcode (";", "genSwap"));
 
   left = IC_LEFT (ic);
   result = IC_RESULT (ic);
@@ -8911,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"));
@@ -9303,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"));
@@ -9685,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 */
@@ -9694,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));
@@ -9708,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);
 
@@ -9788,6 +9847,7 @@ finish:
       while (rsize--)
         aopPut (result, source, offset++);
     }
+  return NULL;
 }
 
 
@@ -9841,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"));
 
@@ -9864,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)))
@@ -9898,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 */
@@ -9921,6 +9981,8 @@ genNearPointerGet (operand * left,
             }
           else
             {
+              char buffer[80];
+
               SNPRINTF (buffer, sizeof(buffer), "@%s", rname);
               aopPut (result, buffer, offset);
             }
@@ -9959,7 +10021,7 @@ genNearPointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   /* done */
@@ -9981,6 +10043,7 @@ genPagedPointerGet (operand * left,
   asmop *aop = NULL;
   regs *preg = NULL;
   char *rname;
+  char *ifxCond = "a";
   sym_link *rtype, *retype;
 
   D (emitcode (";", "genPagedPointerGet"));
@@ -9990,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)))
@@ -10005,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 */
@@ -10058,7 +10121,7 @@ genPagedPointerGet (operand * left,
 
   if (ifx && !ifx->generated)
     {
-      genIfxJump (ifx, "a", left, NULL, result);
+      genIfxJump (ifx, ifxCond, left, NULL, result);
     }
 
   /* done */
@@ -10086,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:
@@ -10135,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"));
@@ -10147,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);
@@ -10172,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);
@@ -10187,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"));
@@ -10199,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);
@@ -10225,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);
@@ -10240,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"));
@@ -10253,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
     {
@@ -10279,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);
@@ -10310,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 */
@@ -10369,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);
@@ -10384,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);
@@ -10455,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);
@@ -10505,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)
@@ -10516,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,
@@ -10557,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);
@@ -10646,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);
 }
 
 /*-----------------------------------------------------------------*/
@@ -10676,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);
 
@@ -10694,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;
 
@@ -10703,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++;
         }
     }
@@ -10727,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--)
@@ -10737,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);
 }
 
 /*-----------------------------------------------------------------*/
@@ -10753,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);
@@ -11109,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) &&
@@ -11585,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]);
@@ -11702,7 +11791,7 @@ genCritical (iCode *ic)
 static void
 genEndCritical (iCode *ic)
 {
-  D(emitcode(";     genEndCritical",""));
+  D(emitcode(";", "genEndCritical"));
 
   if (IC_RIGHT (ic))
     {
@@ -11767,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;
@@ -11775,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++) {
@@ -11800,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