* support/regression/Makefile.in,
[fw/sdcc] / src / ds390 / gen.c
index 28173930dd2e711c31564ade58cf9f9bd4ed8d46..74e31a5cb440ab3ad94bb844282fd6254975f78d 100644 (file)
@@ -26,7 +26,7 @@
 -------------------------------------------------------------------------*/
 
 //#define D(x)
-#define D(x) x
+#define D(x) do if (options.verboseAsm) {x;} while(0)
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include "SDCCglobl.h"
 #include "newalloc.h"
+#include "dbuf_string.h"
 
 #include "common.h"
 #include "main.h"
@@ -75,7 +76,7 @@ static short rbank = -1;
 #define AOP_TYPE(op) AOP(op)->type
 #define AOP_SIZE(op) AOP(op)->size
 #define IS_AOP_PREG(x) (AOP(x) && (AOP_TYPE(x) == AOP_R1 || \
-                       AOP_TYPE(x) == AOP_R0))
+                        AOP_TYPE(x) == AOP_R0))
 
 #define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY ||  \
                          AOP_TYPE(x) == AOP_DPTR || AOP_TYPE(x) == AOP_DPTR2 || \
@@ -165,8 +166,8 @@ static void saveRBank (int, iCode *, bool);
 #define MOVA(x)  mova(x)  /* use function to avoid multiple eval */
 #define MOVB(x)  movb(x)
 
-#define CLRC    emitcode("clr","c")
-#define SETC    emitcode("setb","c")
+#define CLRC     emitcode("clr","c")
+#define SETC     emitcode("setb","c")
 
 // A scratch register which will be used to hold
 // result bytes from operands in far space via DPTR2.
@@ -191,7 +192,7 @@ static unsigned char SRMask[] =
                                 emitcode ("setb","F1");                         \
                                 emitcode ("jbc","EA,!tlabel",lbl->key+100);     \
                                 emitcode ("clr","F1");                          \
-                                emitcode ("","!tlabeldef",lbl->key+100);        \
+                                emitLabel (lbl);                                \
                         }}
 #define UNPROTECT_SP    { if (options.protect_sp_update) {                      \
                                 emitcode ("mov","EA,F1");                       \
@@ -205,49 +206,61 @@ static int _lazyDPS = 0;        /* if non-zero, we are doing lazy evaluation of
 /* emitcode - writes the code into a file : for now it is simple    */
 /*-----------------------------------------------------------------*/
 static void
-emitcode (char *inst, const char *fmt,...)
+emitcode (const char *inst, const char *fmt,...)
 {
   va_list ap;
-  char lb[INITIAL_INLINEASM];
-  char *lbp = lb;
+  struct dbuf_s dbuf;
+  const char *lbp, *lb;
+
+  dbuf_init (&dbuf, INITIAL_INLINEASM);
 
   va_start (ap, fmt);
 
   if (inst && *inst)
     {
+      dbuf_append_str (&dbuf, inst);
+
       if (fmt && *fmt)
         {
-          SNPRINTF (lb, sizeof(lb), "%s\t", inst);
-        }
-      else
-        {
-          SNPRINTF (lb, sizeof(lb), "%s", inst);
+          dbuf_append_char (&dbuf, '\t');
+          dbuf_tvprintf (&dbuf, fmt, ap);
         }
-
-      tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap);
     }
   else
     {
-      tvsprintf (lb, sizeof(lb), fmt, ap);
+      dbuf_tvprintf (&dbuf, fmt, ap);
     }
 
+  lbp = lb = dbuf_c_str(&dbuf);
+
   while (isspace ((unsigned char)*lbp))
     {
       lbp++;
     }
 
-  if (lbp && *lbp)
+  if (lbp)
     {
       lineCurr = (lineCurr ?
                   connectLine (lineCurr, newLineNode (lb)) :
                   (lineHead = newLineNode (lb)));
+
+      lineCurr->isInline = _G.inLine;
+      lineCurr->isDebug = _G.debugLine;
+      lineCurr->ic = _G.current_iCode;
+      lineCurr->aln = ds390newAsmLineNode(_currentDPS);
+      lineCurr->isComment = (*lbp == ';');
     }
 
-  lineCurr->isInline = _G.inLine;
-  lineCurr->isDebug = _G.debugLine;
-  lineCurr->ic = _G.current_iCode;
-  lineCurr->aln = ds390newAsmLineNode(_currentDPS);
   va_end (ap);
+
+  dbuf_destroy(&dbuf);
+}
+
+static void
+emitLabel (symbol *tlbl)
+{
+  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  lineCurr->isLabel = 1;
 }
 
 /*-----------------------------------------------------------------*/
@@ -476,7 +489,7 @@ endOfWorld:
 /*-----------------------------------------------------------------*/
 /* genSetDPTR: generate code to select which DPTR is in use (zero  */
 /* selects standard DPTR (DPL/DPH/DPX), non-zero selects DS390     */
-/* alternate DPTR (DPL1/DPH1/DPX1).          */
+/* alternate DPTR (DPL1/DPH1/DPX1).                                */
 /*-----------------------------------------------------------------*/
 static void
 genSetDPTR (int n)
@@ -560,9 +573,9 @@ _flushLazyDPS (void)
 }
 
 /*-----------------------------------------------------------------*/
-/* _endLazyDPSEvaluation: end lazy DPS evaluation block.     */
-/*                   */
-/* Forces us back to the safe state (standard DPTR selected).    */
+/* _endLazyDPSEvaluation: end lazy DPS evaluation block.           */
+/*                                                                 */
+/* Forces us back to the safe state (standard DPTR selected).      */
 /*-----------------------------------------------------------------*/
 static void
 _endLazyDPSEvaluation (void)
@@ -631,7 +644,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);
@@ -642,7 +655,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);
@@ -653,7 +666,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);
@@ -661,7 +674,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);
@@ -722,9 +735,9 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
         {
           if (sym->onStack)
             {
-              char offset = ((sym->stack < 0) ?
-                         ((char) (sym->stack - _G.nRegsSaved)) :
-                         ((char) sym->stack)) & 0xff;
+              signed char offset = ((sym->stack < 0) ?
+                         ((signed char) (sym->stack - _G.nRegsSaved)) :
+                         ((signed char) sym->stack)) & 0xff;
 
               if ((abs(offset) <= 3) ||
                   (accuse && (abs(offset) <= 7)))
@@ -768,14 +781,14 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
 
   if (sym->onStack && options.stack10bit)
     {
-        short stack_val = -((sym->stack < 0) ?
-                            ((short) (sym->stack - _G.nRegsSaved)) :
-                            ((short) sym->stack)) ;
-        if (_G.dptrInUse ) {
-            emitcode ("push",dpl);
-            emitcode ("push",dph);
-            emitcode ("push",dpx);
-        }
+      short stack_val = -((sym->stack < 0) ?
+                          ((short) (sym->stack - _G.nRegsSaved)) :
+                          ((short) sym->stack)) ;
+      if (_G.dptrInUse ) {
+          emitcode ("push",dpl);
+          emitcode ("push",dph);
+          emitcode ("push",dpx);
+      }
       /* It's on the 10 bit stack, which is located in
        * far data space.
        */
@@ -783,8 +796,8 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
         { /* between -5 & -1 */
           if (options.model == MODEL_FLAT24)
             {
-                emitcode ("mov", "%s,#!constbyte", dpx,
-                          (options.stack_loc >> 16) & 0xff);
+              emitcode ("mov", "%s,#!constbyte", dpx,
+                        (options.stack_loc >> 16) & 0xff);
             }
           emitcode ("mov", "%s,_bpx+1", dph);
           emitcode ("mov", "%s,_bpx", dpl);
@@ -875,7 +888,7 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
 }
 
 /*-----------------------------------------------------------------*/
-/* aopForRemat - rematerialzes an object                           */
+/* aopForRemat - rematerializes an object                          */
 /*-----------------------------------------------------------------*/
 static asmop *
 aopForRemat (symbol * sym)
@@ -891,45 +904,47 @@ 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;
     }
 
   if (val)
-  {
+    {
       SNPRINTF (buffer, sizeof(buffer),
                 "(%s %c 0x%06x)",
                 OP_SYMBOL (IC_LEFT (ic))->rname,
                 val >= 0 ? '+' : '-',
                 abs (val) & 0xffffff);
-  }
+    }
   else
-  {
+    {
       if (IS_ASSIGN_ICODE(ic) && isOperandLiteral(IC_RIGHT(ic)))
-      {
+        {
           SNPRINTF(buffer, sizeof(buffer),
                    "0x%x",(int) operandLitValue (IC_RIGHT (ic)));
-      }
+        }
       else
-      {
+        {
           strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer));
-      }
-  }
+        }
+    }
 
   aop->aopu.aop_immd.aop_immd1 = Safe_strdup(buffer);
   /* set immd2 field if required */
   if (aop->aopu.aop_immd.from_cast_remat)
-  {
+    {
       tsprintf(buffer, sizeof(buffer), "#!constbyte",ptr_type);
       aop->aopu.aop_immd.aop_immd2 = Safe_strdup(buffer);
-  }
+    }
 
   return aop;
 }
@@ -1161,8 +1176,7 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2)
       /* rematerialize it NOW */
       if (sym->remat)
         {
-          sym->aop = op->aop = aop =
-            aopForRemat (sym);
+          sym->aop = op->aop = aop = aopForRemat (sym);
           aop->size = getSize (sym->type);
           return;
         }
@@ -1205,13 +1219,21 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2)
 
       if (sym->usl.spillLoc)
         {
+          asmop *oldAsmOp = NULL;
+
           if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
             {
               /* force a new aop if sizes differ */
+              oldAsmOp = sym->usl.spillLoc->aop;
               sym->usl.spillLoc->aop = NULL;
             }
           sym->aop = op->aop = aop =
                      aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+          if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+            {
+              /* Don't reuse the new aop, go with the last one */
+              sym->usl.spillLoc->aop = oldAsmOp;
+            }
           aop->size = getSize (sym->type);
           return;
         }
@@ -1241,7 +1263,7 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2)
 
 /*-----------------------------------------------------------------*/
 /* freeAsmop - free up the asmop given to an operand               */
-/*----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
 static void
 freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
 {
@@ -1394,6 +1416,8 @@ aopGetUsesAcc (operand * oper, int offset)
         return TRUE;
       return FALSE;
     case AOP_DPTR:
+    case AOP_DPTR2:
+    case AOP_DPTRn:
       return TRUE;
     case AOP_IMMD:
       return FALSE;
@@ -1530,32 +1554,32 @@ aopGet (operand * oper,
           genSetDPTR (0);
         }
 
-        if (saveAcc)
+      if (saveAcc)
         {
-       TR_AP("#2");
-              emitcode ("xch", "a, %s", saveAcc);
-//            if (strcmp(saveAcc, "_ap"))
-//            {
-//                emitcode(";", "spiffy: non _ap return from aopGet.");
-//            }
+          TR_AP("#2");
+          emitcode ("xch", "a, %s", saveAcc);
+//        if (strcmp(saveAcc, "_ap"))
+//          {
+//            emitcode(";", "spiffy: non _ap return from aopGet.");
+//          }
 
-              return saveAcc;
+          return saveAcc;
         }
       return (dname ? "acc" : "a");
 
     case AOP_IMMD:
       if (aop->aopu.aop_immd.from_cast_remat && (offset == (aop->size-1)))
-      {
+        {
           SNPRINTF(buffer, sizeof(buffer),
                    "%s",aop->aopu.aop_immd.aop_immd2);
-      }
+        }
       else if (bit16)
-      {
-         SNPRINTF(buffer, sizeof(buffer),
-                  "#%s", aop->aopu.aop_immd.aop_immd1);
-      }
+        {
+          SNPRINTF(buffer, sizeof(buffer),
+                   "#%s", aop->aopu.aop_immd.aop_immd1);
+        }
       else if (offset)
-      {
+        {
           switch (offset) {
           case 1:
               tsprintf(buffer, sizeof(buffer),
@@ -1575,12 +1599,13 @@ aopGet (operand * oper,
                        aop->aopu.aop_immd.aop_immd1,
                        offset * 8);
           }
-      }
+        }
       else
-      {
-        SNPRINTF (buffer, sizeof(buffer),
-                  "#%s", aop->aopu.aop_immd.aop_immd1);
-      }
+        {
+          SNPRINTF (buffer, sizeof(buffer),
+                    "#%s",
+                    aop->aopu.aop_immd.aop_immd1);
+        }
       return Safe_strdup(buffer);
 
     case AOP_DIR:
@@ -1594,13 +1619,14 @@ aopGet (operand * oper,
         {
           SNPRINTF (buffer, sizeof(buffer),
                     "(%s + %d)",
-                   aop->aopu.aop_dir,
-                   offset);
+                    aop->aopu.aop_dir,
+                    offset);
         }
       else
         {
           SNPRINTF (buffer, sizeof(buffer),
-                   "%s", aop->aopu.aop_dir);
+                    "%s",
+                    aop->aopu.aop_dir);
         }
 
       return Safe_strdup(buffer);
@@ -1612,8 +1638,8 @@ aopGet (operand * oper,
         return aop->aopu.aop_reg[offset]->name;
 
     case AOP_CRY:
-      emitcode ("clr", "a");
       emitcode ("mov", "c,%s", aop->aopu.aop_dir);
+      emitcode ("clr", "a");
       emitcode ("rlc", "a");
       return (dname ? "acc" : "a");
 
@@ -1642,49 +1668,6 @@ aopGet (operand * oper,
   return NULL;  // not reached, but makes compiler happy.
 }
 
-/*-----------------------------------------------------------------*/
-/* aopPutUsesAcc - indicates ahead of time whether aopPut() will   */
-/*                 clobber the accumulator                         */
-/*-----------------------------------------------------------------*/
-static bool
-aopPutUsesAcc (operand * oper, const char *s, int offset)
-{
-  asmop * aop = AOP (oper);
-
-  if (offset > (aop->size - 1))
-    return FALSE;
-
-  switch (aop->type)
-    {
-    case AOP_DUMMY:
-      return TRUE;
-    case AOP_DIR:
-      return FALSE;
-    case AOP_REG:
-      wassert(strcmp(aop->aopu.aop_reg[offset]->name, "a"));
-      return FALSE;
-    case AOP_DPTR:
-      return TRUE;
-    case AOP_R0:
-    case AOP_R1:
-      return ((aop->paged) || (*s == '@'));
-    case AOP_STK:
-      return (*s == '@');
-    case AOP_CRY:
-      return (!aop->aopu.aop_dir || strcmp(s, aop->aopu.aop_dir));
-    case AOP_STR:
-      return FALSE;
-    case AOP_IMMD:
-      return FALSE;
-    case AOP_ACC:
-      return FALSE;
-    default:
-      /* Error case --- will have been caught already */
-      wassert(0);
-      return FALSE;
-    }
-}
-
 /*-----------------------------------------------------------------*/
 /* aopPut - puts a string for a aop and indicates if acc is in use */
 /*-----------------------------------------------------------------*/
@@ -1694,6 +1677,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))
     {
@@ -1720,19 +1704,20 @@ aopPut (operand * result, const char *s, int offset)
         }
       else if (offset)
         {
-            SNPRINTF (buffer, sizeof(buffer),
-                      "(%s + %d)",
-                      aop->aopu.aop_dir, offset);
+          SNPRINTF (buffer, sizeof(buffer),
+                    "(%s + %d)",
+                    aop->aopu.aop_dir, offset);
         }
       else
         {
-            SNPRINTF (buffer, sizeof(buffer),
-                     "%s", aop->aopu.aop_dir);
+          SNPRINTF (buffer, sizeof(buffer),
+                    "%s",
+                    aop->aopu.aop_dir);
         }
 
       if (strcmp (buffer, s) || bvolatile)
         {
-            emitcode ("mov", "%s,%s", buffer, s);
+          emitcode ("mov", "%s,%s", buffer, s);
         }
       if (!strcmp (buffer, "acc"))
         {
@@ -1754,13 +1739,13 @@ aopPut (operand * result, const char *s, int offset)
               strcmp (s, "r6") == 0 ||
               strcmp (s, "r7") == 0)
             {
-                emitcode ("mov", "%s,%s",
-                          aop->aopu.aop_reg[offset]->dname, s);
+              emitcode ("mov", "%s,%s",
+                        aop->aopu.aop_reg[offset]->dname, s);
             }
-            else
+          else
             {
-                emitcode ("mov", "%s,%s",
-                          aop->aopu.aop_reg[offset]->name, s);
+              emitcode ("mov", "%s,%s",
+                        aop->aopu.aop_reg[offset]->name, s);
             }
         }
       break;
@@ -1848,50 +1833,78 @@ aopPut (operand * result, const char *s, int offset)
           emitcode ("mov", "@%s,%s",
                     aop->aopu.aop_ptr->name, buffer);
         }
-        else
+      else
         {
-            emitcode ("mov", "@%s,%s", aop->aopu.aop_ptr->name, s);
+          emitcode ("mov", "@%s,%s", aop->aopu.aop_ptr->name, s);
         }
       break;
 
     case AOP_STK:
       if (strcmp (s, "a") == 0)
-        emitcode ("push", "acc");
-      else
-        if (*s=='@') {
+        {
+          emitcode ("push", "acc");
+        }
+      else if (*s=='@')
+        {
           MOVA(s);
           emitcode ("push", "acc");
-        } else {
+        }
+      else if (strcmp (s, "r0") == 0 ||
+               strcmp (s, "r1") == 0 ||
+               strcmp (s, "r2") == 0 ||
+               strcmp (s, "r3") == 0 ||
+               strcmp (s, "r4") == 0 ||
+               strcmp (s, "r5") == 0 ||
+               strcmp (s, "r6") == 0 ||
+               strcmp (s, "r7") == 0)
+        {
+          char buffer[10];
+          SNPRINTF (buffer, sizeof(buffer), "a%s", s);
+          emitcode ("push", buffer);
+        }
+      else
+        {
           emitcode ("push", s);
         }
 
       break;
 
     case AOP_CRY:
-      /* if not bit variable */
-      if (!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"))
         {
-          /* inefficient: move carry into A and use jz/jnz */
-          emitcode ("clr", "a");
-          emitcode ("rlc", "a");
-          accuse = TRUE;
+          MOVA (s);
+          /* set C, if a >= 1 */
+          emitcode ("add", "a,#!constbyte",0xff);
+          s = "c";
         }
-      else
+      // now source is zero, one or carry
+
+      /* if result no bit variable */
+      if (!d)
         {
-          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))
-            {
-                  MOVA (s);
-                /* set C, if a >= 1 */
-                emitcode ("add", "a,#!constbyte",0xff);
-                emitcode ("mov", "%s,c", aop->aopu.aop_dir);
-              }
+          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:
@@ -1958,15 +1971,13 @@ reAdjustPreg (asmop * aop)
 }
 
 /*-----------------------------------------------------------------*/
-/* opIsGptr: returns non-zero if the passed operand is       */
-/* a generic pointer type.             */
+/* opIsGptr: returns non-zero if the passed operand is             */
+/* a generic pointer type.                                         */
 /*-----------------------------------------------------------------*/
 static int
 opIsGptr (operand * op)
 {
-  sym_link *type = operandType (op);
-
-  if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
+  if (op && IS_GENPTR (operandType (op)) && (AOP_SIZE (op) == GPTRSIZE))
     {
       return 1;
     }
@@ -1979,8 +1990,8 @@ opIsGptr (operand * op)
 static int
 getDataSize (operand * op)
 {
-  int size;
-  size = AOP_SIZE (op);
+  int size = AOP_SIZE (op);
+
   if (size == GPTRSIZE)
     {
       sym_link *type = operandType (op);
@@ -2064,7 +2075,7 @@ toBoolean (operand * oper)
       emitcode("mov", "b,a");
       while (--size)
         {
-        MOVA (aopGet (oper, offset++, FALSE, FALSE, NULL));
+          MOVA (aopGet (oper, offset++, FALSE, FALSE, NULL));
           emitcode ("orl", "b,a");
         }
       MOVA (aopGet (oper, offset++, FALSE, FALSE, NULL));
@@ -2091,7 +2102,7 @@ genNot (iCode * ic)
 {
   symbol *tlbl;
 
-  D (emitcode (";", "genNot "));
+  D (emitcode (";", "genNot"));
 
   /* assign asmOps to operand & result */
   aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
@@ -2118,8 +2129,8 @@ genNot (iCode * ic)
 
   /* set C, if a == 0 */
   tlbl = newiTempLabel (NULL);
-  emitcode ("cjne", "a,#1,!tlabel", tlbl->key + 100);
-  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  emitcode ("cjne", "a,#0x01,!tlabel", tlbl->key + 100);
+  emitLabel (tlbl);
   outBitC (IC_RESULT (ic));
 
 release:
@@ -2175,7 +2186,7 @@ genCpl (iCode * ic)
           MOVA (l);
           emitcode ("cjne", "a,#0xFF,%05d$", tlbl->key + 100);
         }
-      emitcode ("", "%05d$:", tlbl->key + 100);
+      emitLabel (tlbl);
       outBitC (IC_RESULT(ic));
       goto release;
     }
@@ -2207,7 +2218,7 @@ genUminusFloat (operand * op, operand * result)
   int size, offset = 0;
   char *l;
 
-  D(emitcode (";", "genUminusFloat"));
+  D (emitcode (";", "genUminusFloat"));
 
   /* for this we just copy and then flip the bit */
 
@@ -2239,7 +2250,7 @@ genUminus (iCode * ic)
   int offset, size;
   sym_link *optype;
 
-  D (emitcode (";", "genUminus "));
+  D (emitcode (";", "genUminus"));
 
   /* assign asmops */
   aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
@@ -2278,7 +2289,7 @@ genUminus (iCode * ic)
           if (offset == 0)
             SETC;
           emitcode ("cpl", "a");
-          emitcode ("addc", "a,#0");
+          emitcode ("addc", "a,#0x00");
         }
       else
         {
@@ -2293,7 +2304,7 @@ genUminus (iCode * ic)
 
   /* if any remaining bytes in the result */
   /* we just need to propagate the sign   */
-  if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))) != 0)
+  if ((size = (AOP_SIZE (IC_RESULT (ic)) - AOP_SIZE (IC_LEFT (ic)))))
     {
       emitcode ("rlc", "a");
       emitcode ("subb", "a,acc");
@@ -2313,6 +2324,7 @@ release:
 static void savermask(bitVect *rs_mask)
 {
   int i;
+
   if (options.useXstack)
     {
       if (bitVectBitValue (rs_mask, R0_IDX))
@@ -2371,7 +2383,7 @@ saveRegisters (iCode * lic)
      do nothing */
   if (ic->regsSaved
       || (IS_SYMOP(IC_LEFT(ic)) && IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT(ic))) && !TARGET_IS_DS400) )
-    return ;
+    return;
 
   /* special case if DPTR alive across a function call then must save it
      even though callee saves */
@@ -2402,9 +2414,11 @@ saveRegisters (iCode * lic)
 /*-----------------------------------------------------------------*/
 static void unsavermask(bitVect *rs_mask)
 {
-    int i;
-    if (options.useXstack) {
-        emitcode ("mov", "r0,%s", spname);
+  int i;
+
+  if (options.useXstack)
+    {
+      emitcode ("mov", "r0,%s", spname);
       for (i = ds390_nRegs; i >= 0; i--)
         {
           if (bitVectBitValue (rs_mask, i))
@@ -2433,7 +2447,7 @@ static void unsavermask(bitVect *rs_mask)
       bool bits_popped = FALSE;
       for (i = ds390_nRegs; i >= 0; i--)
         {
-            if (bitVectBitValue (rs_mask, i))
+          if (bitVectBitValue (rs_mask, i))
             {
               bits_popped = popReg (i, bits_popped);
             }
@@ -2469,12 +2483,32 @@ unsaveRegisters (iCode * ic)
 
 
 /*-----------------------------------------------------------------*/
-/* pushSide -                */
+/* 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, FALSE);
+
+  if (nPushed != _G.r0Pushed + _G.r1Pushed)
+    {
+      while (offset < size)
+        {
+          char *l = aopGet (oper, offset, FALSE, TRUE, NULL);
+          emitcode ("mov", "%s,%s", fReturn[offset++], l);
+        }
+      freeAsmop (oper, NULL, ic, TRUE);
+      offset = 0;
+      while (offset < size)
+        {
+          emitcode ("push", "%s", fReturn[offset++]);
+        }
+      return;
+    }
+
   _startLazyDPSEvaluation ();
   while (size--)
     {
@@ -2488,10 +2522,11 @@ pushSide (operand * oper, int size)
         }
       else
         {
-        emitcode ("push", "%s", l);
-    }
+          emitcode ("push", "%s", l);
+        }
     }
   _endLazyDPSEvaluation ();
+  freeAsmop (oper, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2553,7 +2588,7 @@ genXpush (iCode * ic)
   regs *r;
   int size, offset = 0;
 
-  D (emitcode (";", "genXpush "));
+  D (emitcode (";", "genXpush"));
 
   aopOp (IC_LEFT (ic), ic, FALSE, FALSE);
   r = getFreePtr (ic, &aop, FALSE);
@@ -2590,7 +2625,7 @@ genXpush (iCode * ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* genIpush - generate code for pushing this gets a little complex  */
+/* genIpush - generate code for pushing this gets a little complex */
 /*-----------------------------------------------------------------*/
 static void
 genIpush (iCode * ic)
@@ -2599,7 +2634,7 @@ genIpush (iCode * ic)
   char *l;
   char *prev = "";
 
-  D (emitcode (";", "genIpush "));
+  D (emitcode (";", "genIpush"));
 
   /* if this is not a parm push : ie. it is spill push
      and spill push is always done on the local stack */
@@ -2661,7 +2696,7 @@ genIpush (iCode * ic)
         }
       else
         {
-            emitcode ("push", "%s", l);
+          emitcode ("push", "%s", l);
         }
       prev = l;
     }
@@ -2678,7 +2713,7 @@ genIpop (iCode * ic)
 {
   int size, offset;
 
-  D (emitcode (";", "genIpop "));
+  D (emitcode (";", "genIpop"));
 
   /* if the temp was not pushed then */
   if (OP_SYMBOL (IC_LEFT (ic))->isspilt || OP_SYMBOL (IC_LEFT (ic))->dptr)
@@ -2698,6 +2733,21 @@ genIpop (iCode * ic)
   freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
 }
 
+/*-----------------------------------------------------------------*/
+/* popForBranch - recover the spilt registers for a branch         */
+/*-----------------------------------------------------------------*/
+static void
+popForBranch (iCode * ic, bool markGenerated)
+{
+  while (ic && ic->op == IPOP)
+    {
+      genIpop (ic);
+      if (markGenerated)
+        ic->generated = 1;    /* mark the icode as generated */
+      ic = ic->next;
+    }
+}
+
 /*-----------------------------------------------------------------*/
 /* saveRBank - saves an entire register bank on the stack          */
 /*-----------------------------------------------------------------*/
@@ -2710,28 +2760,28 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
   regs *r = NULL;
 
   if (options.useXstack)
-  {
+    {
       if (!ic)
-      {
+        {
           /* Assume r0 is available for use. */
-          r = REG_WITH_INDEX (R0_IDX);;
-      }
+          r = REG_WITH_INDEX (R0_IDX);
+        }
       else
-      {
+        {
           aop = newAsmop (0);
           r = getFreePtr (ic, &aop, FALSE);
-      }
+        }
       // allocate space first
       emitcode ("mov", "%s,_spx", r->name);
       MOVA (r->name);
       emitcode ("add", "a,#%d", count);
       emitcode ("mov", "_spx,a");
-  }
+    }
 
   for (i = 0; i < 8; i++) /* only R0-R7 needs saving */
     {
       if (options.useXstack)
-      {
+        {
           emitcode ("mov", "a,(%s+%d)",
                     regs390[i].base, 8 * bank + regs390[i].offset);
           emitcode ("movx", "@%s,a", r->name);
@@ -2769,20 +2819,20 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
       else
       {
         emitcode ("push", "psw");
-    }
+      }
 
       emitcode ("mov", "psw,#!constbyte", (bank << 3) & 0x00ff);
     }
 
   if (aop)
-  {
+    {
       freeAsmop (NULL, aop, ic, TRUE);
-  }
+    }
 
   if (ic)
-  {
-    ic->bankSaved = 1;
-  }
+    {
+      ic->bankSaved = 1;
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -2797,17 +2847,17 @@ unsaveRBank (int bank, iCode * ic, bool popPsw)
 
   if (options.useXstack)
     {
-        if (!ic)
+      if (!ic)
         {
           /* Assume r0 is available for use. */
-          r = REG_WITH_INDEX (R0_IDX);;
+          r = REG_WITH_INDEX (R0_IDX);
         }
-        else
+      else
         {
           aop = newAsmop (0);
           r = getFreePtr (ic, &aop, FALSE);
         }
-        emitcode ("mov", "%s,_spx", r->name);
+      emitcode ("mov", "%s,_spx", r->name);
     }
 
   if (popPsw)
@@ -2850,7 +2900,7 @@ unsaveRBank (int bank, iCode * ic, bool popPsw)
       else
         {
           emitcode ("pop", "(%s+%d)",
-                  regs390[i].base, 8 * bank + regs390[i].offset);
+                    regs390[i].base, 8 * bank + regs390[i].offset);
         }
     }
 
@@ -2860,9 +2910,9 @@ unsaveRBank (int bank, iCode * ic, bool popPsw)
     }
 
   if (aop)
-  {
-    freeAsmop (NULL, aop, ic, TRUE);
-  }
+    {
+      freeAsmop (NULL, aop, ic, TRUE);
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -2870,13 +2920,13 @@ unsaveRBank (int bank, iCode * ic, bool popPsw)
 /*-----------------------------------------------------------------*/
 static void genSend(set *sendSet)
 {
-    iCode *sic;
+  iCode *sic;
   int bit_count = 0;
-    int sendCount = 0 ;
-    static int rb1_count = 0;
+  int sendCount = 0 ;
+  static int rb1_count = 0;
 
   /* first we do all bit parameters */
-    for (sic = setFirstItem (sendSet); sic;
+  for (sic = setFirstItem (sendSet); sic;
        sic = setNextItem (sendSet))
     {
       if (sic->argreg > 12)
@@ -2928,43 +2978,51 @@ static void genSend(set *sendSet)
        sic = setNextItem (sendSet))
     {
       if (sic->argreg <= 12)
-      {
-        int size, offset = 0;
+        {
+          int size, offset = 0;
 
-        size=getSize(operandType(IC_LEFT(sic)));
-        D (emitcode (";", "genSend argreg = %d, size = %d ",sic->argreg,size));
-        if (sendCount == 0) { /* first parameter */
-            // we know that dpl(hxb) is the result, so
-            rb1_count = 0 ;
-            _startLazyDPSEvaluation ();
-            if (size>1) {
-                aopOp (IC_LEFT (sic), sic, FALSE,
-                       (AOP_IS_STR(IC_LEFT(sic)) ? FALSE : TRUE));
-            } else {
-                aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
-            }
-            while (size--)
-              {
-                char *l = aopGet (IC_LEFT (sic), offset, FALSE, FALSE, NULL);
-                if (strcmp (l, fReturn[offset]))
-                  {
-                    emitcode ("mov", "%s,%s", fReturn[offset], l);
+          size = getSize (operandType (IC_LEFT (sic)));
+          D (emitcode (";", "genSend argreg = %d, size = %d ",sic->argreg,size));
+          if (sendCount == 0)
+            { /* first parameter */
+              // we know that dpl(hxb) is the result, so
+              rb1_count = 0 ;
+              _startLazyDPSEvaluation ();
+              if (size>1)
+                {
+                  aopOp (IC_LEFT (sic), sic, FALSE,
+                         (AOP_IS_STR(IC_LEFT(sic)) ? FALSE : TRUE));
+                }
+              else
+                {
+                  aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
+                }
+              while (size--)
+                {
+                  char *l = aopGet (IC_LEFT (sic), offset, FALSE, FALSE, NULL);
+                  if (strcmp (l, fReturn[offset]))
+                    {
+                      emitcode ("mov", "%s,%s", fReturn[offset], l);
+                    }
+                  offset++;
                 }
-                offset++;
+              _endLazyDPSEvaluation ();
+              freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+              rb1_count =0;
             }
-            _endLazyDPSEvaluation ();
-            freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
-            rb1_count =0;
-        } else { /* if more parameter in registers */
-            aopOp (IC_LEFT (sic), sic, FALSE, TRUE);
-            while (size--) {
-                emitcode ("mov","b1_%d,%s",rb1_count++,aopGet (IC_LEFT (sic), offset++,
-                                                                FALSE, FALSE, NULL));
+          else
+            { /* if more parameter in registers */
+              aopOp (IC_LEFT (sic), sic, FALSE, TRUE);
+              while (size--)
+                {
+                  emitcode ("mov","b1_%d,%s",rb1_count++,
+                            aopGet (IC_LEFT (sic), offset, FALSE, FALSE, NULL));
+                  offset++;
+                }
+              freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
             }
-            freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+          sendCount++;
         }
-        sendCount++;
-      }
     }
 }
 
@@ -3014,7 +3072,7 @@ genCall (iCode * ic)
   bool resultInF0 = FALSE;
   bool assignResultGenerated = FALSE;
 
-  D (emitcode (";", "genCall "));
+  D (emitcode (";", "genCall"));
 
   /* if we are calling a not _naked function that is not using
      the same register bank then we need to save the
@@ -3036,8 +3094,8 @@ genCall (iCode * ic)
       swapBanks = TRUE;
   }
 
-    /* if caller saves & we have not saved then */
-    if (!ic->regsSaved)
+  /* if caller saves & we have not saved then */
+  if (!ic->regsSaved)
       saveRegisters (ic);
 
   /* if send set is not empty then assign */
@@ -3057,10 +3115,10 @@ genCall (iCode * ic)
     }
 
   if (swapBanks)
-  {
-        emitcode ("mov", "psw,#!constbyte",
-           ((FUNC_REGBANK(dtype)) << 3) & 0xff);
-  }
+    {
+      emitcode ("mov", "psw,#!constbyte",
+         ((FUNC_REGBANK(dtype)) << 3) & 0xff);
+    }
 
   /* make the call */
   emitcode ("lcall", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
@@ -3151,15 +3209,16 @@ genCall (iCode * ic)
                   emitcode ("push", "acc");
                   accPushed = TRUE;
                 }
-            if (IS_BIT (OP_SYM_ETYPE (IC_LEFT (ic))) &&
-                IS_BIT (OP_SYM_ETYPE (IC_RESULT (ic))) &&
-                !assignResultGenerated)
-              {
-                emitcode ("mov", "F0,c");
-                resultInF0 = TRUE;
-              }
-              emitcode ("mov", "a,%s", spname);
-              emitcode ("add", "a,#!constbyte", (-ic->parmBytes) & 0xff);
+              if (IS_BIT (OP_SYM_ETYPE (IC_LEFT (ic))) &&
+                  IS_BIT (OP_SYM_ETYPE (IC_RESULT (ic))) &&
+                  !assignResultGenerated)
+                {
+                  emitcode ("mov", "F0,c");
+                  resultInF0 = TRUE;
+                }
+
+              emitcode ("mov", "a,%s", spname);
+              emitcode ("add", "a,#!constbyte", (-ic->parmBytes) & 0xff);
               emitcode ("mov", "%s,a", spname);
 
               /* unsaveRegisters from xstack needs acc, but */
@@ -3218,7 +3277,7 @@ genPcall (iCode * ic)
   bool restoreBank=FALSE;
   bool resultInF0 = FALSE;
 
-  D (emitcode (";", "genPcall "));
+  D (emitcode (";", "genPcall"));
 
   dtype = operandType (IC_LEFT (ic))->next;
   etype = getSpec(dtype);
@@ -3248,22 +3307,19 @@ genPcall (iCode * ic)
       emitcode ("push", "acc");
     }
 
-  /* now push the calling address */
-  aopOp (IC_LEFT (ic), ic, FALSE, 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));
         _G.sendSet = NULL;
     }
 
+  /* make the call */
   emitcode ("ret", "");
-  emitcode ("", "!tlabeldef", (rlbl->key + 100));
+  emitLabel (rlbl);
 
 
   /* if we need assign a result value */
@@ -3324,7 +3380,7 @@ genPcall (iCode * ic)
               emitcode ("mov", "a,%s", spname);
               emitcode ("add", "a,#!constbyte", (-ic->parmBytes) & 0xff);
               emitcode ("mov", "%s,a", spname);
-            }
+          }
           else
               for (i = 0; i < ic->parmBytes; i++)
                   emitcode ("dec", "%s", spname);
@@ -3368,12 +3424,6 @@ resultRemat (iCode * ic)
   return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 /*-----------------------------------------------------------------*/
 /* inExcludeList - return 1 if the string is in exclude Reg list   */
 /*-----------------------------------------------------------------*/
@@ -3403,10 +3453,10 @@ genFunction (iCode * ic)
 {
   symbol   *sym = OP_SYMBOL (IC_LEFT (ic));
   sym_link *ftype;
-  bool   switchedPSW = FALSE;
+  bool     switchedPSW = FALSE;
   bool     fReentrant = (IFFUNC_ISREENT (sym->type) || options.stackAuto);
 
-  D (emitcode (";", "genFunction "));
+  D (emitcode (";", "genFunction"));
 
   _G.nRegsSaved = 0;
   /* create the function header */
@@ -3415,6 +3465,7 @@ genFunction (iCode * ic)
   emitcode (";", "-----------------------------------------");
 
   emitcode ("", "%s:", sym->rname);
+  lineCurr->isLabel = 1;
   ftype = operandType (IC_LEFT (ic));
   _G.currentFunc = sym;
 
@@ -3453,7 +3504,7 @@ genFunction (iCode * ic)
   /* if this is an interrupt service routine then
      save acc, b, dpl, dph  */
   if (IFFUNC_ISISR (sym->type))
-      { /* is ISR */
+    { /* is ISR */
       if (!inExcludeList ("acc"))
         emitcode ("push", "acc");
       if (!inExcludeList ("b"))
@@ -3482,7 +3533,7 @@ genFunction (iCode * ic)
          registers :-) */
       if (!FUNC_REGBANK (sym->type))
         {
-            int i;
+          int i;
 
           /* if this function does not call any other
              function then we can be economical and
@@ -3507,14 +3558,16 @@ genFunction (iCode * ic)
                  determine register usage so we will have to push the
                  entire bank */
               saveRBank (0, ic, FALSE);
-              if (options.parms_in_bank1) {
-                  for (i=0; i < 8 ; i++ ) {
+              if (options.parms_in_bank1)
+                {
+                  for (i=0; i < 8 ; i++ )
+                    {
                       emitcode ("push","%s",rb1regs[i]);
-                  }
-              }
+                    }
+                }
             }
         }
-        else
+      else
         {
             /* This ISR uses a non-zero bank.
              *
@@ -3711,7 +3764,7 @@ genFunction (iCode * ic)
       emitcode ("setb", "c");
       emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
       emitcode ("clr", "c");
-      emitcode ("", "%05d$:", (tlbl->key + 100));
+      emitLabel (tlbl);
       emitcode ("push", "psw"); /* save old ea via c in psw */
     }
 }
@@ -3722,14 +3775,14 @@ genFunction (iCode * ic)
 static void
 genEndFunction (iCode * ic)
 {
-  symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+  symbol   *sym = OP_SYMBOL (IC_LEFT (ic));
   lineNode *lnp = lineCurr;
-  bitVect *regsUsed;
-  bitVect *regsUsedPrologue;
-  bitVect *regsUnneeded;
-  int idx;
+  bitVect  *regsUsed;
+  bitVect  *regsUsedPrologue;
+  bitVect  *regsUnneeded;
+  int      idx;
 
-  D (emitcode (";", "genEndFunction "););
+  D (emitcode (";", "genEndFunction"));
 
   _G.currentFunc = NULL;
   if (IFFUNC_ISNAKED(sym->type))
@@ -3811,7 +3864,7 @@ genEndFunction (iCode * ic)
   }
 
   if (IFFUNC_ISISR (sym->type))
-      { /* is ISR */
+    { /* is ISR */
 
       /* now we need to restore the registers */
       /* if this isr has no bank i.e. is going to
@@ -3819,7 +3872,7 @@ genEndFunction (iCode * ic)
          registers :-) */
       if (!FUNC_REGBANK (sym->type))
         {
-            int i;
+          int i;
           /* if this function does not call any other
              function then we can be economical and
              save only those registers that are used */
@@ -3842,15 +3895,17 @@ genEndFunction (iCode * ic)
               /* this function has a function call. We cannot
                  determine register usage so we will have to pop the
                  entire bank */
-              if (options.parms_in_bank1) {
-                  for (i = 7 ; i >= 0 ; i-- ) {
+              if (options.parms_in_bank1)
+                {
+                  for (i = 7 ; i >= 0 ; i-- )
+                    {
                       emitcode ("pop","%s",rb1regs[i]);
-                  }
-              }
+                    }
+                }
               unsaveRBank (0, ic, FALSE);
             }
         }
-        else
+      else
         {
             /* This ISR uses a non-zero bank.
              *
@@ -4033,7 +4088,7 @@ genEndFunction (iCode * ic)
 
   for (idx = 0; idx < regsUnneeded->size; idx++)
     if (bitVectBitValue (regsUnneeded, idx))
-      emitcode ("", ";\teliminated unneeded push/pop %s", REG_WITH_INDEX (idx)->dname);
+      emitcode (";", "eliminated unneeded push/pop %s", REG_WITH_INDEX (idx)->dname);
 
   freeBitVect (regsUnneeded);
   freeBitVect (regsUsed);
@@ -4161,9 +4216,9 @@ genLabel (iCode * ic)
   if (IC_LABEL (ic) == entryLabel)
     return;
 
-  D (emitcode (";", "genLabel "));
+  D (emitcode (";", "genLabel"));
 
-  emitcode ("", "!tlabeldef", (IC_LABEL (ic)->key + 100));
+  emitLabel (IC_LABEL (ic));
 }
 
 /*-----------------------------------------------------------------*/
@@ -4172,7 +4227,7 @@ genLabel (iCode * ic)
 static void
 genGoto (iCode * ic)
 {
-  D (emitcode (";", "genGoto "));
+  D (emitcode (";", "genGoto"));
 
   emitcode ("ljmp", "!tlabel", (IC_LABEL (ic)->key + 100));
 }
@@ -4227,7 +4282,7 @@ genPlusIncr (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;
 
   if (size == 1 && AOP(IC_LEFT(ic)) == AOP(IC_RESULT(ic)) &&
@@ -4258,7 +4313,7 @@ genPlusIncr (iCode * ic)
           && (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
           && labelRange <= 5)
         {
-          D(emitcode (";", "tail increment optimized (range %d)", labelRange););
+          D (emitcode (";", "tail increment optimized (range %d)", labelRange));
           tlbl = IC_LABEL (ic->next);
           emitTlbl = 0;
         }
@@ -4287,16 +4342,16 @@ genPlusIncr (iCode * ic)
         {
           if (!strcmp(l, "acc"))
             {
-                emitcode("jnz", "!tlabel", tlbl->key + 100);
+              emitcode("jnz", "!tlabel", tlbl->key + 100);
             }
           else if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
                    IS_AOP_PREG (IC_RESULT (ic)))
             {
-                emitcode ("cjne", "%s,%s,!tlabel", l, zero, tlbl->key + 100);
+              emitcode ("cjne", "%s,%s,!tlabel", l, zero, tlbl->key + 100);
             }
           else
             {
-                emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
+              emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
             }
 
           l = aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE, NULL);
@@ -4306,16 +4361,16 @@ genPlusIncr (iCode * ic)
         {
           if (!strcmp(l, "acc"))
             {
-                emitcode("jnz", "!tlabel", tlbl->key + 100);
+              emitcode("jnz", "!tlabel", tlbl->key + 100);
             }
           else if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
                    IS_AOP_PREG (IC_RESULT (ic)))
             {
-                emitcode ("cjne", "%s,%s,!tlabel", l, zero, tlbl->key + 100);
+              emitcode ("cjne", "%s,%s,!tlabel", l, zero, tlbl->key + 100);
             }
           else
             {
-                emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
+              emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
             }
 
           l = aopGet (IC_RESULT (ic), MSB32, FALSE, FALSE, NULL);
@@ -4324,7 +4379,7 @@ genPlusIncr (iCode * ic)
 
       if (emitTlbl)
         {
-          emitcode ("", "!tlabeldef", tlbl->key + 100);
+          emitLabel (tlbl);
         }
       return TRUE;
     }
@@ -4349,17 +4404,18 @@ genPlusIncr (iCode * ic)
       while (icount--)
         emitcode ("inc", "dptr");
       return TRUE;
-  }
+    }
 
   if (AOP_INDPTRn(IC_LEFT(ic)) && AOP_INDPTRn(IC_RESULT(ic)) &&
       AOP(IC_LEFT(ic))->aopu.dptr == AOP(IC_RESULT(ic))->aopu.dptr &&
-      icount <= 5 ) {
+      icount <= 5 )
+    {
       emitcode ("mov","dps,#!constbyte",AOP(IC_LEFT(ic))->aopu.dptr);
       while (icount--)
         emitcode ("inc", "dptr");
       emitcode ("mov", "dps,#0");
       return TRUE;
-  }
+    }
 
   /* if the sizes are greater than 1 then we cannot */
   if (AOP_SIZE (IC_RESULT (ic)) > 1 ||
@@ -4412,7 +4468,7 @@ outBitAcc (operand * result)
     {
       emitcode ("jz", "!tlabel", tlbl->key + 100);
       emitcode ("mov", "a,%s", one);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       outAcc (result);
     }
 }
@@ -4423,21 +4479,20 @@ outBitAcc (operand * result)
 static void
 genPlusBits (iCode * ic)
 {
-  D (emitcode (";", "genPlusBits "));
+  D (emitcode (";", "genPlusBits"));
 
+  emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
   if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
     {
       symbol *lbl = newiTempLabel (NULL);
-      emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
       emitcode ("jnb", "%s,!tlabel", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
       emitcode ("cpl", "c");
-      emitcode ("", "!tlabeldef", (lbl->key + 100));
+      emitLabel (lbl);
       outBitC (IC_RESULT (ic));
     }
   else
     {
       emitcode ("clr", "a");
-      emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
       emitcode ("rlc", "a");
       emitcode ("mov", "c,%s", AOP (IC_RIGHT (ic))->aopu.aop_dir);
       emitcode ("addc", "a,%s", zero);
@@ -4462,13 +4517,13 @@ adjustArithmeticResult (iCode * ic)
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
     {
       aopPut (IC_RESULT (ic),
-            aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE, NULL),
+              aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE, NULL),
               GPTRSIZE - 1);
     }
 
   if (opIsGptr (IC_RESULT (ic)) &&
-      AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
-      AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+      IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+      IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
     {
@@ -4490,12 +4545,12 @@ bool aopOp3(iCode * ic)
     // First, generate the right opcode. DPTR may be used if neither left nor result are
     // of type AOP_STR.
 
-//    D(emitcode(";", "aopOp3: AOP_IS_STR left: %s right: %s result: %s",
+//    D (emitcode(";", "aopOp3: AOP_IS_STR left: %s right: %s result: %s",
 //             AOP_IS_STR(IC_LEFT(ic)) ? "true" : "false",
 //             AOP_IS_STR(IC_RIGHT(ic)) ? "true" : "false",
 //             AOP_IS_STR(IC_RESULT(ic)) ? "true" : "false");
 //      );
-//    D(emitcode(";", "aopOp3: AOP_IS_DPTRn left: %s right: %s result: %s",
+//    D (emitcode(";", "aopOp3: AOP_IS_DPTRn left: %s right: %s result: %s",
 //             AOP_IS_DPTRn(IC_LEFT(ic)) ? "true" : "false",
 //             AOP_IS_DPTRn(IC_RIGHT(ic)) ? "true" : "false",
 //             AOP_IS_DPTRn(IC_RESULT(ic)) ? "true" : "false");
@@ -4503,8 +4558,8 @@ bool aopOp3(iCode * ic)
 
     // Right uses DPTR unless left or result is an AOP_STR; however,
     // if right is an AOP_STR, it must use DPTR regardless.
-    if ((AOP_IS_STR(IC_LEFT(ic)) || AOP_IS_STR(IC_RESULT(ic)))
-     && !AOP_IS_STR(IC_RIGHT(ic)))
+    if ((AOP_IS_STR (IC_LEFT (ic)) || AOP_IS_STR (IC_RESULT (ic)))
+     && !AOP_IS_STR (IC_RIGHT (ic)))
     {
         useDp2 = TRUE;
     }
@@ -4513,7 +4568,7 @@ bool aopOp3(iCode * ic)
         useDp2 = FALSE;
     }
 
-    aopOp (IC_RIGHT(ic),ic,FALSE, useDp2);
+    aopOp (IC_RIGHT(ic), ic, FALSE, useDp2);
 
     // if the right used DPTR, left MUST use DPTR2.
     // if the right used DPTR2, left MUST use DPTR.
@@ -4521,17 +4576,17 @@ bool aopOp3(iCode * ic)
     // and left is not an AOP_STR, then we will get better code if we use DP2 for left,
     // enabling us to assign DPTR to result.
 
-    if (AOP_USESDPTR(IC_RIGHT(ic)))
+    if (AOP_USESDPTR (IC_RIGHT (ic)))
     {
         useDp2 = TRUE;
     }
-    else if (AOP_USESDPTR2(IC_RIGHT(ic)))
+    else if (AOP_USESDPTR2 (IC_RIGHT (ic)))
     {
         useDp2 = FALSE;
     }
     else
     {
-        if (AOP_IS_STR(IC_RESULT(ic)) && !AOP_IS_STR(IC_LEFT(ic)))
+        if (AOP_IS_STR (IC_RESULT (ic)) && !AOP_IS_STR (IC_LEFT (ic)))
         {
             useDp2 = TRUE;
         }
@@ -4541,63 +4596,63 @@ bool aopOp3(iCode * ic)
         }
     }
 
-    aopOp(IC_LEFT(ic), ic, FALSE, useDp2);
+    aopOp (IC_LEFT (ic), ic, FALSE, useDp2);
 
 
     // We've op'd the left & right. So, if left or right are the same operand as result,
     // we know aopOp will succeed, and we can just do it & bail.
-    if (isOperandEqual(IC_LEFT(ic),IC_RESULT(ic)))
+    if (isOperandEqual (IC_LEFT (ic), IC_RESULT (ic)))
       {
         aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR2 (IC_LEFT (ic)));
         return TRUE;
       }
-    if (isOperandEqual(IC_RIGHT(ic),IC_RESULT(ic)))
+    if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (ic)))
       {
-//      D(emitcode(";", "aopOp3: (left | right) & result equal"););
-        aopOp(IC_RESULT(ic),ic,TRUE, AOP_USESDPTR2 (IC_RIGHT (ic)));
+//      D (emitcode(";", "aopOp3: (left | right) & result equal"));
+        aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR2 (IC_RIGHT (ic)));
         return TRUE;
       }
 
     // Operands may be equivalent (but not equal) if they share a spill location. If
     // so, use the same DPTR or DPTR2.
-    if (operandsEqu (IC_LEFT(ic), IC_RESULT(ic)))
+    if (operandsEqu (IC_LEFT (ic), IC_RESULT (ic)))
       {
         aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR2 (IC_LEFT (ic)));
         return TRUE;
       }
-    if (operandsEqu (IC_RIGHT(ic), IC_RESULT(ic)))
+    if (operandsEqu (IC_RIGHT (ic), IC_RESULT (ic)))
       {
         aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR2 (IC_RIGHT (ic)));
         return TRUE;
       }
 
     // Note which dptrs are currently in use.
-    dp1InUse = AOP_USESDPTR(IC_LEFT(ic)) || AOP_USESDPTR(IC_RIGHT(ic));
-    dp2InUse = AOP_USESDPTR2(IC_LEFT(ic)) || AOP_USESDPTR2(IC_RIGHT(ic));
+    dp1InUse = AOP_USESDPTR (IC_LEFT (ic)) || AOP_USESDPTR (IC_RIGHT (ic));
+    dp2InUse = AOP_USESDPTR2 (IC_LEFT (ic)) || AOP_USESDPTR2 (IC_RIGHT (ic));
 
     // OK, now if either left or right uses DPTR and the result is an AOP_STR, we cannot
     // generate it.
-    if (dp1InUse && AOP_IS_STR(IC_RESULT(ic)))
+    if (dp1InUse && AOP_IS_STR (IC_RESULT (ic)))
     {
         return FALSE;
     }
 
     // Likewise, if left or right uses DPTR2 and the result is a DPTRn, we cannot generate it.
-    if (dp2InUse && AOP_IS_DPTRn(IC_RESULT(ic)))
+    if (dp2InUse && AOP_IS_DPTRn (IC_RESULT (ic)))
     {
         return FALSE;
     }
 
     // or, if both dp1 & dp2 are in use and the result needs a dptr, we're out of luck
-    if (dp1InUse && dp2InUse && isOperandInFarSpace(IC_RESULT(ic)))
+    if (dp1InUse && dp2InUse && isOperandInFarSpace (IC_RESULT (ic)))
     {
         return FALSE;
     }
 
-    aopOp (IC_RESULT(ic),ic,TRUE, dp1InUse);
+    aopOp (IC_RESULT (ic), ic, TRUE, dp1InUse);
 
     // Some sanity checking...
-    if (dp1InUse && AOP_USESDPTR(IC_RESULT(ic)))
+    if (dp1InUse && AOP_USESDPTR (IC_RESULT (ic)))
     {
         fprintf(stderr,
                 "Internal error: got unexpected DPTR (%s:%d %s:%d)\n",
@@ -4605,7 +4660,7 @@ bool aopOp3(iCode * ic)
         emitcode(";", ">>> unexpected DPTR here.");
     }
 
-    if (dp2InUse && AOP_USESDPTR2(IC_RESULT(ic)))
+    if (dp2InUse && AOP_USESDPTR2 (IC_RESULT (ic)))
     {
         fprintf(stderr,
                 "Internal error: got unexpected DPTR2 (%s:%d %s:%d)\n",
@@ -4626,8 +4681,8 @@ bool aopOp3(iCode * ic)
 
 // aopOp the left & right operands of an ic.
 #define AOP_OP_2(ic) \
-    aopOp (IC_RIGHT(ic),ic,FALSE, AOP_IS_STR(IC_LEFT(ic))); \
-    aopOp (IC_LEFT(ic),ic,FALSE, AOP_USESDPTR(IC_RIGHT(ic)));
+    aopOp (IC_RIGHT (ic), ic, FALSE, AOP_IS_STR (IC_LEFT (ic))); \
+    aopOp (IC_LEFT (ic), ic, FALSE, AOP_USESDPTR (IC_RIGHT (ic)));
 
 // convienience macro.
 #define AOP_SET_LOCALS(ic) \
@@ -4648,7 +4703,7 @@ bool aopOp3(iCode * ic)
        */                                                       \
       while (pushedSize > resultSize)                           \
       {                                                         \
-          D (emitcode (";", "discarding unused result byte."););\
+          D (emitcode (";", "discarding unused result byte.")); \
           emitcode ("pop", "acc");                              \
           pushedSize--;                                         \
       }                                                         \
@@ -4677,32 +4732,32 @@ genPlus (iCode * ic)
   int rSize;
   bool swappedLR = FALSE;
 
-  D (emitcode (";", "genPlus "));
+  D (emitcode (";", "genPlus"));
 
   /* special cases :- */
-  if ( AOP_IS_STR(IC_LEFT(ic)) &&
-      isOperandLiteral(IC_RIGHT(ic)) && OP_SYMBOL(IC_RESULT(ic))->ruonly) {
+  if ( AOP_IS_STR (IC_LEFT (ic)) &&
+      isOperandLiteral (IC_RIGHT (ic)) && OP_SYMBOL (IC_RESULT (ic))->ruonly) {
       aopOp (IC_RIGHT (ic), ic, TRUE, FALSE);
-      size = (int)floatFromVal (AOP (IC_RIGHT(ic))->aopu.aop_lit);
+      size = (int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
       if (size <= 9) {
           while (size--) emitcode ("inc","dptr");
       } else {
-          emitcode ("mov","a,dpl");
-          emitcode ("add","a,#!constbyte",size & 0xff);
-          emitcode ("mov","dpl,a");
-          emitcode ("mov","a,dph");
-          emitcode ("addc","a,#!constbyte",(size >> 8) & 0xff);
-          emitcode ("mov","dph,a");
-          emitcode ("mov","a,dpx");
-          emitcode ("addc","a,#!constbyte",(size >> 16) & 0xff);
-          emitcode ("mov","dpx,a");
+          emitcode ("mov", "a,dpl");
+          emitcode ("add", "a,#!constbyte", size & 0xff);
+          emitcode ("mov", "dpl,a");
+          emitcode ("mov", "a,dph");
+          emitcode ("addc", "a,#!constbyte", (size >> 8) & 0xff);
+          emitcode ("mov", "dph,a");
+          emitcode ("mov", "a,dpx");
+          emitcode ("addc", "a,#!constbyte", (size >> 16) & 0xff);
+          emitcode ("mov", "dpx,a");
       }
       freeAsmop (IC_RIGHT (ic), NULL, ic, FALSE);
       return ;
   }
-  if ( IS_SYMOP(IC_LEFT(ic)) &&
-       OP_SYMBOL(IC_LEFT(ic))->remat &&
-       isOperandInFarSpace(IC_RIGHT(ic))) {
+  if ( IS_SYMOP (IC_LEFT (ic)) &&
+       OP_SYMBOL (IC_LEFT (ic))->remat &&
+       isOperandInFarSpace (IC_RIGHT (ic))) {
       operand *op = IC_RIGHT(ic);
       IC_RIGHT(ic) = IC_LEFT(ic);
       IC_LEFT(ic) = op;
@@ -4712,7 +4767,7 @@ genPlus (iCode * ic)
 
   if (pushResult)
     {
-      D (emitcode (";", "genPlus: must push result: 3 ops in far space"););
+      D (emitcode (";", "genPlus: must push result: 3 ops in far space"));
     }
 
   if (!pushResult)
@@ -4720,15 +4775,15 @@ genPlus (iCode * ic)
       /* if literal, literal on the right or
          if left requires ACC or right is already
          in ACC */
-      if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT)
-       || ((AOP_NEEDSACC (IC_LEFT (ic))) && !(AOP_NEEDSACC (IC_RIGHT (ic))))
-          || AOP_TYPE (IC_RIGHT (ic)) == AOP_ACC)
+      if ((AOP_TYPE (IC_LEFT (ic)) == AOP_LIT) ||
+          ((AOP_NEEDSACC (IC_LEFT (ic))) && !(AOP_NEEDSACC (IC_RIGHT (ic)))) ||
+          AOP_TYPE (IC_RIGHT (ic)) == AOP_ACC)
         {
           operand *t = IC_RIGHT (ic);
           IC_RIGHT (ic) = IC_LEFT (ic);
           IC_LEFT (ic) = t;
           swappedLR = TRUE;
-          emitcode (";", "Swapped plus args.");
+          D (emitcode (";", "Swapped plus args."));
         }
 
       /* if both left & right are in bit
@@ -4748,7 +4803,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));
             }
@@ -4771,7 +4826,7 @@ genPlus (iCode * ic)
          of add then GOOD for ME */
       if (genPlusIncr (ic) == TRUE)
         {
-          emitcode (";", "did genPlusIncr");
+          D (emitcode (";", "did genPlusIncr"));
           goto release;
         }
 
@@ -4799,7 +4854,7 @@ genPlus (iCode * ic)
                * above branch.
                */
               assert(AOP_NEEDSACC(IC_RIGHT(ic)));
-       TR_AP("#3");
+              TR_AP("#3");
               D(emitcode(";", "+ AOP_ACC special case."););
               emitcode("xch", "a, %s", DP2_RESULT_REG);
           }
@@ -4808,7 +4863,7 @@ genPlus (iCode * ic)
           {
             if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC)
             {
-         TR_AP("#4");
+                TR_AP("#4");
                 emitcode("add", "a, %s", DP2_RESULT_REG);
             }
             else
@@ -4888,7 +4943,7 @@ 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;
 
   if (size == 1 && AOP(IC_LEFT(ic)) == AOP(IC_RESULT(ic)) &&
@@ -4918,7 +4973,7 @@ genMinusDec (iCode * ic)
           && (labelRange = findLabelBackwards (ic, IC_LABEL (ic->next)->key)) != 0
           && labelRange <= 5)
         {
-          emitcode (";", "tail decrement optimized (range %d)", labelRange);
+          D (emitcode (";", "tail decrement optimized (range %d)", labelRange));
           tlbl = IC_LABEL (ic->next);
           emitTlbl = 0;
         }
@@ -4934,59 +4989,59 @@ genMinusDec (iCode * ic)
       if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
           AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
           IS_AOP_PREG (IC_RESULT (ic)))
-      {
+        {
           emitcode ("cjne", "%s,#!constbyte,!tlabel", l, 0xff, tlbl->key + 100);
-      }
+        }
       else
-      {
+        {
           emitcode ("mov", "a,#!constbyte",0xff);
           emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
-      }
+        }
       l = aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE, NULL);
       emitcode ("dec", "%s", l);
       if (size > 2)
         {
-            if (!strcmp(l, "acc"))
+          if (!strcmp(l, "acc"))
             {
-                emitcode("jnz", "!tlabel", tlbl->key + 100);
+              emitcode("jnz", "!tlabel", tlbl->key + 100);
             }
-            else if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
-                     AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
-                     IS_AOP_PREG (IC_RESULT (ic)))
+          else if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+                   AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
+                   IS_AOP_PREG (IC_RESULT (ic)))
             {
-                emitcode ("cjne", "%s,#!constbyte,!tlabel", l, 0xff, tlbl->key + 100);
+              emitcode ("cjne", "%s,#!constbyte,!tlabel", l, 0xff, tlbl->key + 100);
             }
-            else
+          else
             {
-                emitcode ("mov", "a,#!constbyte",0xff);
-                emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
+              emitcode ("mov", "a,#!constbyte",0xff);
+              emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
             }
-            l = aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE, NULL);
-            emitcode ("dec", "%s", l);
+          l = aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE, NULL);
+          emitcode ("dec", "%s", l);
         }
       if (size > 3)
         {
-            if (!strcmp(l, "acc"))
+          if (!strcmp(l, "acc"))
             {
-                emitcode("jnz", "!tlabel", tlbl->key + 100);
+              emitcode("jnz", "!tlabel", tlbl->key + 100);
             }
-            else if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
-                     AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
-                     IS_AOP_PREG (IC_RESULT (ic)))
+          else if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG ||
+                   AOP_TYPE (IC_RESULT (ic)) == AOP_DPTR ||
+                   IS_AOP_PREG (IC_RESULT (ic)))
             {
-                emitcode ("cjne", "%s,#!constbyte,!tlabel", l, 0xff, tlbl->key + 100);
+              emitcode ("cjne", "%s,#!constbyte,!tlabel", l, 0xff, tlbl->key + 100);
             }
-            else
+          else
             {
-                emitcode ("mov", "a,#!constbyte",0xff);
-                emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
+              emitcode ("mov", "a,#!constbyte",0xff);
+              emitcode ("cjne", "a,%s,!tlabel", l, tlbl->key + 100);
             }
-            l = aopGet (IC_RESULT (ic), MSB32, FALSE, FALSE, NULL);
-            emitcode ("dec", "%s", l);
+          l = aopGet (IC_RESULT (ic), MSB32, FALSE, FALSE, NULL);
+          emitcode ("dec", "%s", l);
         }
       if (emitTlbl)
         {
-          emitcode ("", "!tlabeldef", tlbl->key + 100);
+          emitLabel (tlbl);
         }
       return TRUE;
     }
@@ -5047,17 +5102,17 @@ addSign (operand * result, int offset, int sign)
           emitcode ("rlc", "a");
           emitcode ("subb", "a,acc");
           while (size--)
-          {
-            aopPut (result, "a", offset++);
-          }
+            {
+              aopPut (result, "a", offset++);
+            }
         }
       else
-      {
-        while (size--)
         {
-          aopPut (result, zero, offset++);
+          while (size--)
+            {
+              aopPut (result, zero, offset++);
+            }
         }
-      }
       _endLazyDPSEvaluation();
     }
 }
@@ -5070,14 +5125,14 @@ genMinusBits (iCode * ic)
 {
   symbol *lbl = newiTempLabel (NULL);
 
-  D (emitcode (";", "genMinusBits "));
+  D (emitcode (";", "genMinusBits"));
 
   if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
     {
       emitcode ("mov", "c,%s", AOP (IC_LEFT (ic))->aopu.aop_dir);
       emitcode ("jnb", "%s,!tlabel", AOP (IC_RIGHT (ic))->aopu.aop_dir, (lbl->key + 100));
       emitcode ("cpl", "c");
-      emitcode ("", "!tlabeldef", (lbl->key + 100));
+      emitLabel (lbl);
       outBitC (IC_RESULT (ic));
     }
   else
@@ -5086,7 +5141,7 @@ genMinusBits (iCode * ic)
       emitcode ("subb", "a,acc");
       emitcode ("jnb", "%s,!tlabel", AOP (IC_LEFT (ic))->aopu.aop_dir, (lbl->key + 100));
       emitcode ("inc", "a");
-      emitcode ("", "!tlabeldef", (lbl->key + 100));
+      emitLabel (lbl);
       aopPut (IC_RESULT (ic), "a", 0);
       addSign (IC_RESULT (ic), MSB16, SPEC_USIGN (getSpec (operandType (IC_RESULT (ic)))));
     }
@@ -5103,7 +5158,7 @@ genMinus (iCode * ic)
     long lit = 0L;
     bool pushResult;
 
-    D (emitcode (";", "genMinus "));
+    D (emitcode (";", "genMinus"));
 
     AOP_OP_3_NOFATAL(ic, pushResult);
 
@@ -5133,7 +5188,7 @@ genMinus (iCode * ic)
     }
   else
     {
-      lit = (long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+      lit = (long) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
       lit = -lit;
     }
 
@@ -5214,7 +5269,7 @@ genMultbits (operand * left,
              operand * result,
              iCode   * ic)
 {
-  D(emitcode (";", "genMultbits"));
+  D (emitcode (";", "genMultbits"));
 
   emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
   emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir);
@@ -5310,7 +5365,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;
         }
@@ -5324,7 +5379,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;
         }
@@ -5345,7 +5400,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,#!constbyte", -val);
@@ -5364,14 +5419,14 @@ genMultOneByte (operand * left,
           emitcode ("cpl", "F0"); /* complement sign flag */
           emitcode ("cpl", "a");  /* 2's complement */
           emitcode ("inc", "a");
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
           emitcode ("mov", "b,a");
         }
     }
 
   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,#!constbyte", -val);
@@ -5389,7 +5444,7 @@ genMultOneByte (operand * left,
           emitcode ("cpl", "F0"); /* complement sign flag */
           emitcode ("cpl", "a");  /* 2's complement */
           emitcode ("inc", "a");
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
         }
     }
 
@@ -5417,13 +5472,13 @@ genMultOneByte (operand * left,
         emitcode ("inc", "a"); /* inc doesn't set carry flag */
       else
         {
-          emitcode ("add", "a,#1"); /* this sets carry flag */
+          emitcode ("add", "a,#0x01"); /* this sets carry flag */
           emitcode ("xch", "a,b");
           emitcode ("cpl", "a"); /* msb 2's complement */
-          emitcode ("addc", "a,#0");
+          emitcode ("addc", "a,#0x00");
           emitcode ("xch", "a,b");
         }
-      emitcode ("", "!tlabeldef", lbl->key + 100);
+      emitLabel (lbl);
     }
   aopPut (result, "a", 0);
   _G.accInUse--;
@@ -5454,13 +5509,13 @@ static void genMultTwoByte (operand *left, operand *right,
         emitcode ("setb","F1");
         emitcode ("jbc","EA,!tlabel",lbl->key+100);
         emitcode ("clr","F1");
-        emitcode("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
 
         /* load up MB with right */
         if (!umult) {
                 emitcode("clr","F0");
                 if (AOP_TYPE(right) == AOP_LIT) {
-                        int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
+                        int val=(int) ulFromVal (AOP (right)->aopu.aop_lit);
                         if (val < 0) {
                                 emitcode("setb","F0");
                                 val = -val;
@@ -5479,7 +5534,7 @@ static void genMultTwoByte (operand *left, operand *right,
                         emitcode ("cpl", "a"); // msb
                         emitcode ("addc", "a,#0");
                         emitcode ("setb","F0");
-                        emitcode ("","!tlabeldef",lbl->key+100);
+                        emitLabel (lbl);
                         emitcode ("mov","mb,b");
                         emitcode ("mov","mb,a");
                 }
@@ -5501,7 +5556,7 @@ static void genMultTwoByte (operand *left, operand *right,
                 emitcode ("addc","a,#0");
                 emitcode ("jbc","F0,!tlabel",lbl->key+100);
                 emitcode ("setb","F0");
-                emitcode ("","!tlabeldef",lbl->key+100);
+                emitLabel (lbl);
                 emitcode ("mov","ma,b");
                 emitcode ("mov","ma,a");
         } else {
@@ -5510,7 +5565,7 @@ static void genMultTwoByte (operand *left, operand *right,
         }
         /* wait for multiplication to finish */
         lbl = newiTempLabel(NULL);
-        emitcode("","!tlabeldef", lbl->key+100);
+        emitLabel (lbl);
         emitcode("mov","a,mcnt1");
         emitcode("anl","a,#!constbyte",0x80);
         emitcode("jnz","!tlabel",lbl->key+100);
@@ -5537,10 +5592,10 @@ static void genMultTwoByte (operand *left, operand *right,
                 emitcode("jnb","F0,!tlabel",lbl->key+100);
                 emitcode("cpl","a");
                 emitcode("add","a,#1");
-                emitcode("","!tlabeldef", lbl->key+100);
+                emitLabel (lbl);
                 if (AOP_TYPE(result) == AOP_ACC)
                 {
-                    D(emitcode(";", "ACC special case."););
+                    D (emitcode(";", "ACC special case."));
                     /* We know result is the only live aop, and
                      * it's obviously not a DPTR2, so AP is available.
                      */
@@ -5556,7 +5611,7 @@ static void genMultTwoByte (operand *left, operand *right,
                 emitcode("jnb","F0,!tlabel",lbl->key+100);
                 emitcode("cpl","a");
                 emitcode("addc","a,#0");
-                emitcode("","!tlabeldef", lbl->key+100);
+                emitLabel (lbl);
                 aopPut(result,"a",1);
                 emitcode("pop","acc");
                 if (AOP_SIZE(result) >= 3) {
@@ -5564,7 +5619,7 @@ static void genMultTwoByte (operand *left, operand *right,
                         emitcode("jnb","F0,!tlabel",lbl->key+100);
                         emitcode("cpl","a");
                         emitcode("addc","a,#0");
-                        emitcode("","!tlabeldef", lbl->key+100);
+                        emitLabel (lbl);
                         aopPut(result,"a",2);
                 }
                 emitcode("pop","acc");
@@ -5573,7 +5628,7 @@ static void genMultTwoByte (operand *left, operand *right,
                         emitcode("jnb","F0,!tlabel",lbl->key+100);
                         emitcode("cpl","a");
                         emitcode("addc","a,#0");
-                        emitcode("","!tlabeldef", lbl->key+100);
+                        emitLabel (lbl);
                         aopPut(result,"a",3);
                 }
                 if (AOP_TYPE(result) == AOP_ACC)
@@ -5589,7 +5644,7 @@ static void genMultTwoByte (operand *left, operand *right,
         lbl = newiTempLabel(NULL);
         emitcode ("jnb","F1,!tlabel",lbl->key+100);
         emitcode ("setb","EA");
-        emitcode("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         return ;
 }
 
@@ -5603,7 +5658,7 @@ genMult (iCode * ic)
   operand *right = IC_RIGHT (ic);
   operand *result = IC_RESULT (ic);
 
-  D (emitcode (";", "genMult "));
+  D (emitcode (";", "genMult"));
 
   /* assign the asmops */
   AOP_OP_2 (ic);
@@ -5651,7 +5706,7 @@ genDivbits (operand * left,
   char *l;
   bool pushedB;
 
-  D(emitcode (";     genDivbits",""));
+  D(emitcode (";", "genDivbits"));
 
   pushedB = pushB ();
 
@@ -5681,7 +5736,7 @@ genDivOneByte (operand * left,
   symbol *lbl;
   int size, offset;
 
-  D(emitcode (";     genDivOneByte",""));
+  D(emitcode (";", "genDivOneByte"));
 
   offset = 1;
   lUnsigned = SPEC_USIGN (getSpec (operandType (left)));
@@ -5725,7 +5780,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;
         }
@@ -5739,7 +5794,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;
         }
@@ -5760,7 +5815,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);
@@ -5779,14 +5834,14 @@ genDivOneByte (operand * left,
           emitcode ("cpl", "F0"); /* complement sign flag */
           emitcode ("cpl", "a");  /* 2's complement */
           emitcode ("inc", "a");
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
           emitcode ("mov", "b,a");
         }
     }
 
   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);
@@ -5804,7 +5859,7 @@ genDivOneByte (operand * left,
           emitcode ("cpl", "F0"); /* complement sign flag */
           emitcode ("cpl", "a");  /* 2's complement */
           emitcode ("inc", "a");
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
         }
     }
 
@@ -5819,7 +5874,7 @@ genDivOneByte (operand * left,
         emitcode ("jnb", "F0,!tlabel", lbl->key + 100);
       emitcode ("cpl", "a"); /* lsb 2's complement */
       emitcode ("inc", "a");
-      emitcode ("", "!tlabeldef", lbl->key + 100);
+      emitLabel (lbl);
 
       _G.accInUse++;
       aopOp (result, ic, TRUE, FALSE);
@@ -5875,7 +5930,7 @@ static void genDivTwoByte (operand *left, operand *right,
         emitcode ("setb","F1");
         emitcode ("jbc","EA,!tlabel",lbl->key+100);
         emitcode ("clr","F1");
-        emitcode("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
 
         /* load up MA with left */
         if (!umult) {
@@ -5891,7 +5946,7 @@ static void genDivTwoByte (operand *left, operand *right,
                 emitcode ("cpl", "a"); // msb
                 emitcode ("addc","a,#0");
                 emitcode ("setb","F0");
-                emitcode ("","!tlabeldef",lbl->key+100);
+                emitLabel (lbl);
                 emitcode ("mov","ma,b");
                 emitcode ("mov","ma,a");
         } else {
@@ -5902,12 +5957,12 @@ static void genDivTwoByte (operand *left, operand *right,
         /* load up MB with right */
         if (!umult) {
                 if (AOP_TYPE(right) == AOP_LIT) {
-                        int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
+                        int val=(int) ulFromVal (AOP (right)->aopu.aop_lit);
                         if (val < 0) {
                                 lbl = newiTempLabel(NULL);
                                 emitcode ("jbc","F0,!tlabel",lbl->key+100);
                                 emitcode("setb","F0");
-                                emitcode ("","!tlabeldef",lbl->key+100);
+                                emitLabel (lbl);
                                 val = -val;
                         }
                         emitcode ("mov","mb,#!constbyte",val & 0xff);
@@ -5925,7 +5980,7 @@ static void genDivTwoByte (operand *left, operand *right,
                         emitcode ("addc", "a,#0");
                         emitcode ("jbc","F0,!tlabel",lbl->key+100);
                         emitcode ("setb","F0");
-                        emitcode ("","!tlabeldef",lbl->key+100);
+                        emitLabel (lbl);
                         emitcode ("mov","mb,b");
                         emitcode ("mov","mb,a");
                 }
@@ -5936,7 +5991,7 @@ static void genDivTwoByte (operand *left, operand *right,
 
         /* wait for multiplication to finish */
         lbl = newiTempLabel(NULL);
-        emitcode("","!tlabeldef", lbl->key+100);
+        emitLabel (lbl);
         emitcode("mov","a,mcnt1");
         emitcode("anl","a,#!constbyte",0x80);
         emitcode("jnz","!tlabel",lbl->key+100);
@@ -5957,14 +6012,14 @@ static void genDivTwoByte (operand *left, operand *right,
                 emitcode("jnb","F0,!tlabel",lbl->key+100);
                 emitcode("cpl","a");
                 emitcode("add","a,#1");
-                emitcode("","!tlabeldef", lbl->key+100);
+                emitLabel (lbl);
                 aopPut(result,"a",0);
                 emitcode("pop","acc");
                 lbl = newiTempLabel(NULL);
                 emitcode("jnb","F0,!tlabel",lbl->key+100);
                 emitcode("cpl","a");
                 emitcode("addc","a,#0");
-                emitcode("","!tlabeldef", lbl->key+100);
+                emitLabel (lbl);
                 aopPut(result,"a",1);
         }
         freeAsmop (result, NULL, ic, TRUE);
@@ -5972,7 +6027,7 @@ static void genDivTwoByte (operand *left, operand *right,
         lbl = newiTempLabel(NULL);
         emitcode ("jnb","F1,!tlabel",lbl->key+100);
         emitcode ("setb","EA");
-        emitcode("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         return ;
 }
 
@@ -5986,7 +6041,7 @@ genDiv (iCode * ic)
   operand *right = IC_RIGHT (ic);
   operand *result = IC_RESULT (ic);
 
-  D (emitcode (";", "genDiv "));
+  D (emitcode (";", "genDiv"));
 
   /* assign the amsops */
   AOP_OP_2 (ic);
@@ -6033,7 +6088,7 @@ genModbits (operand * left,
   char *l;
   bool pushedB;
 
-  D(emitcode (";     genModbits",""));
+  D (emitcode (";", "genModbits"));
 
   pushedB = pushB ();
 
@@ -6064,7 +6119,7 @@ genModOneByte (operand * left,
   symbol *lbl;
   int size, offset;
 
-  D(emitcode (";     genModOneByte",""));
+  D (emitcode (";", "genModOneByte"));
 
   offset = 1;
   lUnsigned = SPEC_USIGN (getSpec (operandType (left)));
@@ -6095,7 +6150,7 @@ genModOneByte (operand * left,
   /* modulus: sign of the right operand has no influence on the result! */
   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);
@@ -6113,7 +6168,7 @@ genModOneByte (operand * left,
           emitcode ("jnb", "acc.7,!tlabel", lbl->key + 100);
           emitcode ("cpl", "a");  /* 2's complement */
           emitcode ("inc", "a");
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
           emitcode ("mov", "b,a");
         }
     }
@@ -6127,7 +6182,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)
         {
@@ -6151,7 +6206,7 @@ genModOneByte (operand * left,
           emitcode ("setb", "F0"); /* set sign flag */
           emitcode ("cpl", "a");   /* 2's complement */
           emitcode ("inc", "a");
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
         }
     }
 
@@ -6167,7 +6222,7 @@ genModOneByte (operand * left,
         emitcode ("jnb", "F0,!tlabel", lbl->key + 100);
       emitcode ("cpl", "a"); /* lsb 2's complement */
       emitcode ("inc", "a");
-      emitcode ("", "!tlabeldef", lbl->key + 100);
+      emitLabel (lbl);
 
       _G.accInUse++;
       aopOp (result, ic, TRUE, FALSE);
@@ -6224,7 +6279,7 @@ static void genModTwoByte (operand *left, operand *right,
         emitcode ("setb","F1");
         emitcode ("jbc","EA,!tlabel",lbl->key+100);
         emitcode ("clr","F1");
-        emitcode("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
 
         if (!umult) {
                 lbl = newiTempLabel(NULL);
@@ -6237,7 +6292,7 @@ static void genModTwoByte (operand *left, operand *right,
                 emitcode ("xch", "a,b");
                 emitcode ("cpl", "a"); // msb
                 emitcode ("addc","a,#0");
-                emitcode ("","!tlabeldef",lbl->key+100);
+                emitLabel (lbl);
                 emitcode ("mov","ma,b");
                 emitcode ("mov","ma,a");
         } else {
@@ -6248,7 +6303,7 @@ static void genModTwoByte (operand *left, operand *right,
         /* load up MB with right */
         if (!umult) {
                 if (AOP_TYPE(right) == AOP_LIT) {
-                        int val=(int)floatFromVal (AOP (right)->aopu.aop_lit);
+                        int val=(int) ulFromVal (AOP (right)->aopu.aop_lit);
                         if (val < 0) {
                                 val = -val;
                         }
@@ -6265,7 +6320,7 @@ static void genModTwoByte (operand *left, operand *right,
                         emitcode ("xch", "a,b");
                         emitcode ("cpl", "a"); // msb
                         emitcode ("addc", "a,#0");
-                        emitcode ("","!tlabeldef",lbl->key+100);
+                        emitLabel (lbl);
                         emitcode ("mov","mb,b");
                         emitcode ("mov","mb,a");
                 }
@@ -6276,7 +6331,7 @@ static void genModTwoByte (operand *left, operand *right,
 
         /* wait for multiplication to finish */
         lbl = newiTempLabel(NULL);
-        emitcode("","!tlabeldef", lbl->key+100);
+        emitLabel (lbl);
         emitcode("mov","a,mcnt1");
         emitcode("anl","a,#!constbyte",0x80);
         emitcode("jnz","!tlabel",lbl->key+100);
@@ -6293,8 +6348,7 @@ static void genModTwoByte (operand *left, operand *right,
         lbl = newiTempLabel(NULL);
         emitcode ("jnb","F1,!tlabel",lbl->key+100);
         emitcode ("setb","EA");
-        emitcode("","!tlabeldef",lbl->key+100);
-        return ;
+        emitLabel (lbl);
 }
 
 /*-----------------------------------------------------------------*/
@@ -6307,7 +6361,7 @@ genMod (iCode * ic)
   operand *right = IC_RIGHT (ic);
   operand *result = IC_RESULT (ic);
 
-  D (emitcode (";", "genMod "));
+  D (emitcode (";", "genMod"));
 
   /* assign the asmops */
   AOP_OP_2 (ic);
@@ -6348,12 +6402,15 @@ release:
 /* genIfxJump :- will create a jump depending on the ifx           */
 /*-----------------------------------------------------------------*/
 static void
-genIfxJump (iCode * ic, char *jval)
+genIfxJump (iCode * ic, char *jval, iCode *popIc)
 {
   symbol *jlbl;
   symbol *tlbl = newiTempLabel (NULL);
   char *inst;
 
+  /* if there is something to be popped then do it first */
+  popForBranch (popIc, TRUE);
+
   D (emitcode (";", "genIfxJump"));
 
   /* if true label then we jump if condition
@@ -6376,7 +6433,7 @@ genIfxJump (iCode * ic, char *jval)
   else
     emitcode (inst, "!tlabel", tlbl->key + 100);
   emitcode ("ljmp", "!tlabel", jlbl->key + 100);
-  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  emitLabel (tlbl);
 
   /* mark the icode as generated */
   ic->generated = 1;
@@ -6420,13 +6477,13 @@ genCmp (operand * left, operand * right,
                     aopGet (left, offset, FALSE, FALSE, NULL),
                     aopGet (right, offset, FALSE, FALSE, NULL),
                     lbl->key + 100);
-          emitcode ("", "!tlabeldef", lbl->key + 100);
+          emitLabel (lbl);
         }
       else
         {
           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)
                 {
@@ -6446,7 +6503,7 @@ genCmp (operand * left, operand * right,
                       if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx)
                         {
                           freeAsmop (result, NULL, ic, TRUE);
-                          genIfxJump (ifx, "acc.7");
+                          genIfxJump (ifx, "acc.7", ic->next);
                           return;
                         }
                       else
@@ -6470,8 +6527,7 @@ genCmp (operand * left, operand * right,
                   emitcode ("xrl", "a,#!constbyte",0x80);
                   if (AOP_TYPE (right) == AOP_LIT)
                     {
-                      unsigned long lit = (unsigned long)
-                      floatFromVal (AOP (right)->aopu.aop_lit);
+                      unsigned long lit = ulFromVal (AOP (right)->aopu.aop_lit);
                       // emitcode (";", "genCmp #3.1");
                       emitcode ("subb", "a,#!constbyte",
                                 0x80 ^ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL));
@@ -6521,7 +6577,7 @@ release_freedLR:
          code a little differently */
       if (ifx)
         {
-          genIfxJump (ifx, "c");
+          genIfxJump (ifx, "c", ic->next);
         }
       else
         {
@@ -6567,7 +6623,7 @@ genCmpLt (iCode * ic, iCode * ifx)
   sym_link *letype, *retype;
   int sign;
 
-  D (emitcode (";", "genCmpLt "));
+  D (emitcode (";", "genCmpLt"));
 
   left = IC_LEFT (ic);
   right = IC_RIGHT (ic);
@@ -6597,7 +6653,7 @@ 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) ||
       (IS_AOP_PREG (right) && !IS_AOP_PREG (left)))
     {
@@ -6607,7 +6663,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 (opIsGptr (left) || opIsGptr (right))
     {
@@ -6682,9 +6738,9 @@ gencjne (operand * left, operand * right, symbol * lbl)
 
   emitcode ("mov", "a,%s", one);
   emitcode ("sjmp", "!tlabel", tlbl->key + 100);
-  emitcode ("", "!tlabeldef", lbl->key + 100);
+  emitLabel (lbl);
   emitcode ("clr", "a");
-  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  emitLabel (tlbl);
 }
 
 /*-----------------------------------------------------------------*/
@@ -6694,6 +6750,7 @@ static void
 genCmpEq (iCode * ic, iCode * ifx)
 {
   operand *left, *right, *result;
+  iCode * popIc = ic->next;
 
   D (emitcode (";", "genCmpEq"));
 
@@ -6722,7 +6779,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);
@@ -6744,7 +6801,7 @@ genCmpEq (iCode * ic, iCode * ifx)
               emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
               emitcode ("jb", "%s,!tlabel", AOP (right)->aopu.aop_dir, (lbl->key + 100));
               emitcode ("cpl", "c");
-              emitcode ("", "!tlabeldef", (lbl->key + 100));
+              emitLabel (lbl);
             }
           /* if true label then we jump if condition
              supplied is true */
@@ -6752,14 +6809,16 @@ genCmpEq (iCode * ic, iCode * ifx)
           if (IC_TRUE (ifx))
             {
               emitcode ("jnc", "!tlabel", tlbl->key + 100);
+              popForBranch (popIc, FALSE);
               emitcode ("ljmp", "!tlabel", IC_TRUE (ifx)->key + 100);
             }
           else
             {
               emitcode ("jc", "!tlabel", tlbl->key + 100);
+              popForBranch (popIc, FALSE);
               emitcode ("ljmp", "!tlabel", IC_FALSE (ifx)->key + 100);
             }
-          emitcode ("", "!tlabeldef", tlbl->key + 100);
+          emitLabel (tlbl);
         }
       else
         {
@@ -6767,16 +6826,18 @@ genCmpEq (iCode * ic, iCode * ifx)
           gencjneshort (left, right, tlbl);
           if (IC_TRUE (ifx))
             {
+              popForBranch (popIc, FALSE);
               emitcode ("ljmp", "!tlabel", IC_TRUE (ifx)->key + 100);
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
             }
           else
             {
               symbol *lbl = newiTempLabel (NULL);
               emitcode ("sjmp", "!tlabel", lbl->key + 100);
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
+              popForBranch (popIc, FALSE);
               emitcode ("ljmp", "!tlabel", IC_FALSE (ifx)->key + 100);
-              emitcode ("", "!tlabeldef", lbl->key + 100);
+              emitLabel (lbl);
             }
         }
       /* mark the icode as generated */
@@ -6793,7 +6854,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);
@@ -6815,7 +6876,7 @@ genCmpEq (iCode * ic, iCode * ifx)
           emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir);
           emitcode ("jb", "%s,!tlabel", AOP (right)->aopu.aop_dir, (lbl->key + 100));
           emitcode ("cpl", "c");
-          emitcode ("", "!tlabeldef", (lbl->key + 100));
+          emitLabel (lbl);
         }
 
       freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
@@ -6831,7 +6892,7 @@ genCmpEq (iCode * ic, iCode * ifx)
         }
       if (ifx)
         {
-          genIfxJump (ifx, "c");
+          genIfxJump (ifx, "c", popIc);
           goto release;
         }
       /* if the result is used in an arithmetic operation
@@ -6854,7 +6915,7 @@ genCmpEq (iCode * ic, iCode * ifx)
         }
       if (ifx)
         {
-          genIfxJump (ifx, "a");
+          genIfxJump (ifx, "a", popIc);
           goto release;
         }
       /* if the result is used in an arithmetic operation
@@ -6874,18 +6935,21 @@ release:
 static iCode *
 ifxForOp (operand * op, iCode * ic)
 {
+  iCode *ifxIc;
+
   /* if true symbol then needs to be assigned */
   if (IS_TRUE_SYMOP (op))
     return NULL;
 
   /* if this has register type condition and
+     while skipping ipop's (see bug 1509084),
      the next instruction is ifx with the same operand
      and live to of the operand is upto the ifx only then */
-  if (ic->next &&
-      ic->next->op == IFX &&
-      IC_COND (ic->next)->key == op->key &&
-      OP_SYMBOL (op)->liveTo <= ic->next->seq)
-    return ic->next;
+  for (ifxIc = ic->next; ifxIc && ifxIc->op == IPOP; ifxIc = ifxIc->next);
+  if (ifxIc && ifxIc->op == IFX &&
+      IC_COND (ifxIc)->key == op->key &&
+      OP_SYMBOL (op)->liveTo <= ifxIc->seq)
+    return ifxIc;
 
   return NULL;
 }
@@ -6908,22 +6972,25 @@ hasInc (operand *op, iCode *ic, int osize)
   if (IS_AGGREGATE(type->next)) return NULL;
   if (osize != (isize = getSize(type->next))) return NULL;
 
-  while (lic) {
+  while (lic)
+    {
       /* if operand of the form op = op + <sizeof *op> */
       if (lic->op == '+' && isOperandEqual(IC_LEFT(lic),op) &&
           isOperandEqual(IC_RESULT(lic),op) &&
           isOperandLiteral(IC_RIGHT(lic)) &&
-          operandLitValue(IC_RIGHT(lic)) == isize) {
+          operandLitValue(IC_RIGHT(lic)) == isize)
+        {
           return lic;
-      }
+        }
       /* if the operand used or deffed */
-      if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) {
+      if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key)
+        {
           return NULL;
-      }
+        }
       /* if GOTO or IFX */
       if (lic->op == IFX || lic->op == GOTO || lic->op == LABEL) break;
       lic = lic->next;
-  }
+    }
   return NULL;
 }
 
@@ -6936,7 +7003,7 @@ genAndOp (iCode * ic)
   operand *left, *right, *result;
   symbol *tlbl;
 
-  D (emitcode (";", "genAndOp "));
+  D (emitcode (";", "genAndOp"));
 
   /* note here that && operations that are in an
      if statement are taken away by backPatchLabels
@@ -6962,14 +7029,15 @@ genAndOp (iCode * ic)
       toBoolean (left);
       emitcode ("jz", "!tlabel", tlbl->key + 100);
       toBoolean (right);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
       freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
 
       aopOp (result,ic,FALSE, FALSE);
       outBitAcc (result);
     }
-    freeAsmop (result, NULL, ic, TRUE);
+
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 
@@ -6982,7 +7050,7 @@ genOrOp (iCode * ic)
   operand *left, *right, *result;
   symbol *tlbl;
 
-  D (emitcode (";", "genOrOp "));
+  D (emitcode (";", "genOrOp"));
 
   /* note here that || operations that are in an
      if statement are taken away by backPatchLabels
@@ -7009,7 +7077,7 @@ genOrOp (iCode * ic)
       toBoolean (left);
       emitcode ("jnz", "!tlabel", tlbl->key + 100);
       toBoolean (right);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
       freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE));
 
@@ -7076,14 +7144,14 @@ jmpTrueOrFalse (iCode * ic, symbol * tlbl)
     {
       symbol *nlbl = newiTempLabel (NULL);
       emitcode ("sjmp", "!tlabel", nlbl->key + 100);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       emitcode ("ljmp", "!tlabel", IC_TRUE (ic)->key + 100);
-      emitcode ("", "!tlabeldef", nlbl->key + 100);
+      emitLabel (nlbl);
     }
   else
     {
       emitcode ("ljmp", "!tlabel", IC_FALSE (ic)->key + 100);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
     }
   ic->generated = 1;
 }
@@ -7160,10 +7228,10 @@ genAnd (iCode * ic, iCode * ifx)
   }
 
 #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
@@ -7197,7 +7265,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);
 
@@ -7254,7 +7322,7 @@ genAnd (iCode * ic, iCode * ifx)
         outBitC (result);
       // if(bit & ...)
       else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
-        genIfxJump (ifx, "c");
+        genIfxJump (ifx, "c", ic->next);
       goto release;
     }
 
@@ -7290,12 +7358,12 @@ genAnd (iCode * ic, iCode * ifx)
                 {
                   SNPRINTF (buffer, sizeof(buffer),
                             "acc.%d", posbit & 0x07);
-                  genIfxJump (ifx, buffer);
+                  genIfxJump (ifx, buffer, ic->next);
                 }
               else
-                  {
-                      emitcode ("anl","a,#!constbyte",1 << (posbit & 0x07));
-                  }
+                {
+                  emitcode ("anl","a,#!constbyte",1 << (posbit & 0x07));
+                }
               goto release;
             }
         }
@@ -7327,7 +7395,7 @@ genAnd (iCode * ic, iCode * ifx)
           if (size)
             {
               emitcode ("clr", "c");
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
             }
           // if(left & literal)
           else
@@ -7335,7 +7403,7 @@ genAnd (iCode * ic, iCode * ifx)
               if (ifx)
                 jmpTrueOrFalse (ifx, tlbl);
               else
-                emitcode ("", "!tlabeldef", tlbl->key + 100);
+                emitLabel (tlbl);
               goto release;
             }
         }
@@ -7378,20 +7446,34 @@ genAnd (iCode * ic, iCode * ifx)
           else
             {
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("anl", "a,%s",
-                          aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("anl", "a,b");
+                  aopPut (result, "a", offset);
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  aopPut (result, "a", offset);
+                }
               else
                 {
                   MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
                   if (IS_AOP_PREG (result))
                     {
-                      emitcode ("anl", "a,%s",
-                                aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
+                      emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
                       aopPut (result, "a", offset);
                     }
                   else
-                    emitcode ("anl", "%s,a",
-                              aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
+                    emitcode ("anl", "%s,a", aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
                 }
             }
         }
@@ -7410,38 +7492,59 @@ genAnd (iCode * ic, iCode * ifx)
             emitcode ("setb", "c");
           while (sizer--)
             {
-              if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
-                emitcode ("anl", "a,%s",
-                          aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
-              } else {
-                if (AOP_TYPE(left)==AOP_ACC)
+              if ((AOP_TYPE(right)==AOP_REG  || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+                  && AOP_TYPE(left)==AOP_ACC)
                 {
-                  bool pushedB = pushB ();
-                  emitcode("mov", "b,a");
-                  MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
-                  emitcode("anl", "a,b");
-                  popB (pushedB);
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, NULL));
                 }
-                else
+              else if (AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (!offset)
+                    {
+                      bool pushedB = pushB ();
+                      emitcode("mov", "b,a");
+                      MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                      emitcode("anl", "a,b");
+                      popB (pushedB);
+                    }
+                  else
+                    {
+                      MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                      emitcode("anl", "a,b");
+                    }
+                }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("anl", "a,b");
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else
                 {
                   MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
-                  emitcode ("anl", "a,%s",
-                            aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
                 }
-              }
+
               emitcode ("jnz", "!tlabel", tlbl->key + 100);
               offset++;
             }
           if (size)
             {
               CLRC;
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
               outBitC (result);
             }
           else if (ifx)
             jmpTrueOrFalse (ifx, tlbl);
           else
-            emitcode ("", "!tlabeldef", tlbl->key + 100);
+            emitLabel (tlbl);
         }
       else
         {
@@ -7467,34 +7570,63 @@ genAnd (iCode * ic, iCode * ifx)
                       aopPut (result, zero, offset);
                       continue;
                     }
-                  D (emitcode (";", "better literal AND."););
-                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
-                  emitcode ("anl", "a, %s", aopGet (right, offset,
-                                                    FALSE, FALSE, DP2_RESULT_REG));
-
+                  else if (AOP_TYPE (left) == AOP_ACC)
+                    {
+                      if (!offset)
+                        {
+                          emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, NULL));
+                          aopPut (result, "a", offset);
+                          continue;
+                        }
+                      else
+                        {
+                          emitcode ("anl", "b,%s", aopGet (right, offset, FALSE, FALSE, NULL));
+                          aopPut (result, "b", offset);
+                          continue;
+                        }
+                    }
                 }
-              else
+              // faster than result <- left, anl result,right
+              // and better if result is SFR
+              if ((AOP_TYPE(right)==AOP_REG  || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+                  && AOP_TYPE(left)==AOP_ACC)
                 {
-                  // faster than result <- left, anl result,right
-                  // and better if result is SFR
-                  if (AOP_TYPE (left) == AOP_ACC)
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, NULL));
+                }
+              else if (AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (!offset)
                     {
-                      emitcode ("anl", "a,%s",
-                                aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      bool pushedB = pushB ();
+                      emitcode("mov", "b,a");
+                      MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                      emitcode("anl", "a,b");
+                      popB (pushedB);
                     }
                   else
                     {
-                      char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
-                      if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
-                      {
-                          emitcode("mov", "b,a");
-                          rOp = "b";
-                      }
-
-                      MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
-                      emitcode ("anl", "a,%s", rOp);
+                      MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                      emitcode("anl", "a,b");
                     }
                 }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("anl", "a,b");
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else
+                {
+                  MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                  emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
               aopPut (result, "a", offset);
             }
         }
@@ -7518,7 +7650,7 @@ genOr (iCode * ic, iCode * ifx)
   int bytelit = 0;
   bool     pushResult;
 
-  D (emitcode (";", "genOr "));
+  D (emitcode (";", "genOr"));
 
   AOP_OP_3_NOFATAL (ic, pushResult);
   AOP_SET_LOCALS (ic);
@@ -7531,10 +7663,10 @@ genOr (iCode * ic, iCode * ifx)
 
 
 #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
@@ -7568,7 +7700,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);
 
@@ -7626,7 +7758,7 @@ genOr (iCode * ic, iCode * ifx)
               else
                 {
                   CLRC;
-                  emitcode ("", "!tlabeldef", tlbl->key + 100);
+                  emitLabel (tlbl);
                 }
             }
         }
@@ -7636,7 +7768,7 @@ genOr (iCode * ic, iCode * ifx)
         outBitC (result);
       // if(bit | ...)
       else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
-           genIfxJump (ifx, "c");
+        genIfxJump (ifx, "c", ic->next);
       goto release;
     }
 
@@ -7666,11 +7798,11 @@ genOr (iCode * ic, iCode * ifx)
               symbol *tlbl = newiTempLabel (NULL);
               emitcode ("jnz", "!tlabel", tlbl->key + 100);
               CLRC;
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
             }
           else
             {
-              genIfxJump (ifx, "a");
+              genIfxJump (ifx, "a", ic->next);
               goto release;
             }
         }
@@ -7716,8 +7848,22 @@ genOr (iCode * ic, iCode * ifx)
             {
               if (AOP_TYPE (left) == AOP_ACC)
                 {
-                  emitcode ("orl", "a,%s",
-                            aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  emitcode ("mov", "b,%s", aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("orl", "a,b");
+                  aopPut (result, "a", offset);
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  aopPut (result, "a", offset);
                 }
               else
                 {
@@ -7751,27 +7897,59 @@ genOr (iCode * ic, iCode * ifx)
             emitcode ("setb", "c");
           while (sizer--)
             {
-              if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
-                emitcode ("orl", "a,%s",
-                          aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
-              } else {
-                MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
-                emitcode ("orl", "a,%s",
-                          aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+              if ((AOP_TYPE(right)==AOP_REG  || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+                  && AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else if (AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (!offset)
+                    {
+                      bool pushedB = pushB ();
+                      emitcode("mov", "b,a");
+                      MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      emitcode("orl", "a,b");
+                      popB (pushedB);
+                    }
+                  else
+                    {
+                      MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      emitcode("orl", "a,b");
+                    }
+                }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("orl", "a,b");
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else
+                {
+                  MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                  emitcode ("orl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
               }
+
               emitcode ("jnz", "!tlabel", tlbl->key + 100);
               offset++;
             }
           if (size)
             {
               CLRC;
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
               outBitC (result);
             }
           else if (ifx)
             jmpTrueOrFalse (ifx, tlbl);
           else
-            emitcode ("", "!tlabeldef", tlbl->key + 100);
+            emitLabel (tlbl);
         }
       else
         {
@@ -7798,37 +7976,48 @@ genOr (iCode * ic, iCode * ifx)
                       aopPut (result, "#0xFF", offset);
                       continue;
                     }
-                  D (emitcode (";", "better literal OR."););
-                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
-                  emitcode ("orl", "a, %s",
-                            aopGet (right, offset,
-                                    FALSE, FALSE, DP2_RESULT_REG));
-
                 }
-              else
+              // faster than result <- left, orl result,right
+              // and better if result is SFR
+              if ((AOP_TYPE(right)==AOP_REG  || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+                  && AOP_TYPE(left)==AOP_ACC)
                 {
-                  // faster than result <- left, anl result,right
-                  // and better if result is SFR
-                  if (AOP_TYPE (left) == AOP_ACC)
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else if (AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (!offset)
                     {
-                      emitcode ("orl", "a,%s",
-                                aopGet (right, offset,
-                                        FALSE, FALSE, DP2_RESULT_REG));
+                      bool pushedB = pushB ();
+                      emitcode("mov", "b,a");
+                      MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      emitcode("orl", "a,b");
+                      popB (pushedB);
                     }
                   else
                     {
-                      char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
-
-                      if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
-                      {
-                          emitcode("mov", "b,a");
-                          rOp = "b";
-                      }
-
-                      MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
-                      emitcode ("orl", "a,%s", rOp);
+                      MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      emitcode("orl", "a,b");
                     }
                 }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("orl", "a,b");
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else
+                {
+                  MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                  emitcode ("orl", "a,%s", aopGet (left, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
               aopPut (result, "a", offset);
             }
             _endLazyDPSEvaluation();
@@ -7853,7 +8042,7 @@ genXor (iCode * ic, iCode * ifx)
   int bytelit = 0;
   bool pushResult;
 
-  D (emitcode (";", "genXor "));
+  D (emitcode (";", "genXor"));
 
   AOP_OP_3_NOFATAL (ic, pushResult);
   AOP_SET_LOCALS (ic);
@@ -7865,10 +8054,10 @@ genXor (iCode * ic, iCode * ifx)
   }
 
 #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
@@ -7902,8 +8091,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);
 
@@ -7952,7 +8142,6 @@ genXor (iCode * ic, iCode * ifx)
                     }
                 }
             }
-
         }
       else
         {
@@ -7983,15 +8172,15 @@ genXor (iCode * ic, iCode * ifx)
             }
           emitcode ("jnb", "%s,!tlabel", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
           emitcode ("cpl", "c");
-          emitcode ("", "!tlabeldef", (tlbl->key + 100));
+          emitLabel (tlbl);
         }
       // bit = c
       // val = c
       if (size)
         outBitC (result);
-      // if(bit | ...)
+      // if(bit ^ ...)
       else if ((AOP_TYPE (result) == AOP_CRY) && ifx)
-        genIfxJump (ifx, "c");
+        genIfxJump (ifx, "c", ic->next);
       goto release;
     }
 
@@ -8028,8 +8217,24 @@ genXor (iCode * ic, iCode * ifx)
           else
             {
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("xrl", "a,%s",
-                          aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("xrl", "a,b");
+                  aopPut (result, "a", offset);
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  aopPut (result, "a", offset);
+                }
               else
                 {
                   MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
@@ -8066,30 +8271,53 @@ genXor (iCode * ic, iCode * ifx)
                 {
                   MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
                 }
+              else if ((AOP_TYPE(right)==AOP_REG  || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+                  && AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else if (AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (!offset)
+                    {
+                      bool pushedB = pushB ();
+                      emitcode("mov", "b,a");
+                      MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      emitcode("xrl", "a,b");
+                      popB (pushedB);
+                    }
+                  else
+                    {
+                      MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                      emitcode("xrl", "a,b");
+                    }
+                }
+              else if (aopGetUsesAcc (left, offset) && aopGetUsesAcc (right, offset))
+                {
+                  MOVB (aopGet (left, offset, FALSE, FALSE, NULL));
+                  MOVA (aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                  emitcode ("xrl", "a,b");
+                }
+              else if (aopGetUsesAcc (left, offset))
+                {
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
               else
                 {
-                  if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
-                    emitcode ("xrl", "a,%s",
-                              aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
-                  } else {
-                      char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
-                      if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
-                      {
-                          emitcode("mov", "b,a");
-                          rOp = "b";
-                      }
-
-                      MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
-                      emitcode ("xrl", "a,%s", rOp);
-                  }
+                  MOVA (aopGet (right, offset, FALSE, FALSE, NULL));
+                  emitcode ("xrl", "a,%s", aopGet (left, offset, FALSE, TRUE, DP2_RESULT_REG));
                 }
+
               emitcode ("jnz", "!tlabel", tlbl->key + 100);
               offset++;
             }
           if (size)
             {
               CLRC;
-              emitcode ("", "!tlabeldef", tlbl->key + 100);
+              emitLabel (tlbl);
               outBitC (result);
             }
           else if (ifx)
@@ -8097,50 +8325,50 @@ genXor (iCode * ic, iCode * ifx)
         }
       else
         {
-        for (; (size--); offset++)
-          {
-            // normal case
-            // result = left ^ right
-            if (AOP_TYPE (right) == AOP_LIT)
-              {
-                bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL);
-                if (bytelit == 0)
-                  {
-                    aopPut (result,
-                            aopGet (left, offset, FALSE, FALSE, NULL),
-                            offset);
-                    continue;
-                  }
-                D (emitcode (";", "better literal XOR."););
-                MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
-                emitcode ("xrl", "a, %s",
-                          aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
-              }
-            else
-              {
-                // faster than result <- left, anl result,right
-                // and better if result is SFR
-                if (AOP_TYPE (left) == AOP_ACC)
-                  {
-                    emitcode ("xrl", "a,%s",
-                              aopGet (right, offset,
-                                      FALSE, FALSE, DP2_RESULT_REG));
-                  }
-                else
-                  {
+          for (; (size--); offset++)
+            {
+              // normal case
+              // result = left ^ right
+              if (AOP_TYPE (right) == AOP_LIT)
+                {
+                  bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL);
+                  if (bytelit == 0)
+                    {
+                      aopPut (result,
+                              aopGet (left, offset, FALSE, FALSE, NULL),
+                              offset);
+                      continue;
+                    }
+                  D (emitcode (";", "better literal XOR."));
+                  MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
+                  emitcode ("xrl", "a, %s",
+                            aopGet (right, offset, FALSE, FALSE, DP2_RESULT_REG));
+                }
+              else
+                {
+                  // faster than result <- left, anl result,right
+                  // and better if result is SFR
+                  if (AOP_TYPE (left) == AOP_ACC)
+                    {
+                      emitcode ("xrl", "a,%s",
+                                aopGet (right, offset,
+                                        FALSE, FALSE, DP2_RESULT_REG));
+                    }
+                  else
+                    {
                       char *rOp = aopGet (right, offset, FALSE, FALSE, NULL);
                       if (!strcmp(rOp, "a") || !strcmp(rOp, "acc"))
-                      {
+                        {
                           emitcode("mov", "b,a");
                           rOp = "b";
-                      }
+                        }
 
                       MOVA (aopGet (left, offset, FALSE, FALSE, NULL));
                       emitcode ("xrl", "a,%s", rOp);
-                  }
-              }
-            aopPut (result, "a", offset);
-          }
+                    }
+                }
+              aopPut (result, "a", offset);
+            }
         }
     }
 
@@ -8157,40 +8385,51 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
-  D (emitcode (";", "genInline "));
+  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);
 }
 
@@ -8202,7 +8441,7 @@ genRRC (iCode * ic)
 {
   operand *left, *result;
   int     size, offset;
-  char *l;
+  char    *l;
 
   D (emitcode (";", "genRRC"));
 
@@ -8251,7 +8490,7 @@ genRLC (iCode * ic)
   int size, offset;
   char *l;
 
-  D (emitcode (";", "genRLC "));
+  D (emitcode (";", "genRLC"));
 
   /* rotate right with carry */
   left = IC_LEFT (ic);
@@ -8321,7 +8560,7 @@ genGetHbit (iCode * ic)
   else
     {
       emitcode ("rl", "a");
-      emitcode ("anl", "a,#1");
+      emitcode ("anl", "a,#0x01");
       outAcc (result);
     }
 
@@ -8338,7 +8577,7 @@ genSwap (iCode * ic)
 {
   operand *left, *result;
 
-  D(emitcode (";     genSwap",""));
+  D(emitcode (";", "genSwap"));
 
   left = IC_LEFT (ic);
   result = IC_RESULT (ic);
@@ -8514,7 +8753,7 @@ AccSRsh (int shCount)
           emitcode ("jnb", "acc.%d,!tlabel", 7 - shCount, tlbl->key + 100);
           emitcode ("orl", "a,#!constbyte",
                     (unsigned char) ~SRMask[shCount]);
-          emitcode ("", "!tlabeldef", tlbl->key + 100);
+          emitLabel (tlbl);
         }
     }
 }
@@ -8570,16 +8809,16 @@ movLeft2Result (operand * left, int offl,
       l = aopGet (left, offl, FALSE, FALSE, NULL);
 
       if (*l == '@' && (IS_AOP_PREG (result)))
-      {
+        {
           emitcode ("mov", "a,%s", l);
           aopPut (result, "a", offr);
-      }
+        }
       else
-      {
+        {
           if (!sign)
-          {
-            aopPut (result, l, offr);
-          }
+            {
+              aopPut (result, l, offr);
+            }
           else
             {
               /* MSB sign in acc.7 ! */
@@ -8589,8 +8828,8 @@ movLeft2Result (operand * left, int offl,
                   aopPut (result, "a", offr);
                 }
             }
-      }
-  }
+        }
+    }
 }
 #endif
 
@@ -8871,7 +9110,7 @@ AccAXRshS (char *x, int shCount)
       emitcode ("orl", "a,#!constbyte",
                 (unsigned char) ~SRMask[shCount]);      // 111AAAAA:BBBCCCCC
 
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       break;                            // SSSSAAAA:BBBCCCCC
 
     case 6:                             // AABBBBBB:CCDDDDDD
@@ -8890,7 +9129,7 @@ AccAXRshS (char *x, int shCount)
       emitcode ("orl", "a,#!constbyte",
                 (unsigned char) ~SRMask[shCount]);      // 111111AA:BBBBBBCC
 
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       break;
     case 7:                             // ABBBBBBB:CDDDDDDD
 
@@ -8907,7 +9146,7 @@ AccAXRshS (char *x, int shCount)
       emitcode ("orl", "a,#!constbyte",
                 (unsigned char) ~SRMask[shCount]);      // 1111111A:BBBBBBBC
 
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       break;
     default:
       break;
@@ -9091,7 +9330,7 @@ shiftRLeftOrResult (operand * left, int offl,
 static void
 genlshOne (operand * result, operand * left, int shCount)
 {
-  D (emitcode (";", "genlshOne "));
+  D (emitcode (";", "genlshOne"));
 
   shiftL1Left2Result (left, LSB, result, LSB, shCount);
 }
@@ -9112,7 +9351,7 @@ genlshTwo (operand * result, operand * left, int shCount)
 
   /* if shCount >= 8 */
   if (shCount >= 8)
-  {
+    {
       shCount -= 8;
 
       _startLazyDPSEvaluation();
@@ -9120,19 +9359,19 @@ genlshTwo (operand * result, operand * left, int shCount)
       if (size > 1)
         {
           if (shCount)
-          {
-            _endLazyDPSEvaluation();
-            shiftL1Left2Result (left, LSB, result, MSB16, shCount);
-            aopPut (result, zero, LSB);
-          }
+            {
+              _endLazyDPSEvaluation();
+              shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+              aopPut (result, zero, LSB);
+            }
           else
-          {
-            movLeft2Result (left, LSB, result, MSB16, 0);
-            aopPut (result, zero, LSB);
-            _endLazyDPSEvaluation();
-          }
+            {
+              movLeft2Result (left, LSB, result, MSB16, 0);
+              aopPut (result, zero, LSB);
+              _endLazyDPSEvaluation();
+            }
         }
-        else
+      else
         {
           aopPut (result, zero, LSB);
           _endLazyDPSEvaluation();
@@ -9146,7 +9385,7 @@ genlshTwo (operand * result, operand * left, int shCount)
         shiftL1Left2Result (left, LSB, result, LSB, shCount);
       else
         shiftL2Left2Result (left, LSB, result, LSB, shCount);
-      }
+    }
 }
 #endif
 
@@ -9232,7 +9471,7 @@ genlshFour (operand * result, operand * left, int shCount)
 {
   int size;
 
-  D (emitcode (";", "genlshFour "));
+  D (emitcode (";", "genlshFour"));
 
   size = AOP_SIZE (result);
 
@@ -9330,12 +9569,12 @@ 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;
 
   size = getSize (operandType (result));
 
-  D(emitcode (";", "genLeftShiftLiteral (%d), size %d", shCount, size););
+  D (emitcode (";", "genLeftShiftLiteral (%d), size %d", shCount, size););
 
   /* We only handle certain easy cases so far. */
   if ((shCount != 0)
@@ -9378,25 +9617,25 @@ genLeftShiftLiteral (operand * left,
 
   /* I suppose that the left size >= result size */
   if (shCount == 0)
-  {
-        _startLazyDPSEvaluation();
-        while (size--)
+    {
+      _startLazyDPSEvaluation();
+      while (size--)
         {
           movLeft2Result (left, size, result, size, 0);
         }
-        _endLazyDPSEvaluation();
-  }
+      _endLazyDPSEvaluation();
+    }
   else if (shCount >= (size * 8))
-  {
-    _startLazyDPSEvaluation();
-    while (size--)
     {
-      aopPut (result, zero, size);
+      _startLazyDPSEvaluation();
+      while (size--)
+        {
+          aopPut (result, zero, size);
+        }
+      _endLazyDPSEvaluation();
     }
-    _endLazyDPSEvaluation();
-  }
   else
-  {
+    {
       switch (size)
         {
         case 1:
@@ -9412,7 +9651,8 @@ genLeftShiftLiteral (operand * left,
           break;
 #endif
         default:
-          fprintf(stderr, "*** ack! mystery literal shift!\n");
+          werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+                  "*** ack! mystery literal shift!\n");
           break;
         }
     }
@@ -9434,7 +9674,7 @@ genLeftShift (iCode * ic)
   symbol *tlbl, *tlbl1;
   bool pushedB;
 
-  D (emitcode (";", "genLeftShift "));
+  D (emitcode (";", "genLeftShift"));
 
   right = IC_RIGHT (ic);
   left = IC_LEFT (ic);
@@ -9469,7 +9709,7 @@ genLeftShift (iCode * ic)
        * some small improvement.
        */
        emitcode("mov", "b,#!constbyte",
-                ((int) floatFromVal (AOP (right)->aopu.aop_lit)) + 1);
+                ((int) ulFromVal (AOP (right)->aopu.aop_lit)) + 1);
   }
   else
   {
@@ -9517,9 +9757,9 @@ genLeftShift (iCode * ic)
       l = aopGet (left, 0, FALSE, FALSE, NULL);
       MOVA (l);
       emitcode ("sjmp", "!tlabel", tlbl1->key + 100);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       emitcode ("add", "a,acc");
-      emitcode ("", "!tlabeldef", tlbl1->key + 100);
+      emitLabel (tlbl1);
       emitcode ("djnz", "b,!tlabel", tlbl->key + 100);
       popB (pushedB);
       aopPut (result, "a", 0);
@@ -9529,7 +9769,7 @@ genLeftShift (iCode * ic)
   reAdjustPreg (AOP (result));
 
   emitcode ("sjmp", "!tlabel", tlbl1->key + 100);
-  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  emitLabel (tlbl);
   l = aopGet (result, offset, FALSE, FALSE, NULL);
   MOVA (l);
   emitcode ("add", "a,acc");
@@ -9545,7 +9785,7 @@ genLeftShift (iCode * ic)
   _endLazyDPSEvaluation ();
   reAdjustPreg (AOP (result));
 
-  emitcode ("", "!tlabeldef", tlbl1->key + 100);
+  emitLabel (tlbl1);
   emitcode ("djnz", "b,!tlabel", tlbl->key + 100);
   popB (pushedB);
 release:
@@ -9562,6 +9802,7 @@ genrshOne (operand * result, operand * left,
            int shCount, int sign)
 {
   D (emitcode (";", "genrshOne"));
+
   shiftR1Left2Result (left, LSB, result, LSB, shCount, sign);
 }
 #endif
@@ -9603,12 +9844,13 @@ static void
 shiftRLong (operand * left, int offl,
             operand * result, int sign)
 {
-  int isSameRegs=sameRegs(AOP(left),AOP(result));
+  bool overlapping = regsInCommon (left, result) || operandsEqu(left, result);
 
-  if (isSameRegs && offl>1) {
-    // we are in big trouble, but this shouldn't happen
-    werror(E_INTERNAL_ERROR, __FILE__, __LINE__);
-  }
+  if (overlapping && offl>1)
+    {
+      // we are in big trouble, but this shouldn't happen
+      werror(E_INTERNAL_ERROR, __FILE__, __LINE__);
+    }
 
   MOVA (aopGet (left, MSB32, FALSE, FALSE, NULL));
 
@@ -9639,28 +9881,44 @@ shiftRLong (operand * left, int offl,
 
   emitcode ("rrc", "a");
 
-  if (isSameRegs && offl==MSB16) {
-    emitcode ("xch",
-              "a,%s",aopGet (left, MSB24, FALSE, FALSE, DP2_RESULT_REG));
-  } else {
-    aopPut (result, "a", MSB32);
-    MOVA (aopGet (left, MSB24, FALSE, FALSE, NULL));
-  }
+  if (overlapping && offl==MSB16)
+    {
+      emitcode ("xch", "a,%s", aopGet (left, MSB24, FALSE, FALSE, DP2_RESULT_REG));
+    }
+  else
+    {
+      aopPut (result, "a", MSB32 - offl);
+      MOVA (aopGet (left, MSB24, FALSE, FALSE, NULL));
+    }
 
   emitcode ("rrc", "a");
-  if (isSameRegs && offl==1) {
-    emitcode ("xch", "a,%s",
-              aopGet (left, MSB16, FALSE, FALSE, DP2_RESULT_REG));
-  } else {
-    aopPut (result, "a", MSB24);
-    MOVA (aopGet (left, MSB16, FALSE, FALSE, NULL));
-  }
-  emitcode ("rrc", "a");
-  aopPut (result, "a", MSB16 - offl);
 
-  if (offl == LSB)
+  if (overlapping && offl==MSB16)
+    {
+      emitcode ("xch", "a,%s", aopGet (left, MSB16, FALSE, FALSE, DP2_RESULT_REG));
+    }
+  else
+    {
+      aopPut (result, "a", MSB24 - offl);
+      MOVA (aopGet (left, MSB16, FALSE, FALSE, NULL));
+    }
+
+  emitcode ("rrc", "a");
+  if (offl != LSB)
+    {
+      aopPut (result, "a", MSB16 - offl);
+    }
+  else
     {
-      MOVA (aopGet (left, LSB, FALSE, FALSE, NULL));
+      if (overlapping && offl==MSB16)
+        {
+          emitcode ("xch", "a,%s", aopGet (left, LSB, FALSE, FALSE, DP2_RESULT_REG));
+        }
+      else
+        {
+          aopPut (result, "a", MSB16 - offl);
+          MOVA (aopGet (left, LSB, FALSE, FALSE, NULL));
+        }
       emitcode ("rrc", "a");
       aopPut (result, "a", LSB);
     }
@@ -9707,7 +9965,7 @@ genrshFour (operand * result, operand * left,
       _startLazyDPSEvaluation();
       if (shCount == 1)
         {
-            shiftRLong (left, MSB16, result, sign);
+          shiftRLong (left, MSB16, result, sign);
         }
       else if (shCount == 0)
         {
@@ -9728,7 +9986,7 @@ genrshFour (operand * result, operand * left,
     }
   else
     {
-        /* 1 <= shCount <= 7 */
+      /* 1 <= shCount <= 7 */
       if (shCount <= 2)
         {
           shiftRLong (left, LSB, result, sign);
@@ -9755,7 +10013,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;
 
   size = getSize (operandType (result));
@@ -9787,20 +10045,20 @@ genRightShiftLiteral (operand * left,
 
   /* I suppose that the left size >= result size */
   if (shCount == 0)
-  {
+    {
       size = getDataSize (result);
       _startLazyDPSEvaluation();
       while (size--)
         movLeft2Result (left, size, result, size, 0);
       _endLazyDPSEvaluation();
-  }
+    }
   else if (shCount >= (size * 8))
     {
       if (sign)
-      {
-        /* get sign in acc.7 */
-        MOVA (aopGet (left, size - 1, FALSE, FALSE, NULL));
-      }
+        {
+          /* get sign in acc.7 */
+          MOVA (aopGet (left, size - 1, FALSE, FALSE, NULL));
+        }
       addSign (result, LSB, sign);
     }
   else
@@ -9876,7 +10134,7 @@ genSignedRightShift (iCode * ic)
        * some small improvement.
        */
        emitcode("mov", "b,#!constbyte",
-                ((int) floatFromVal (AOP (right)->aopu.aop_lit)) + 1);
+                ((int) ulFromVal (AOP (right)->aopu.aop_lit)) + 1);
   }
   else
   {
@@ -9927,10 +10185,10 @@ genSignedRightShift (iCode * ic)
       l = aopGet (left, 0, FALSE, FALSE, NULL);
       MOVA (l);
       emitcode ("sjmp", "!tlabel", tlbl1->key + 100);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       emitcode ("mov", "c,ov");
       emitcode ("rrc", "a");
-      emitcode ("", "!tlabeldef", tlbl1->key + 100);
+      emitLabel (tlbl1);
       emitcode ("djnz", "b,!tlabel", tlbl->key + 100);
       popB (pushedB);
       aopPut (result, "a", 0);
@@ -9939,7 +10197,7 @@ genSignedRightShift (iCode * ic)
 
   reAdjustPreg (AOP (result));
   emitcode ("sjmp", "!tlabel", tlbl1->key + 100);
-  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  emitLabel (tlbl);
   emitcode ("mov", "c,ov");
   _startLazyDPSEvaluation ();
   while (size--)
@@ -9951,7 +10209,7 @@ genSignedRightShift (iCode * ic)
     }
   _endLazyDPSEvaluation ();
   reAdjustPreg (AOP (result));
-  emitcode ("", "!tlabeldef", tlbl1->key + 100);
+  emitLabel (tlbl1);
   emitcode ("djnz", "b,!tlabel", tlbl->key + 100);
   popB (pushedB);
 
@@ -10024,7 +10282,7 @@ genRightShift (iCode * ic)
        * some small improvement.
        */
        emitcode("mov", "b,#!constbyte",
-                ((int) floatFromVal (AOP (right)->aopu.aop_lit)) + 1);
+                ((int) ulFromVal (AOP (right)->aopu.aop_lit)) + 1);
   }
   else
   {
@@ -10070,10 +10328,10 @@ genRightShift (iCode * ic)
       l = aopGet (left, 0, FALSE, FALSE, NULL);
       MOVA (l);
       emitcode ("sjmp", "!tlabel", tlbl1->key + 100);
-      emitcode ("", "!tlabeldef", tlbl->key + 100);
+      emitLabel (tlbl);
       CLRC;
       emitcode ("rrc", "a");
-      emitcode ("", "!tlabeldef", tlbl1->key + 100);
+      emitLabel (tlbl1);
       emitcode ("djnz", "b,!tlabel", tlbl->key + 100);
       popB (pushedB);
       aopPut (result, "a", 0);
@@ -10082,7 +10340,7 @@ genRightShift (iCode * ic)
 
   reAdjustPreg (AOP (result));
   emitcode ("sjmp", "!tlabel", tlbl1->key + 100);
-  emitcode ("", "!tlabeldef", tlbl->key + 100);
+  emitLabel (tlbl);
   CLRC;
   _startLazyDPSEvaluation ();
   while (size--)
@@ -10095,7 +10353,7 @@ genRightShift (iCode * ic)
   _endLazyDPSEvaluation ();
   reAdjustPreg (AOP (result));
 
-  emitcode ("", "!tlabeldef", tlbl1->key + 100);
+  emitLabel (tlbl1);
   emitcode ("djnz", "b,!tlabel", tlbl->key + 100);
   popB (pushedB);
 
@@ -10203,7 +10461,7 @@ genUnpackBits (operand * result, char *rname, int ptype)
   int blen;             /* bitfield length */
   int bstr;             /* bitfield starting bit within byte */
 
-  D(emitcode (";     genUnpackBits",""));
+  D(emitcode (";", "genUnpackBits"));
 
   etype = getSpec (operandType (result));
   rsize = getSize (operandType (result));
@@ -10223,7 +10481,7 @@ genUnpackBits (operand * result, char *rname, int ptype)
 
           emitcode ("jnb", "acc.%d,%05d$", blen - 1, tlbl->key + 100);
           emitcode ("orl", "a,#0x%02x", (unsigned char) (0xff << blen));
-          emitcode ("", "%05d$:", tlbl->key + 100);
+          emitLabel (tlbl);
         }
       aopPut (result, "a", offset++);
       goto finish;
@@ -10251,7 +10509,7 @@ genUnpackBits (operand * result, char *rname, int ptype)
 
           emitcode ("jnb", "acc.%d,%05d$", rlen - 1, tlbl->key + 100);
           emitcode ("orl", "a,#0x%02x", (unsigned char) (0xff << rlen));
-          emitcode ("", "%05d$:", tlbl->key + 100);
+          emitLabel (tlbl);
         }
       aopPut (result, "a", offset++);
     }
@@ -10297,15 +10555,13 @@ genDataPointerGet (operand * left,
   _startLazyDPSEvaluation ();
   while (size--)
     {
-        if (offset)
+      if (offset)
         {
-            SNPRINTF (buffer, sizeof(buffer),
-                      "(%s + %d)", l + 1, offset);
+          SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l + 1, offset);
         }
-        else
+      else
         {
-            SNPRINTF (buffer, sizeof(buffer),
-                      "%s", l + 1);
+          SNPRINTF (buffer, sizeof(buffer), "%s", l + 1);
         }
       aopPut (result, buffer, offset++);
     }
@@ -10392,9 +10648,9 @@ genNearPointerGet (operand * left,
             }
           offset++;
           if (size || pi)
-                emitcode ("inc", "%s", rname);
-            }
+            emitcode ("inc", "%s", rname);
         }
+    }
 
   /* now some housekeeping stuff */
   if (aop)      /* we had to allocate for this iCode */
@@ -10490,7 +10746,8 @@ genPagedPointerGet (operand * left,
   /* now some housekeeping stuff */
   if (aop)      /* we had to allocate for this iCode */
     {
-      if (pi) aopPut (left, rname, 0);
+      if (pi)
+        aopPut (left, rname, 0);
       freeAsmop (NULL, aop, ic, TRUE);
     }
   else
@@ -10524,7 +10781,7 @@ static void
 genFarPointerGet (operand * left,
                   operand * result, iCode * ic, iCode *pi)
 {
-    int size, offset, dopi=1;
+  int size, offset, dopi=1;
   sym_link *retype = getSpec (operandType (result));
   sym_link *letype = getSpec (operandType (left));
   D (emitcode (";", "genFarPointerGet"););
@@ -10566,7 +10823,7 @@ genFarPointerGet (operand * left,
           _endLazyDPSEvaluation ();
         }
     }
-  /* so dptr know contains the address */
+  /* so dptr now contains the address */
   aopOp (result, ic, FALSE, (AOP_INDPTRn(left) ? FALSE : TRUE));
 
   /* if bit then unpack */
@@ -10636,12 +10893,12 @@ genFarPointerGet (operand * left,
       }
   }
 
-  freeAsmop (left, NULL, ic, TRUE);
   freeAsmop (result, NULL, ic, TRUE);
+  freeAsmop (left, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
-/* genCodePointerGet - get value from code space                  */
+/* genCodePointerGet - get value from code space                   */
 /*-----------------------------------------------------------------*/
 static void
 genCodePointerGet (operand * left,
@@ -10686,7 +10943,7 @@ genCodePointerGet (operand * left,
           _endLazyDPSEvaluation ();
         }
     }
-  /* so dptr know contains the address */
+  /* so dptr now contains the address */
   aopOp (result, ic, FALSE, (AOP_INDPTRn(left) ? FALSE : TRUE));
 
   /* if bit then unpack */
@@ -10744,7 +11001,8 @@ genCodePointerGet (operand * left,
           _endLazyDPSEvaluation ();
       }
       pi->generated = 1;
-  } else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
+  } else if (IS_SYMOP(left) &&
+             (OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
              AOP_SIZE(result) > 1 &&
              (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
 
@@ -10763,7 +11021,7 @@ genCodePointerGet (operand * left,
 }
 
 /*-----------------------------------------------------------------*/
-/* genGenPointerGet - gget value from generic pointer space        */
+/* genGenPointerGet - get value from generic pointer space         */
 /*-----------------------------------------------------------------*/
 static void
 genGenPointerGet (operand * left,
@@ -10816,17 +11074,17 @@ genGenPointerGet (operand * left,
 
   /* if bit then unpack */
   if (IS_BITFIELD (retype) || IS_BITFIELD (letype))
-  {
-    genUnpackBits (result, "dptr", GPOINTER);
-  }
+    {
+      genUnpackBits (result, "dptr", GPOINTER);
+    }
   else
     {
-        size = AOP_SIZE (result);
-        offset = 0;
+      size = AOP_SIZE (result);
+      offset = 0;
 
-        while (size--)
+      while (size--)
         {
-            if (size)
+          if (size)
             {
                 // Get two bytes at a time, results in _AP & A.
                 // dptr will be incremented ONCE by __gptrgetWord.
@@ -10835,18 +11093,18 @@ genGenPointerGet (operand * left,
                 // with the implementation of __gptrgetWord
                 // in device/lib/_gptrget.c
                 emitcode ("lcall", "__gptrgetWord");
-                aopPut (result, DP2_RESULT_REG, offset++);
                 aopPut (result, "a", offset++);
+                aopPut (result, DP2_RESULT_REG, offset++);
                 size--;
             }
-            else
+          else
             {
                 // Only one byte to get.
                 emitcode ("lcall", "__gptrget");
                 aopPut (result, "a", offset++);
             }
 
-            if (size || (pi && AOP_TYPE (left) != AOP_IMMD))
+          if (size || (pi && AOP_TYPE (left) != AOP_IMMD))
             {
                 emitcode ("inc", "dptr");
             }
@@ -10888,7 +11146,7 @@ genPointerGet (iCode * ic, iCode *pi)
   sym_link *type, *etype;
   int p_type;
 
-  D (emitcode (";", "genPointerGet "));
+  D (emitcode (";", "genPointerGet"));
 
   left = IC_LEFT (ic);
   result = IC_RESULT (ic);
@@ -10899,7 +11157,9 @@ genPointerGet (iCode * ic, iCode *pi)
   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 */
@@ -10942,6 +11202,7 @@ genPointerGet (iCode * ic, iCode *pi)
     }
 }
 
+
 /*-----------------------------------------------------------------*/
 /* genPackBits - generates code for packed bit storage             */
 /*-----------------------------------------------------------------*/
@@ -10957,7 +11218,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);
@@ -10972,7 +11233,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);
@@ -11043,7 +11304,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);
@@ -11096,19 +11357,19 @@ genDataPointerSet (operand * right,
   while (size--)
     {
       if (offset)
-          SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l + 1, offset);
+        SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l + 1, offset);
       else
-          SNPRINTF (buffer, sizeof(buffer), "%s", l + 1);
+        SNPRINTF (buffer, sizeof(buffer), "%s", l + 1);
       emitcode ("mov", "%s,%s", buffer,
                 aopGet (right, offset++, FALSE, FALSE, NULL));
     }
 
-  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,
@@ -11121,7 +11382,7 @@ genNearPointerSet (operand * right,
   sym_link *retype, *letype;
   sym_link *ptype = operandType (result);
 
-  D(emitcode (";", "genNearPointerSet"));
+  D (emitcode (";", "genNearPointerSet"));
 
   retype = getSpec (operandType (right));
   letype = getSpec (ptype);
@@ -11165,14 +11426,14 @@ genNearPointerSet (operand * right,
     genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, rname, POINTER);
   else
     {
-      /* we have can just get the values */
+      /* we can just get the values */
       int size = AOP_SIZE (right);
       int offset = 0;
 
       while (size--)
         {
           l = aopGet (right, offset, FALSE, TRUE, NULL);
-          if (*l == '@')
+          if ((*l == '@') || (strcmp (l, "acc") == 0))
             {
               MOVA (l);
               emitcode ("mov", "@%s,a", rname);
@@ -11188,7 +11449,8 @@ genNearPointerSet (operand * right,
   /* now some housekeeping stuff */
   if (aop)      /* we had to allocate for this iCode */
     {
-      if (pi) aopPut (result,rname,0);
+      if (pi)
+        aopPut (result, rname, 0);
       freeAsmop (NULL, aop, ic, TRUE);
     }
   else
@@ -11211,9 +11473,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);
 }
 
 /*-----------------------------------------------------------------*/
@@ -11223,7 +11486,7 @@ static void
 genPagedPointerSet (operand * right,
                     operand * result,
                     iCode * ic,
-                    iCode *pi)
+                    iCode * pi)
 {
   asmop *aop = NULL;
   char *rname, *l;
@@ -11251,7 +11514,9 @@ genPagedPointerSet (operand * right,
       rname = preg->name;
     }
   else
-    rname = aopGet (result, 0, FALSE, FALSE, NULL);
+    {
+      rname = aopGet (result, 0, FALSE, FALSE, NULL);
+    }
 
   aopOp (right, ic, FALSE, FALSE);
 
@@ -11260,7 +11525,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;
 
@@ -11269,10 +11534,8 @@ genPagedPointerSet (operand * right,
           l = aopGet (right, offset, FALSE, TRUE, NULL);
           MOVA (l);
           emitcode ("movx", "@%s,a", rname);
-
           if (size || pi)
             emitcode ("inc", "%s", rname);
-
           offset++;
         }
     }
@@ -11294,8 +11557,7 @@ 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;
@@ -11305,9 +11567,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);
 }
 
 /*-----------------------------------------------------------------*/
@@ -11358,7 +11621,7 @@ genFarPointerSet (operand * right,
           _endLazyDPSEvaluation ();
         }
     }
-  /* so dptr know contains the address */
+  /* so dptr now contains the address */
   aopOp (right, ic, FALSE, (AOP_INDPTRn(result) ? FALSE : TRUE));
 
   /* if bit then unpack */
@@ -11416,7 +11679,8 @@ genFarPointerSet (operand * right,
           _endLazyDPSEvaluation ();
       }
       pi->generated=1;
-  } else if ((OP_SYMBOL(result)->ruonly || AOP_INDPTRn(result)) &&
+  } else if (IS_SYMOP (result) &&
+             (OP_SYMBOL(result)->ruonly || AOP_INDPTRn(result)) &&
              AOP_SIZE(right) > 1 &&
              (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) {
 
@@ -11438,7 +11702,7 @@ genFarPointerSet (operand * right,
 /*-----------------------------------------------------------------*/
 static void
 genGenPointerSet (operand * right,
-                  operand * result, iCode * ic, iCode *pi)
+                  operand * result, iCode * ic, iCode * pi)
 {
   int size, offset;
   bool pushedB;
@@ -11486,49 +11750,49 @@ genGenPointerSet (operand * right,
   /* if bit then unpack */
   if (IS_BITFIELD (retype) || IS_BITFIELD (letype))
     {
-        genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, "dptr", GPOINTER);
+      genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, "dptr", GPOINTER);
     }
   else
     {
-        size = AOP_SIZE (right);
-        offset = 0;
+      size = AOP_SIZE (right);
+      offset = 0;
 
-        _startLazyDPSEvaluation ();
-        while (size--)
+      _startLazyDPSEvaluation ();
+      while (size--)
         {
-            if (size)
+          if (size)
             {
-                // Set two bytes at a time, passed in _AP & A.
-                // dptr will be incremented ONCE by __gptrputWord.
-                //
-                // Note: any change here must be coordinated
-                // with the implementation of __gptrputWord
-                // in device/lib/_gptrput.c
-                emitcode("mov", "_ap, %s",
-                         aopGet (right, offset++, FALSE, FALSE, NULL));
-                MOVA (aopGet (right, offset++, FALSE, FALSE, NULL));
-
-                genSetDPTR (0);
-                _flushLazyDPS ();
-                emitcode ("lcall", "__gptrputWord");
-                size--;
+              // Set two bytes at a time, passed in _AP & A.
+              // dptr will be incremented ONCE by __gptrputWord.
+              //
+              // Note: any change here must be coordinated
+              // with the implementation of __gptrputWord
+              // in device/lib/_gptrput.c
+              emitcode("mov", "_ap, %s",
+                       aopGet (right, offset++, FALSE, FALSE, NULL));
+              MOVA (aopGet (right, offset++, FALSE, FALSE, NULL));
+
+              genSetDPTR (0);
+              _flushLazyDPS ();
+              emitcode ("lcall", "__gptrputWord");
+              size--;
             }
-            else
+          else
             {
-                // Only one byte to put.
-                MOVA (aopGet (right, offset++, FALSE, FALSE, NULL));
+              // Only one byte to put.
+              MOVA (aopGet (right, offset++, FALSE, FALSE, NULL));
 
-                genSetDPTR (0);
-                _flushLazyDPS ();
-                emitcode ("lcall", "__gptrput");
+              genSetDPTR (0);
+              _flushLazyDPS ();
+              emitcode ("lcall", "__gptrput");
             }
 
-            if (size || (pi && AOP_TYPE (result) != AOP_IMMD))
+          if (size || (pi && AOP_TYPE (result) != AOP_IMMD))
             {
-                emitcode ("inc", "dptr");
+              emitcode ("inc", "dptr");
             }
         }
-        _endLazyDPSEvaluation ();
+      _endLazyDPSEvaluation ();
     }
 
   if (pi && AOP_TYPE (result) != AOP_IMMD) {
@@ -11633,18 +11897,18 @@ genIfx (iCode * ic, iCode * popIc)
   int isbit = 0;
   char *dup = NULL;
 
-  D (emitcode (";", "genIfx "));
+  D (emitcode (";", "genIfx"));
 
   aopOp (cond, ic, FALSE, FALSE);
 
   /* get the value into acc */
   if (AOP_TYPE (cond) != AOP_CRY)
     {
-        toBoolean (cond);
+      toBoolean (cond);
     }
   else
     {
-        isbit = 1;
+      isbit = 1;
       if (AOP(cond)->aopu.aop_dir)
         dup = Safe_strdup(AOP(cond)->aopu.aop_dir);
     }
@@ -11652,27 +11916,15 @@ genIfx (iCode * ic, iCode * popIc)
   /* the result is now in the accumulator or a directly addressable bit */
   freeAsmop (cond, NULL, ic, TRUE);
 
-  /* if there was something to be popped then do it */
-  if (popIc)
-    genIpop (popIc);
-
-  /* if the condition is  a bit variable */
+  /* if the condition is a bit variable */
   if (isbit && dup)
-    {
-        genIfxJump (ic, dup);
-    }
+    genIfxJump (ic, dup, popIc);
   else if (isbit && IS_ITEMP (cond) && SPIL_LOC (cond))
-    {
-        genIfxJump (ic, SPIL_LOC (cond)->rname);
-    }
+    genIfxJump (ic, SPIL_LOC (cond)->rname, popIc);
   else if (isbit && !IS_ITEMP (cond))
-    {
-        genIfxJump (ic, OP_SYMBOL (cond)->rname);
-    }
+    genIfxJump (ic, OP_SYMBOL (cond)->rname, popIc);
   else
-    {
-        genIfxJump (ic, "a");
-    }
+    genIfxJump (ic, "a", popIc);
 
   ic->generated = 1;
 }
@@ -11694,8 +11946,7 @@ genAddrOf (iCode * ic)
      need to get the stack offset of this
      variable */
   if (sym->onStack)
-  {
-
+    {
       /* if 10 bit stack */
       if (options.stack10bit) {
           char buff[10];
@@ -11761,19 +12012,20 @@ genAddrOf (iCode * ic)
           while (size--)
             {
               aopPut (IC_RESULT (ic), zero, offset++);
-          }
+            }
       }
       goto release;
-  }
+    }
 
   /* object not on stack then we need the name */
-  size = AOP_SIZE (IC_RESULT (ic));
+  size = getDataSize (IC_RESULT (ic));
   offset = 0;
 
   while (size--)
     {
       char s[SDCC_NAME_MAX];
-      if (offset) {
+      if (offset)
+        {
           switch (offset) {
           case 1:
               tsprintf(s, sizeof(s), "#!his",sym->rname);
@@ -11785,18 +12037,22 @@ genAddrOf (iCode * ic)
               tsprintf(s, sizeof(s), "#!hihihis",sym->rname);
               break;
           default: /* should not need this (just in case) */
-              SNPRINTF (s, sizeof(s), "#(%s >> %d)",
-                       sym->rname,
-                       offset * 8);
+              SNPRINTF (s, sizeof(s), "#(%s >> %d)", sym->rname, offset * 8);
           }
-      }
+        }
       else
-      {
+        {
           SNPRINTF (s, sizeof(s), "#%s", sym->rname);
-      }
-
+        }
       aopPut (IC_RESULT (ic), s, offset++);
     }
+  if (opIsGptr (IC_RESULT (ic)))
+    {
+      char buffer[10];
+      SNPRINTF (buffer, sizeof(buffer), "#0x%02x",
+                pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+      aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+    }
 
 release:
   freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
@@ -11805,7 +12061,7 @@ release:
 
 #if 0 // obsolete, and buggy for != xdata
 /*-----------------------------------------------------------------*/
-/* genArrayInit - generates code for address of                       */
+/* genArrayInit - generates code for address of                    */
 /*-----------------------------------------------------------------*/
 static void
 genArrayInit (iCode * ic)
@@ -11817,7 +12073,7 @@ genArrayInit (iCode * ic)
     sym_link    *type;
     operand     *left=IC_LEFT(ic);
 
-    D (emitcode (";", "genArrayInit "););
+    D (emitcode (";", "genArrayInit"));
 
     aopOp (IC_LEFT(ic), ic, FALSE, FALSE);
 
@@ -11881,7 +12137,7 @@ genArrayInit (iCode * ic)
                     emitcode("mov", "b, #!constbyte", count & 0xff);
                 }
 
-                emitcode ("", "!tlabeldef", tlbl->key + 100);
+                emitLabel (tlbl);
             }
 
             firstpass = FALSE;
@@ -11927,7 +12183,7 @@ genFarFarAssign (operand * result, operand * right, iCode * ic)
   if (size == 1)
   {
       /* quick & easy case. */
-      D(emitcode(";","genFarFarAssign (1 byte case)"););
+      D (emitcode(";","genFarFarAssign (1 byte case)"));
       MOVA (aopGet (right, 0, FALSE, FALSE, NULL));
       freeAsmop (right, NULL, ic, FALSE);
       /* now assign DPTR to result */
@@ -11956,7 +12212,7 @@ genFarFarAssign (operand * result, operand * right, iCode * ic)
   {
       /* We can use the '390 auto-toggle feature to good effect here. */
 
-      D(emitcode(";","genFarFarAssign (390 auto-toggle fun)"););
+      D (emitcode(";", "genFarFarAssign (390 auto-toggle fun)"));
       emitcode("mov", "dps,#!constbyte",0x21);  /* Select DPTR2 & auto-toggle. */
       emitcode ("mov", "dptr,#%s", rSym->rname);
       /* DP2 = result, DP1 = right, DP1 is current. */
@@ -11975,7 +12231,7 @@ genFarFarAssign (operand * result, operand * right, iCode * ic)
 #if 0
 some alternative code for processors without auto-toggle
 no time to test now, so later well put in...kpb
-        D(emitcode(";","genFarFarAssign (dual-dptr fun)"););
+        D (emitcode(";", "genFarFarAssign (dual-dptr fun)"));
         emitcode("mov", "dps,#1");      /* Select DPTR2. */
         emitcode ("mov", "dptr,#%s", rSym->rname);
         /* DP2 = result, DP1 = right, DP1 is current. */
@@ -11997,7 +12253,7 @@ no time to test now, so later well put in...kpb
   }
   else
   {
-      D (emitcode (";", "genFarFarAssign"););
+      D (emitcode (";", "genFarFarAssign"));
       aopOp (result, ic, TRUE, TRUE);
 
       _startLazyDPSEvaluation ();
@@ -12024,7 +12280,7 @@ genAssign (iCode * ic)
   int size, offset;
   unsigned long lit = 0L;
 
-  D (emitcode (";", "genAssign "));
+  D (emitcode (";", "genAssign"));
 
   result = IC_RESULT (ic);
   right = IC_RIGHT (ic);
@@ -12085,10 +12341,10 @@ genAssign (iCode * ic)
 
   /* bit variables done */
   /* general case */
-  size = AOP_SIZE (result);
+  size = getDataSize (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) &&
@@ -12127,6 +12383,7 @@ genAssign (iCode * ic)
         }
       _endLazyDPSEvaluation ();
     }
+  adjustArithmeticResult (ic);
 
 release:
   freeAsmop (result, NULL, ic, TRUE);
@@ -12142,8 +12399,7 @@ genJumpTab (iCode * ic)
   symbol *jtab;
   char *l;
 
-  D (emitcode (";", "genJumpTab ");
-    );
+  D (emitcode (";", "genJumpTab"));
 
   aopOp (IC_JTCOND (ic), ic, FALSE, FALSE);
   /* get the condition into accumulator */
@@ -12157,7 +12413,7 @@ genJumpTab (iCode * ic)
   jtab = newiTempLabel (NULL);
   emitcode ("mov", "dptr,#!tlabel", jtab->key + 100);
   emitcode ("jmp", "@a+dptr");
-  emitcode ("", "!tlabeldef", jtab->key + 100);
+  emitLabel (jtab);
   /* now generate the jump labels */
   for (jtab = setFirstItem (IC_JTLABELS (ic)); jtab;
        jtab = setNextItem (IC_JTLABELS (ic)))
@@ -12177,7 +12433,7 @@ genCast (iCode * ic)
   operand *right = IC_RIGHT (ic);
   int size, offset;
 
-  D (emitcode (";", "genCast "));
+  D (emitcode (";", "genCast"));
 
   /* if they are equivalent then do nothing */
   if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
@@ -12186,9 +12442,8 @@ genCast (iCode * ic)
   aopOp (right, ic, FALSE, AOP_IS_STR (result));
   aopOp (result, ic, FALSE, (AOP_TYPE(right) == AOP_DPTR));
 
-  /* if the result is a bit */
-  if (IS_BITVAR (OP_SYMBOL (result)->type)
-      && !IS_BITFIELD (OP_SYMBOL (result)->type) )
+  /* if the result is a bit (and not a bitfield) */
+  if (IS_BIT (OP_SYMBOL (result)->type))
     {
       /* if the right size is a literal then
          we know what the value is */
@@ -12386,154 +12641,6 @@ release:
 
 }
 
-/*-----------------------------------------------------------------*/
-/* genDjnz - generate decrement & jump if not zero instrucion      */
-/*-----------------------------------------------------------------*/
-static int
-genDjnz (iCode * ic, iCode * ifx)
-{
-  symbol *lbl, *lbl1;
-  if (!ifx)
-    return 0;
-
-  /* if the if condition has a false label
-     then we cannot save */
-  if (IC_FALSE (ifx))
-    return 0;
-
-  /* if the minus is not of the form
-     a = a - 1 */
-  if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
-      !IS_OP_LITERAL (IC_RIGHT (ic)))
-    return 0;
-
-  if (operandLitValue (IC_RIGHT (ic)) != 1)
-    return 0;
-
-  /* if the size of this greater than one then no
-     saving */
-  if (getSize (operandType (IC_RESULT (ic))) > 1)
-    return 0;
-
-  /* otherwise we can save BIG */
-  D(emitcode(";", "genDjnz"););
-
-  lbl = newiTempLabel (NULL);
-  lbl1 = newiTempLabel (NULL);
-
-  aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
-
-  if (AOP_NEEDSACC(IC_RESULT(ic)))
-  {
-      /* If the result is accessed indirectly via
-       * the accumulator, we must explicitly write
-       * it back after the decrement.
-       */
-      char *rByte = aopGet(IC_RESULT(ic), 0, FALSE, FALSE, NULL);
-
-      if (strcmp(rByte, "a"))
-      {
-           /* Something is hopelessly wrong */
-           fprintf(stderr, "*** warning: internal error at %s:%d\n",
-                   __FILE__, __LINE__);
-           /* We can just give up; the generated code will be inefficient,
-            * but what the hey.
-            */
-           freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
-           return 0;
-      }
-      emitcode ("dec", "%s", rByte);
-      aopPut(IC_RESULT(ic), rByte, 0);
-      emitcode ("jnz", "!tlabel", lbl->key + 100);
-  }
-  else if (IS_AOP_PREG (IC_RESULT (ic)))
-    {
-      emitcode ("dec", "%s",
-                aopGet (IC_RESULT (ic), 0, FALSE, FALSE, NULL));
-      emitcode ("mov", "a,%s", aopGet (IC_RESULT (ic), 0, FALSE, FALSE, NULL));
-      emitcode ("jnz", "!tlabel", lbl->key + 100);
-    }
-  else
-    {
-      emitcode ("djnz", "%s,!tlabel", aopGet (IC_RESULT (ic), 0, FALSE, TRUE, NULL),
-                lbl->key + 100);
-    }
-  emitcode ("sjmp", "!tlabel", lbl1->key + 100);
-  emitcode ("", "!tlabeldef", lbl->key + 100);
-  emitcode ("ljmp", "!tlabel", IC_TRUE (ifx)->key + 100);
-  emitcode ("", "!tlabeldef", lbl1->key + 100);
-
-  freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
-  ifx->generated = 1;
-  return 1;
-}
-
-/*-----------------------------------------------------------------*/
-/* genReceive - generate code for a receive iCode                  */
-/*-----------------------------------------------------------------*/
-static void
-genReceive (iCode * ic)
-{
-    int size = getSize (operandType (IC_RESULT (ic)));
-    int offset = 0;
-    int rb1off ;
-
-    D (emitcode (";", "genReceive "));
-
-    if (ic->argreg == 1)
-    {
-        /* first parameter */
-        if (AOP_IS_STR(IC_RESULT(ic)))
-        {
-            /* Nothing to do: it's already in the proper place. */
-            return;
-        }
-        else
-        {
-            bool useDp2;
-
-            useDp2 = isOperandInFarSpace (IC_RESULT (ic)) &&
-                (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
-                 IS_TRUE_SYMOP (IC_RESULT (ic)));
-
-            _G.accInUse++;
-            aopOp (IC_RESULT (ic), ic, FALSE, useDp2);
-            _G.accInUse--;
-
-            /* Sanity checking... */
-            if (AOP_USESDPTR(IC_RESULT(ic)))
-            {
-                werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                        "genReceive got unexpected DPTR.");
-            }
-            assignResultValue (IC_RESULT (ic), NULL);
-        }
-    }
-    else if (ic->argreg > 12)
-    { /* bit parameters */
-      if (OP_SYMBOL (IC_RESULT (ic))->regs[0]->rIdx != ic->argreg-5)
-        {
-          aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
-          emitcode ("mov", "c,%s", rb1regs[ic->argreg-5]);
-          outBitC(IC_RESULT (ic));
-        }
-    }
-    else
-    {
-        /* second receive onwards */
-        /* this gets a little tricky since unused receives will be
-         eliminated, we have saved the reg in the type field . and
-         we use that to figure out which register to use */
-        aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
-        rb1off = ic->argreg;
-        while (size--)
-        {
-            aopPut (IC_RESULT (ic), rb1regs[rb1off++ -5], offset++);
-        }
-    }
-    freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
-}
-
 /*-----------------------------------------------------------------*/
 /* genMemcpyX2X - gen code for memcpy xdata to xdata               */
 /*-----------------------------------------------------------------*/
@@ -12606,7 +12713,7 @@ static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc)
 
     /* now for the actual copy */
     if (AOP_TYPE(count) == AOP_LIT &&
-        (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) {
+        (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) {
         emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
         if (fromc) {
             emitcode ("lcall","__bi_memcpyc2x_s");
@@ -12622,7 +12729,7 @@ static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc)
         emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
         freeAsmop (count, NULL, ic, FALSE);
         emitcode ("mov", "dps,#!constbyte",0x21);       /* Select DPTR2 & auto-toggle. */
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         if (fromc) {
             emitcode ("clr","a");
             emitcode ("movc", "a,@a+dptr");
@@ -12641,7 +12748,7 @@ static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc)
         emitcode ("addc","a,#!constbyte",0xFF);
         emitcode ("mov","b,a");
         emitcode ("sjmp","!tlabel",lbl->key+100);
-        emitcode ("","!tlabeldef",lbl1->key+100);
+        emitLabel (lbl1);
     }
     emitcode ("mov", "dps,#0");
     _G.dptrInUse = _G.dptr1InUse = 0;
@@ -12722,7 +12829,7 @@ static void genMemcmpX2X( iCode *ic, int nparms, operand **parms, int fromc)
 
     /* now for the actual compare */
     if (AOP_TYPE(count) == AOP_LIT &&
-        (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) {
+        (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) {
         emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
         if (fromc)
             emitcode("lcall","__bi_memcmpc2x_s");
@@ -12741,7 +12848,7 @@ static void genMemcmpX2X( iCode *ic, int nparms, operand **parms, int fromc)
         emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
         freeAsmop (count, NULL, ic, FALSE);
         emitcode ("mov", "dps,#!constbyte",0x21);       /* Select DPTR2 & auto-toggle. */
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         if (fromc) {
             emitcode ("clr","a");
             emitcode ("movc", "a,@a+dptr");
@@ -12764,9 +12871,9 @@ static void genMemcmpX2X( iCode *ic, int nparms, operand **parms, int fromc)
         emitcode ("addc","a,#!constbyte",0xFF);
         emitcode ("mov","b,a");
         emitcode ("sjmp","!tlabel",lbl->key+100);
-        emitcode ("","!tlabeldef",lbl1->key+100);
+        emitLabel (lbl1);
         emitcode ("clr","a");
-        emitcode ("","!tlabeldef",lbl2->key+100);
+        emitLabel (lbl2);
         aopOp (IC_RESULT(ic), ic, FALSE,FALSE);
         aopPut(IC_RESULT(ic),"a",0);
         freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
@@ -12853,12 +12960,12 @@ static void genInp( iCode *ic, int nparms, operand **parms)
 
     /* now for the actual copy */
     if (AOP_TYPE(count) == AOP_LIT &&
-        (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) {
+        (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) {
         emitcode (";","OH  JOY auto increment with djnz (very fast)");
         emitcode ("mov", "dps,#!constbyte",0x1);        /* Select DPTR2 */
         emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
         freeAsmop (count, NULL, ic, FALSE);
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         emitcode ("movx", "a,@dptr");   /* read data from port */
         emitcode ("dec","dps");         /* switch to DPTR */
         emitcode ("movx", "@dptr,a");   /* save into location */
@@ -12873,7 +12980,7 @@ static void genInp( iCode *ic, int nparms, operand **parms)
         emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
         freeAsmop (count, NULL, ic, FALSE);
         emitcode ("mov", "dps,#!constbyte",0x1);        /* Select DPTR2 */
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         emitcode ("movx", "a,@dptr");
         emitcode ("dec","dps");         /* switch to DPTR */
         emitcode ("movx", "@dptr,a");
@@ -12891,7 +12998,7 @@ static void genInp( iCode *ic, int nparms, operand **parms)
         emitcode ("addc","a,#!constbyte",0xFF);
         emitcode ("mov","b,a");
         emitcode ("sjmp","!tlabel",lbl->key+100);
-        emitcode ("","!tlabeldef",lbl1->key+100);
+        emitLabel (lbl1);
     }
     emitcode ("mov", "dps,#0");
     _G.dptrInUse = _G.dptr1InUse = 0;
@@ -12974,11 +13081,11 @@ static void genOutp( iCode *ic, int nparms, operand **parms)
 
     /* now for the actual copy */
     if (AOP_TYPE(count) == AOP_LIT &&
-        (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) {
+        (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) {
         emitcode (";","OH  JOY auto increment with djnz (very fast)");
         emitcode ("mov", "dps,#!constbyte",0x0);        /* Select DPTR */
         emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         emitcode ("movx", "a,@dptr");   /* read data from port */
         emitcode ("inc","dps");         /* switch to DPTR2 */
         emitcode ("movx", "@dptr,a");   /* save into location */
@@ -12994,7 +13101,7 @@ static void genOutp( iCode *ic, int nparms, operand **parms)
         emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
         freeAsmop (count, NULL, ic, FALSE);
         emitcode ("mov", "dps,#!constbyte",0x0);        /* Select DPTR */
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         emitcode ("movx", "a,@dptr");
         emitcode ("inc", "dptr");
         emitcode ("inc","dps");         /* switch to DPTR2 */
@@ -13010,7 +13117,7 @@ static void genOutp( iCode *ic, int nparms, operand **parms)
         emitcode ("addc","a,#!constbyte",0xFF);
         emitcode ("mov","b,a");
         emitcode ("sjmp","!tlabel",lbl->key+100);
-        emitcode ("","!tlabeldef",lbl1->key+100);
+        emitLabel (lbl1);
     }
     emitcode ("mov", "dps,#0");
     _G.dptrInUse = _G.dptr1InUse = 0;
@@ -13108,11 +13215,11 @@ static void genMemsetX(iCode *ic, int nparms, operand **parms)
     lbl =newiTempLabel(NULL);
     /* now for the actual copy */
     if (AOP_TYPE(count) == AOP_LIT &&
-        (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) {
+        (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) {
         l = aopGet(val, 0, FALSE, FALSE, NULL);
         emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL));
         MOVA(l);
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         emitcode ("movx", "@dptr,a");
         emitcode ("inc", "dptr");
         emitcode ("djnz","b,!tlabel",lbl->key+100);
@@ -13121,7 +13228,7 @@ static void genMemsetX(iCode *ic, int nparms, operand **parms)
 
         emitcode ("mov","_ap,%s",aopGet (count, 0, FALSE, TRUE, NULL));
         emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL));
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         MOVA (aopGet(val, 0, FALSE, FALSE, NULL));
         emitcode ("movx", "@dptr,a");
         emitcode ("inc", "dptr");
@@ -13135,7 +13242,7 @@ static void genMemsetX(iCode *ic, int nparms, operand **parms)
         emitcode ("addc","a,#!constbyte",0xFF);
         emitcode ("mov","b,a");
         emitcode ("sjmp","!tlabel",lbl->key+100);
-        emitcode ("","!tlabeldef",lbl1->key+100);
+        emitLabel (lbl1);
     }
     freeAsmop (count, NULL, ic, FALSE);
     unsavermask(rsave);
@@ -13321,7 +13428,7 @@ static void genNatLibGetStateBlock(iCode *ic,int nparms,
                 aopPut(IC_RESULT(ic),"r3",1);
         }
         freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         unsavermask(rsave);
 }
 
@@ -13368,7 +13475,7 @@ static void genMMMalloc (iCode *ic,int nparms, operand **parms,
         emitcode ("jz","!tlabel",lbl->key+100);
         emitcode ("mov","r2,#!constbyte",0xff);
         emitcode ("mov","r3,#!constbyte",0xff);
-        emitcode ("","!tlabeldef",lbl->key+100);
+        emitLabel (lbl);
         /* we don't care about the pointer : we just save the handle */
         rsym = OP_SYMBOL(IC_RESULT(ic));
         if (rsym->liveFrom != rsym->liveTo) {
@@ -13431,9 +13538,9 @@ static void genMMDeref (iCode *ic,int nparms, operand **parms)
                         if (AOP_TYPE(IC_RESULT(ic)) != AOP_STR) {
                             _startLazyDPSEvaluation ();
 
-                                aopPut(IC_RESULT(ic),"dpl",0);
-                                aopPut(IC_RESULT(ic),"dph",1);
-                                aopPut(IC_RESULT(ic),"dpx",2);
+                            aopPut(IC_RESULT(ic),"dpl",0);
+                            aopPut(IC_RESULT(ic),"dph",1);
+                            aopPut(IC_RESULT(ic),"dpx",2);
 
                             _endLazyDPSEvaluation ();
 
@@ -13782,6 +13889,157 @@ static void genSystemGetCurrentID(iCode *ic,int nparms, operand **parms,char *na
         }
 }
 
+/*-----------------------------------------------------------------*/
+/* genDjnz - generate decrement & jump if not zero instrucion      */
+/*-----------------------------------------------------------------*/
+static int
+genDjnz (iCode * ic, iCode * ifx)
+{
+  symbol *lbl, *lbl1;
+  if (!ifx)
+    return 0;
+
+  /* if the if condition has a false label
+     then we cannot save */
+  if (IC_FALSE (ifx))
+    return 0;
+
+  /* if the minus is not of the form a = a - 1 */
+  if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
+      !IS_OP_LITERAL (IC_RIGHT (ic)))
+    return 0;
+
+  if (operandLitValue (IC_RIGHT (ic)) != 1)
+    return 0;
+
+  /* if the size of this greater than one then no
+     saving */
+  if (getSize (operandType (IC_RESULT (ic))) > 1)
+    return 0;
+
+  /* otherwise we can save BIG */
+
+  D (emitcode (";", "genDjnz"));
+
+  lbl = newiTempLabel (NULL);
+  lbl1 = newiTempLabel (NULL);
+
+  aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+
+  if (AOP_NEEDSACC(IC_RESULT(ic)))
+  {
+      /* If the result is accessed indirectly via
+       * the accumulator, we must explicitly write
+       * it back after the decrement.
+       */
+      char *rByte = aopGet (IC_RESULT(ic), 0, FALSE, FALSE, NULL);
+
+      if (strcmp(rByte, "a"))
+      {
+           /* Something is hopelessly wrong */
+           fprintf(stderr, "*** warning: internal error at %s:%d\n",
+                   __FILE__, __LINE__);
+           /* We can just give up; the generated code will be inefficient,
+            * but what the hey.
+            */
+           freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+           return 0;
+      }
+      emitcode ("dec", "%s", rByte);
+      aopPut (IC_RESULT (ic), rByte, 0);
+      emitcode ("jnz", "!tlabel", lbl->key + 100);
+  }
+  else if (IS_AOP_PREG (IC_RESULT (ic)))
+    {
+      emitcode ("dec", "%s",
+                aopGet (IC_RESULT (ic), 0, FALSE, FALSE, NULL));
+      MOVA (aopGet (IC_RESULT (ic), 0, FALSE, FALSE, NULL));
+      freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+      ifx->generated = 1;
+      emitcode ("jnz", "!tlabel", lbl->key + 100);
+    }
+  else
+    {
+      emitcode ("djnz", "%s,!tlabel", aopGet (IC_RESULT (ic), 0, FALSE, TRUE, NULL),
+                lbl->key + 100);
+    }
+  emitcode ("sjmp", "!tlabel", lbl1->key + 100);
+  emitLabel (lbl);
+  emitcode ("ljmp", "!tlabel", IC_TRUE (ifx)->key + 100);
+  emitLabel (lbl1);
+
+  if (!ifx->generated)
+      freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+  ifx->generated = 1;
+  return 1;
+}
+
+/*-----------------------------------------------------------------*/
+/* genReceive - generate code for a receive iCode                  */
+/*-----------------------------------------------------------------*/
+static void
+genReceive (iCode * ic)
+{
+  int size = getSize (operandType (IC_RESULT (ic)));
+  int offset = 0;
+  int rb1off ;
+
+  D (emitcode (";", "genReceive"));
+
+  if (ic->argreg == 1)
+    {
+      /* first parameter */
+      if (AOP_IS_STR(IC_RESULT(ic)))
+        {
+          /* Nothing to do: it's already in the proper place. */
+          return;
+        }
+      else
+        {
+          bool useDp2;
+
+          useDp2 = isOperandInFarSpace (IC_RESULT (ic)) &&
+                (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+                 IS_TRUE_SYMOP (IC_RESULT (ic)));
+
+          _G.accInUse++;
+          aopOp (IC_RESULT (ic), ic, FALSE, useDp2);
+          _G.accInUse--;
+
+          /* Sanity checking... */
+          if (AOP_USESDPTR(IC_RESULT(ic)))
+            {
+              werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+                      "genReceive got unexpected DPTR.");
+            }
+          assignResultValue (IC_RESULT (ic), NULL);
+        }
+    }
+  else if (ic->argreg > 12)
+    { /* bit parameters */
+      if (OP_SYMBOL (IC_RESULT (ic))->regs[0]->rIdx != ic->argreg-5)
+        {
+          aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+          emitcode ("mov", "c,%s", rb1regs[ic->argreg-5]);
+          outBitC(IC_RESULT (ic));
+        }
+    }
+  else
+    {
+      /* second receive onwards */
+      /* this gets a little tricky since unused receives will be
+       eliminated, we have saved the reg in the type field . and
+       we use that to figure out which register to use */
+      aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+      rb1off = ic->argreg;
+      while (size--)
+        {
+          aopPut (IC_RESULT (ic), rb1regs[rb1off++ -5], offset++);
+        }
+    }
+  freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+}
+
 /*-----------------------------------------------------------------*/
 /* genDummyRead - generate code for dummy read of volatiles        */
 /*-----------------------------------------------------------------*/
@@ -13853,20 +14111,22 @@ genCritical (iCode *ic)
   D (emitcode(";", "genCritical"));
 
   if (IC_RESULT (ic))
-    aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
-
-  emitcode ("setb", "c");
-  emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
-  emitcode ("clr", "c");
-  emitcode ("", "%05d$:", (tlbl->key + 100));
-
-  if (IC_RESULT (ic))
-    outBitC (IC_RESULT (ic)); /* save old ea in an operand */
+    {
+      aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
+      aopPut (IC_RESULT (ic), one, 0); /* save old ea in an operand */
+      emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
+      aopPut (IC_RESULT (ic), zero, 0);
+      emitLabel (tlbl);
+      freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+    }
   else
-    emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/
-
-  if (IC_RESULT (ic))
-    freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+    {
+      emitcode ("setb", "c");
+      emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
+      emitcode ("clr", "c");
+      emitLabel (tlbl);
+      emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -13875,7 +14135,7 @@ genCritical (iCode *ic)
 static void
 genEndCritical (iCode *ic)
 {
-  D(emitcode(";     genEndCritical",""));
+  D(emitcode(";", "genEndCritical"));
 
   if (IC_RIGHT (ic))
     {
@@ -14038,7 +14298,7 @@ gen390Code (iCode * lic)
 #if 1
   /* print the allocation information */
   if (allocInfo && currFunc)
-    printAllocInfo (currFunc, codeOutFile);
+    printAllocInfo (currFunc, codeOutBuf);
 #endif
   /* if debug information required */
   if (options.debug && currFunc)
@@ -14063,13 +14323,15 @@ gen390Code (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;
         }
       if (options.iCodeInAsm) {
-        emitcode("", ";ic:%d: %s", ic->key, printILine(ic));
+        const char *iLine = printILine(ic);
+        emitcode(";", "ic:%d: %s", ic->key, iLine);
+        dbuf_free(iLine);
       }
       /* if the result is marked as
          spilt and rematerializable or code for
@@ -14098,18 +14360,25 @@ gen390Code (iCode * lic)
           break;
 
         case IPOP:
-          /* IPOP happens only when trying to restore a
-             spilt live range, if there is an ifx statement
-             following this pop then the if statement might
-             be using some of the registers being popped which
-             would destory the contents of the register so
-             we need to check for this condition and handle it */
-          if (ic->next &&
-              ic->next->op == IFX &&
-              regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
-            genIfx (ic->next, ic);
-          else
-            genIpop (ic);
+          {
+            iCode *ifxIc, *popIc;
+            bool CommonRegs = FALSE;
+
+            /* IPOP happens only when trying to restore a
+               spilt live range, if there is an ifx statement
+               following this pop (or several) then the if statement might
+               be using some of the registers being popped which
+               would destory the contents of the register so
+               we need to check for this condition and handle it */
+            for (ifxIc = ic->next; ifxIc && ifxIc->op == IPOP; ifxIc = ifxIc->next);
+            for (popIc = ic; popIc && popIc->op == IPOP; popIc = popIc->next)
+              CommonRegs |= (ifxIc && ifxIc->op == IFX && !ifxIc->generated &&
+                             regsInCommon (IC_LEFT (popIc), IC_COND (ifxIc)));
+            if (CommonRegs)
+              genIfx (ifxIc, ic);
+            else
+              genIpop (ic);
+          }
           break;
 
         case CALL:
@@ -14228,12 +14497,16 @@ gen390Code (iCode * lic)
           break;
 
         case GET_VALUE_AT_ADDRESS:
-          genPointerGet (ic,hasInc(IC_LEFT(ic),ic, getSize(operandType(IC_RESULT(ic)))));
+          genPointerGet (ic,
+                         hasInc (IC_LEFT (ic), ic,
+                                 getSize (operandType (IC_RESULT (ic)))));
           break;
 
         case '=':
           if (POINTER_SET (ic))
-            genPointerSet (ic,hasInc(IC_RESULT(ic),ic,getSize(operandType(IC_RIGHT(ic)))));
+            genPointerSet (ic,
+                           hasInc (IC_RESULT (ic), ic,
+                                   getSize (operandType (IC_RIGHT (ic)))));
           else
             genAssign (ic);
           break;
@@ -14288,7 +14561,10 @@ gen390Code (iCode * lic)
 #endif
 
         default:
-          ic = ic;
+            /* This should never happen, right? */
+            fprintf(stderr, "*** Probable error: unsupported op 0x%x (%c) in %s @ %d\n",
+                    ic->op, ic->op, __FILE__, __LINE__);
+            ic = ic;
         }
     }
 
@@ -14299,6 +14575,6 @@ gen390Code (iCode * lic)
     peepHole (&lineHead);
 
   /* now do the actual printing */
-  printLine (lineHead, codeOutFile);
+  printLine (lineHead, codeOutBuf);
   return;
 }