* src/SDCC.y, src/SDCCast.c, src/SDCCcse.c, src/SDCCglue.c, src/SDCCicode.c,
[fw/sdcc] / src / hc08 / gen.c
index 2897a99541cdfeaecc10c23c2eb0e211f37dce2e..d2e1fd9e1c8797ad4aa2aeecd2a9517592d9b2b7 100644 (file)
 
 -------------------------------------------------------------------------*/
 
-//#define D(x)
-#define D(x) x
+/* Use the D macro for basic (unobtrusive) debugging messages */
+#define D(x) do if (options.verboseAsm) {x;} while(0)
+/* Use the DD macro for detailed debugging messages */
+#define DD(x)
+//#define DD(x) x
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -47,6 +50,7 @@ char *aopLiteralLong (value * val, int offset, int size);
 extern int allocInfo;
 static int pushReg (regs *reg, bool freereg);
 static void pullReg (regs *reg);
+static void transferAopAop (asmop *srcaop, int srcofs, asmop *dstaop, int dstofs);
 
 static char *zero = "#0x00";
 static char *one = "#0x01";
@@ -54,7 +58,7 @@ static char *spname;
 
 char *fReturnhc08[] =
 {"a", "x", "_ret2", "_ret3"};
-unsigned fReturnSizeHC08 = 4;  /* shared with ralloc.c */
+unsigned fReturnSizeHC08 = 4;   /* shared with ralloc.c */
 char **fReturn2 = fReturnhc08;
 
 
@@ -78,7 +82,7 @@ static asmop *hc08_aop_pass[4];
 
 extern int hc08_ptrRegReq;
 extern int hc08_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
 //static void saveRBank (int, iCode *, bool);
 static bool operandsEqu (operand * op1, operand * op2);
 static void loadRegFromConst (regs *reg, char *c);
@@ -154,9 +158,9 @@ emitcode (char *inst, char *fmt,...)
   if (inst && *inst)
     {
       if (fmt && *fmt)
-       sprintf (lb, "%s\t", inst);
+        sprintf (lb, "%s\t", inst);
       else
-       sprintf (lb, "%s", inst);
+        sprintf (lb, "%s", inst);
       vsprintf (lb + (strlen (lb)), fmt, ap);
     }
   else
@@ -167,8 +171,8 @@ emitcode (char *inst, char *fmt,...)
 
   if (lbp && *lbp)
     lineCurr = (lineCurr ?
-               connectLine (lineCurr, newLineNode (lb)) :
-               (lineHead = newLineNode (lb)));
+                connectLine (lineCurr, newLineNode (lb)) :
+                (lineHead = newLineNode (lb)));
   lineCurr->isInline = _G.inLine;
   lineCurr->isDebug = _G.debugLine;
   lineCurr->ic = _G.current_iCode;
@@ -188,6 +192,7 @@ static void
 emitLabel (symbol *tlbl)
 {
   emitcode ("", "%05d$:", (tlbl->key +100));
+  lineCurr->isLabel = 1;
 }
 
 /*-----------------------------------------------------------------*/
@@ -223,11 +228,11 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc)
   if (!sreg)
     {
       werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-             "NULL sreg in transferRegReg");
+              "NULL sreg in transferRegReg");
       return;
     }
 
-  D(emitcode ("", "; transferRegReg(%s,%s)",
+  DD(emitcode ("", "; transferRegReg(%s,%s)",
             sreg->name, dreg->name));
 
   srcidx = sreg->rIdx;
@@ -242,8 +247,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc)
         switch (srcidx)
           {
             case H_IDX: /* H to A */
-             pushReg (hc08_reg_h, FALSE);
-             pullReg (hc08_reg_a);
+              pushReg (hc08_reg_h, FALSE);
+              pullReg (hc08_reg_a);
               break;
             case X_IDX: /* X to A */
               emitcode ("txa", "");
@@ -256,12 +261,12 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc)
         switch (srcidx)
           {
             case A_IDX: /* A to H */
-             pushReg (hc08_reg_a, FALSE);
-             pullReg (hc08_reg_h);
+              pushReg (hc08_reg_a, FALSE);
+              pullReg (hc08_reg_h);
               break;
             case X_IDX: /* X to H */
-             pushReg (hc08_reg_x, FALSE);
-             pullReg (hc08_reg_h);
+              pushReg (hc08_reg_x, FALSE);
+              pullReg (hc08_reg_h);
               break;
             default:
               error=1;
@@ -274,8 +279,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc)
               emitcode ("tax", "");
               break;
             case H_IDX: /* H to X */
-             pushReg (hc08_reg_h, FALSE);
-             pullReg (hc08_reg_x);
+              pushReg (hc08_reg_h, FALSE);
+              pullReg (hc08_reg_x);
               break;
             default:
               error=1;
@@ -285,8 +290,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc)
         switch (srcidx)
           {
             case XA_IDX: /* XA to HX */
-             pushReg (hc08_reg_x, FALSE);
-             pullReg (hc08_reg_h);
+              pushReg (hc08_reg_x, FALSE);
+              pullReg (hc08_reg_h);
               emitcode ("tax", "");
               break;
             default:
@@ -298,8 +303,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc)
           {
             case HX_IDX: /* HX to XA */
               emitcode ("txa", "");
-             pushReg (hc08_reg_h, FALSE);
-             pullReg (hc08_reg_x);
+              pushReg (hc08_reg_h, FALSE);
+              pullReg (hc08_reg_x);
               break;
             default:
               error=1;
@@ -332,7 +337,7 @@ updateCFA(void)
     return;
   
   debugFile->writeFrameAddress (NULL, hc08_reg_sp,
-                               1 + _G.stackOfs + _G.stackPushes);
+                                1 + _G.stackOfs + _G.stackPushes);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -349,32 +354,32 @@ pushReg (regs *reg, bool freereg)
       case A_IDX:
         emitcode ("psha", "");
         _G.stackPushes++;
-       updateCFA();
+        updateCFA();
         break;
       case X_IDX:
         emitcode ("pshx", "");
         _G.stackPushes++;
-       updateCFA();
+        updateCFA();
         break;
       case H_IDX:
         emitcode ("pshh", "");
         _G.stackPushes++;
-       updateCFA();
+        updateCFA();
         break;
       case HX_IDX:
         emitcode ("pshx", "");
         _G.stackPushes++;
-       updateCFA();
+        updateCFA();
         emitcode ("pshh", "");
         _G.stackPushes++;
-       updateCFA();
+        updateCFA();
         break;
       case XA_IDX:
         emitcode ("psha", "");
-       updateCFA();
+        updateCFA();
         _G.stackPushes++;
         emitcode ("pshx", "");
-       updateCFA();
+        updateCFA();
         _G.stackPushes++;
         break;
       default:
@@ -398,33 +403,33 @@ pullReg (regs *reg)
       case A_IDX:
         emitcode ("pula", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         break;
       case X_IDX:
         emitcode ("pulx", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         break;
       case H_IDX:
         emitcode ("pulh", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         break;
       case HX_IDX:
         emitcode ("pulh", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         emitcode ("pulx", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         break;
       case XA_IDX:
         emitcode ("pulx", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         emitcode ("pula", "");
         _G.stackPushes--;
-       updateCFA();
+        updateCFA();
         break;
       default:
         break;
@@ -488,22 +493,22 @@ adjustStack (int n)
         {
           emitcode ("ais","#127");
           n -= 127;
-         _G.stackPushes -= 127;
-         updateCFA();
+          _G.stackPushes -= 127;
+          updateCFA();
         }
       else if (n<-128)
         {
           emitcode ("ais","#-128");
           n += 128;
-         _G.stackPushes += 128;
-         updateCFA();
+          _G.stackPushes += 128;
+          updateCFA();
         }
       else
         {
           emitcode ("ais", "#%d", n);
-         _G.stackPushes -= n;
+          _G.stackPushes -= n;
           n = 0;
-         updateCFA();
+          updateCFA();
         }
     }    
 }
@@ -598,9 +603,9 @@ loadRegFromAop (regs *reg, asmop *aop, int loffset)
     printf(" reg missing operand link\n");
 #endif
 
-  D(emitcode ("", ";     loadRegFromAop (%s, %s, %d)",
+  DD(emitcode ("", ";     loadRegFromAop (%s, %s, %d)",
             reg->name, aopName (aop), loffset));
-       
+        
   /* If operand is volatile, we cannot optimize. */
   if (!aop->op || isOperandVolatile (aop->op, FALSE))
     goto forceload;
@@ -613,7 +618,7 @@ loadRegFromAop (regs *reg, asmop *aop, int loffset)
       && (reg->aopofs == loffset))
     {
       hc08_useReg(reg);
-      D(emitcode ("","; already had correct value for %s", reg->name));
+      DD(emitcode ("","; already had correct value for %s", reg->name));
       return;
     }
 
@@ -623,7 +628,7 @@ loadRegFromAop (regs *reg, asmop *aop, int loffset)
       && operandsEqu(hc08_reg_h->aop->op,aop->op)
       && (hc08_reg_h->aopofs == loffset))
     {
-      D(emitcode ("","; found correct value for %s in h", reg->name));
+      DD(emitcode ("","; found correct value for %s in h", reg->name));
       transferRegReg (hc08_reg_h, reg, FALSE);
       hc08_useReg (reg);
       return;
@@ -634,7 +639,7 @@ loadRegFromAop (regs *reg, asmop *aop, int loffset)
       && operandsEqu(hc08_reg_x->aop->op,aop->op)
       && (hc08_reg_x->aopofs == loffset))
     {
-      D(emitcode ("","; found correct value for %s in x", reg->name));
+      DD(emitcode ("","; found correct value for %s in x", reg->name));
       transferRegReg (hc08_reg_x, reg, FALSE);
       hc08_useReg (reg);
       return;
@@ -644,7 +649,7 @@ loadRegFromAop (regs *reg, asmop *aop, int loffset)
       && operandsEqu(hc08_reg_a->aop->op,aop->op)
       && (hc08_reg_a->aopofs == loffset))
     {
-      D(emitcode ("","; found correct value for %s in a", reg->name));
+      DD(emitcode ("","; found correct value for %s in a", reg->name));
       transferRegReg (hc08_reg_a, reg, FALSE);
       hc08_useReg (reg);
       return;
@@ -768,25 +773,51 @@ forceload:
 /*--------------------------------------------------------------------------*/
 /* forceStackedAop - Reserve space on the stack for asmop aop; when         */
 /*                   freeAsmop is called with aop, the stacked data will    */
-/*                   be copied to the original aop location and             */
+/*                   be copied to the original aop location.                */
 /*--------------------------------------------------------------------------*/
 static asmop *
-forceStackedAop (asmop *aop)
+forceStackedAop (asmop *aop, bool copyOrig)
 {
+  regs *reg;
   int loffset;
   asmop *newaop = newAsmop (aop->type);
   memcpy (newaop, aop, sizeof(*newaop));
   
-  D(emitcode("", "; forcedStackAop %s", aopName(aop)));
+  DD(emitcode("", "; forcedStackAop %s", aopName(aop)));
+
+  if (copyOrig && hc08_reg_a->isFree)
+    reg = hc08_reg_a;
+  else if (copyOrig && hc08_reg_x->isFree)
+    reg = hc08_reg_x;
+  else
+    reg = NULL;
   for (loffset=0; loffset < newaop->size; loffset++)
     {
       asmop *aopsof = newAsmop (AOP_SOF);
       aopsof->size = 1;
-      aopsof->aopu.aop_stk = pushReg (hc08_reg_a, FALSE);
+      if (copyOrig && reg)
+        {
+          loadRegFromAop (reg, aop, loffset);
+          aopsof->aopu.aop_stk = pushReg (reg, FALSE);
+        }
+      else
+        {
+          aopsof->aopu.aop_stk = pushReg (hc08_reg_a, FALSE);
+        }
       aopsof->op = aop->op;
       newaop->stk_aop[loffset] = aopsof;
     }
   newaop->stacked = 1;
+
+  if (!reg && copyOrig)
+    {
+      for (loffset=0; loffset < newaop->size; loffset++)
+        {
+          transferAopAop (aop, loffset, newaop, loffset);
+        }
+    }
+
   return newaop;
 }
 
@@ -803,7 +834,7 @@ storeRegToAop (regs *reg, asmop *aop, int loffset)
   int otheridx;
   #endif
 
-  D(emitcode ("", ";     storeRegToAop (%s, %s, %d), stacked=%d, isaddr=%d",
+  DD(emitcode ("", ";     storeRegToAop (%s, %s, %d), stacked=%d, isaddr=%d",
             reg->name, aopName (aop), loffset, aop->stacked, aop->isaddr));
 
   if ((reg->rIdx == HX_IDX) && aop->stacked
@@ -923,19 +954,19 @@ storeRegToAop (regs *reg, asmop *aop, int loffset)
                 && operandsEqu(otherreg->aop->op,aop->op)
                 && (otherreg->aopofs == loffset))
               {
-                D(emitcode("","; marking %s stale", otherreg->name));
+                DD(emitcode("","; marking %s stale", otherreg->name));
                 otherreg->aop=NULL;
               }
           }
       if ((!hc08_reg_x->aop || !hc08_reg_h->aop) && hc08_reg_hx->aop)
         {
           hc08_reg_hx->aop = NULL;
-          D(emitcode("","; marking hx stale"));
+          DD(emitcode("","; marking hx stale"));
         }
       if ((!hc08_reg_x->aop || !hc08_reg_a->aop) && hc08_reg_xa->aop)
         {
           hc08_reg_xa->aop = NULL;
-          D(emitcode("","; marking xa stale"));
+          DD(emitcode("","; marking xa stale"));
         }
     
       reg->aop = aop;
@@ -994,8 +1025,8 @@ loadRegFromConst (regs *reg, char *c)
         break;
       default:
         werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-               "Bad rIdx in loadRegFromConst");
-       return;
+                "Bad rIdx in loadRegFromConst");
+        return;
     }
   hc08_useReg (reg);
 }
@@ -1163,10 +1194,10 @@ transferAopAop (asmop *srcaop, int srcofs, asmop *dstaop, int dstofs)
       return;
     }
 
-//  D(emitcode ("", "; transferAopAop (%s, %d, %s, %d)",
+//  DD(emitcode ("", "; transferAopAop (%s, %d, %s, %d)",
 //            aopName (srcaop), srcofs, aopName (dstaop), dstofs));
-//  D(emitcode ("", "; srcaop->type = %d", srcaop->type));
-//  D(emitcode ("", "; dstaop->type = %d", dstaop->type));
+//  DD(emitcode ("", "; srcaop->type = %d", srcaop->type));
+//  DD(emitcode ("", "; dstaop->type = %d", dstaop->type));
   
   if (dstofs >= dstaop->size)
     return;
@@ -1179,7 +1210,7 @@ transferAopAop (asmop *srcaop, int srcofs, asmop *dstaop, int dstofs)
           unsigned long lit;
           unsigned long bytemask;
           
-          lit = (unsigned long) floatFromVal (srcaop->aopu.aop_lit);
+          lit = ulFromVal (srcaop->aopu.aop_lit);
           bytemask = (lit >> (srcofs*8)) & 0xff;
           
           if (bytemask == 0)
@@ -1445,7 +1476,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
 
 
   werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-         "aopForSym should never reach here");
+          "aopForSym should never reach here");
 
   exit(1);
   
@@ -1470,19 +1501,19 @@ aopForRemat (symbol * sym)
   for (;;)
     {
       if (ic->op == '+')
-       val += (int) operandLitValue (IC_RIGHT (ic));
+        val += (int) operandLitValue (IC_RIGHT (ic));
       else if (ic->op == '-')
-       val -= (int) operandLitValue (IC_RIGHT (ic));
+        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 = DCL_TYPE(from_type);
-             if (ptr_type == IPOINTER) {
-               // bug #481053
-               ptr_type = POINTER;
-             }
-             continue ;
+              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 = DCL_TYPE(from_type);
+              if (ptr_type == IPOINTER) {
+                // bug #481053
+                ptr_type = POINTER;
+              }
+              continue ;
       } else break;
 
       ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
@@ -1492,9 +1523,9 @@ aopForRemat (symbol * sym)
     {
       if (val)
         sprintf (buffer, "(%s %c 0x%04x)",
-                OP_SYMBOL (IC_LEFT (ic))->rname,
-                val >= 0 ? '+' : '-',
-                abs (val) & 0xffff);
+                 OP_SYMBOL (IC_LEFT (ic))->rname,
+                 val >= 0 ? '+' : '-',
+                 abs (val) & 0xffff);
       else
         strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname);
 
@@ -1503,11 +1534,11 @@ aopForRemat (symbol * sym)
       strcpy (aop->aopu.aop_immd.aop_immd1, buffer);
       /* set immd2 field if required */
       if (aop->aopu.aop_immd.from_cast_remat)
-       {
-         sprintf(buffer,"#0x%02x",ptr_type);
-         aop->aopu.aop_immd.aop_immd2 = Safe_calloc (1, strlen (buffer) + 1);
-         strcpy (aop->aopu.aop_immd.aop_immd2, buffer);
-       }
+        {
+          sprintf(buffer,"#0x%02x",ptr_type);
+          aop->aopu.aop_immd.aop_immd2 = Safe_calloc (1, strlen (buffer) + 1);
+          strcpy (aop->aopu.aop_immd.aop_immd2, buffer);
+        }
     }
   else if (ic->op == '=')
     {
@@ -1519,7 +1550,7 @@ aopForRemat (symbol * sym)
     }
   else
     werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-           "unexpected rematerialization");
+            "unexpected rematerialization");
 
 
 
@@ -1549,16 +1580,16 @@ regsInCommon (operand * op1, operand * op2)
     {
       int j;
       if (!sym1->regs[i])
-       continue;
+        continue;
 
       for (j = 0; j < sym2->nRegs; j++)
-       {
-         if (!sym2->regs[j])
-           continue;
+        {
+          if (!sym2->regs[j])
+            continue;
 
-         if (sym2->regs[j] == sym1->regs[i])
-           return TRUE;
-       }
+          if (sym2->regs[j] == sym1->regs[i])
+            return TRUE;
+        }
     }
 
   return FALSE;
@@ -1589,6 +1620,7 @@ operandsEqu (operand * op1, operand * op2)
   if (sym1 == sym2)
     return TRUE;
 
+  /* if they have the same rname */
   if (sym1->rname[0] && sym2->rname[0]
       && strcmp (sym1->rname, sym2->rname) == 0)
     return TRUE;
@@ -1749,10 +1781,10 @@ aopOp (operand * op, iCode * ic, bool result)
 //      printf("checking remat\n");
       /* rematerialize it NOW */
       if (sym->remat)
-       {
-         sym->aop = op->aop = aop =
-           aopForRemat (sym);
-         aop->size = getSize (sym->type);
+        {
+          sym->aop = op->aop = aop =
+            aopForRemat (sym);
+          aop->size = getSize (sym->type);
           aop->op = op;
           aop->isaddr = op->isaddr;
           /* if (aop->isaddr & IS_ITEMP (op))
@@ -1760,44 +1792,44 @@ aopOp (operand * op, iCode * ic, bool result)
               aop->psize=aop->size;
               aop->size = getSize( operandType (op)->next);
             } */
-         return;
-       }
+          return;
+        }
 
 //      printf("checking accuse\n");
       if (sym->accuse)
-       {
-         aop = op->aop = sym->aop = newAsmop (AOP_REG);
-         aop->size = getSize (sym->type);
-         switch (sym->accuse)
-           {
-           case ACCUSE_XA:
+        {
+          aop = op->aop = sym->aop = newAsmop (AOP_REG);
+          aop->size = getSize (sym->type);
+          switch (sym->accuse)
+            {
+            case ACCUSE_XA:
               aop->aopu.aop_reg[0] = hc08_reg_a;
               aop->aopu.aop_reg[1] = hc08_reg_x;
               break;
-           case ACCUSE_HX:
+            case ACCUSE_HX:
               aop->aopu.aop_reg[0] = hc08_reg_x;
               aop->aopu.aop_reg[1] = hc08_reg_h;
               break;
             }
           aop->op = op;
           aop->isaddr = op->isaddr;
-         return;
-       }
+          return;
+        }
 
 //      printf("checking ruonly\n");
 #if 1
       if (sym->ruonly)
-       {
-         unsigned i;
+        {
+          unsigned i;
 
-         aop = op->aop = sym->aop = newAsmop (AOP_STR);
-         aop->size = getSize (sym->type);
-         for (i = 0; i < fReturnSizeHC08; i++)
-           aop->aopu.aop_str[i] = fReturn2[i];
+          aop = op->aop = sym->aop = newAsmop (AOP_STR);
+          aop->size = getSize (sym->type);
+          for (i = 0; i < fReturnSizeHC08; i++)
+            aop->aopu.aop_str[i] = fReturn2[i];
           aop->op = op;
           aop->isaddr = op->isaddr;
-         return;
-       }
+          return;
+        }
 #endif
       /* else spill location  */
       if (sym->usl.spillLoc)
@@ -1807,24 +1839,24 @@ aopOp (operand * op, iCode * ic, bool result)
           if (sym->usl.spillLoc->aop
               && sym->usl.spillLoc->aop->size != getSize (sym->type))
             {
-             /* force a new aop if sizes differ */
+              /* force a new aop if sizes differ */
               oldAsmOp = sym->usl.spillLoc->aop;
-             sym->usl.spillLoc->aop = NULL;
-             //printf ("forcing new aop\n");
+              sym->usl.spillLoc->aop = NULL;
+              //printf ("forcing new aop\n");
             }
-         sym->aop = op->aop = aop = aopForSym (ic, sym->usl.spillLoc, result);
+          sym->aop = op->aop = aop = aopForSym (ic, sym->usl.spillLoc, result);
           if (sym->usl.spillLoc->aop->size != getSize (sym->type))
             {
               /* Don't reuse the new aop, go with the last one */
               sym->usl.spillLoc->aop = oldAsmOp;
             }
-         aop->size = getSize (sym->type);
-         aop->op = op;
-         aop->isaddr = op->isaddr;
-         //printf ("spill symbol %s\n", OP_SYMBOL (op)->name);
-         //printf (" with size = %d\n", aop->size);
-         return;
-       }
+          aop->size = getSize (sym->type);
+          aop->op = op;
+          aop->isaddr = op->isaddr;
+          //printf ("spill symbol %s\n", OP_SYMBOL (op)->name);
+          //printf (" with size = %d\n", aop->size);
+          return;
+        }
       
       /* else must be a dummy iTemp */
       sym->aop = op->aop = aop = newAsmop (AOP_DUMMY);
@@ -1869,7 +1901,7 @@ freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
       int stackAdjust;
       int loffset;
 
-      D(emitcode ("","; freeAsmop restoring stacked %s", aopName(aop)));
+      DD(emitcode ("","; freeAsmop restoring stacked %s", aopName(aop)));
       aop->stacked = 0;
       stackAdjust = 0;
       for (loffset=0; loffset<aop->size; loffset++)
@@ -1887,12 +1919,12 @@ dealloc:
     {
       op->aop = NULL;
       if (IS_SYMOP (op))
-       {
-         OP_SYMBOL (op)->aop = NULL;
-         /* if the symbol has a spill */
-         if (SPIL_LOC (op))
-           SPIL_LOC (op)->aop = NULL;
-       }
+        {
+          OP_SYMBOL (op)->aop = NULL;
+          /* if the symbol has a spill */
+          if (SPIL_LOC (op))
+            SPIL_LOC (op)->aop = NULL;
+        }
     }
 }
 
@@ -1911,7 +1943,7 @@ aopDerefAop (asmop *aop)
   sym_link *type, *etype;
   int p_type;
   
-  D(emitcode ("", ";     aopDerefAop(%s)", aopName(aop)));
+  DD(emitcode ("", ";     aopDerefAop(%s)", aopName(aop)));
   if (aop->op)
     {
     
@@ -1939,7 +1971,7 @@ aopDerefAop (asmop *aop)
       newaop->aopu.aop_dir = aop->aopu.aop_immd.aop_immd1;
       break;
     case AOP_LIT:
-      adr = (int) floatFromVal (aop->aopu.aop_lit);
+      adr = (int) ulFromVal (aop->aopu.aop_lit);
       if (p_type == POINTER)
         adr &= 0xff;
 
@@ -1995,44 +2027,44 @@ aopAdrStr (asmop * aop, int loffset, bool bit16)
       
     case AOP_IMMD:
       if (aop->aopu.aop_immd.from_cast_remat && (loffset == (aop->size-1))) {
-             sprintf(s,"%s",aop->aopu.aop_immd.aop_immd2);
+              sprintf(s,"%s",aop->aopu.aop_immd.aop_immd2);
       } else if (bit16)
-       sprintf (s, "#%s", aop->aopu.aop_immd.aop_immd1);
+        sprintf (s, "#%s", aop->aopu.aop_immd.aop_immd1);
       else if (loffset)
         {
           if (loffset!=1)
-           sprintf (s, "#(%s >> %d)",
-                    aop->aopu.aop_immd.aop_immd1,
-                    loffset * 8);
-         else
-           sprintf (s, "#>%s",
-                    aop->aopu.aop_immd.aop_immd1);
+            sprintf (s, "#(%s >> %d)",
+                     aop->aopu.aop_immd.aop_immd1,
+                     loffset * 8);
+          else
+            sprintf (s, "#>%s",
+                     aop->aopu.aop_immd.aop_immd1);
         }
       else
-       sprintf (s, "#%s",
-                aop->aopu.aop_immd.aop_immd1);
+        sprintf (s, "#%s",
+                 aop->aopu.aop_immd.aop_immd1);
       rs = Safe_calloc (1, strlen (s) + 1);
       strcpy (rs, s);
       return rs;
 
     case AOP_DIR:
       if (offset)
-       sprintf (s, "*(%s + %d)",
-                aop->aopu.aop_dir,
-                offset);
+        sprintf (s, "*(%s + %d)",
+                 aop->aopu.aop_dir,
+                 offset);
       else
-       sprintf (s, "*%s", aop->aopu.aop_dir);
+        sprintf (s, "*%s", aop->aopu.aop_dir);
       rs = Safe_calloc (1, strlen (s) + 1);
       strcpy (rs, s);
       return rs;
 
     case AOP_EXT:
       if (offset)
-       sprintf (s, "(%s + %d)",
-                aop->aopu.aop_dir,
-                offset);
+        sprintf (s, "(%s + %d)",
+                 aop->aopu.aop_dir,
+                 offset);
       else
-       sprintf (s, "%s", aop->aopu.aop_dir);
+        sprintf (s, "%s", aop->aopu.aop_dir);
       rs = Safe_calloc (1, strlen (s) + 1);
       strcpy (rs, s);
       return rs;
@@ -2051,8 +2083,8 @@ aopAdrStr (asmop * aop, int loffset, bool bit16)
       return aop->aopu.aop_str[loffset];
 
     case AOP_SOF:
-       sprintf (s, "%d,s", _G.stackOfs + _G.stackPushes + aop->aopu.aop_stk
-                           + offset + 1);
+        sprintf (s, "%d,s", _G.stackOfs + _G.stackPushes + aop->aopu.aop_stk
+                            + offset + 1);
       rs = Safe_calloc (1, strlen (s) + 1);
       strcpy (rs, s);
       return rs;
@@ -2060,7 +2092,7 @@ aopAdrStr (asmop * aop, int loffset, bool bit16)
     }
 
   werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-         "aopAdrStr got unsupported aop->type");
+          "aopAdrStr got unsupported aop->type");
   exit (1);
 }
 
@@ -2156,7 +2188,7 @@ asmopToBool (asmop *aop, bool resultInA)
             emitcode ("tsta", "");
             emitcode ("bne", "%05d$", (tlbl->key + 100));
             emitcode ("tstx", "");
-            emitcode ("", "%05d$:", (tlbl->key + 100));
+            emitLabel (tlbl);
           }
         else
           {
@@ -2183,7 +2215,7 @@ asmopToBool (asmop *aop, bool resultInA)
         break;
       case AOP_LIT:
         /* Higher levels should optimize this case away but let's be safe */
-        if ((unsigned long) floatFromVal (aop->aopu.aop_lit))
+        if (ulFromVal (aop->aopu.aop_lit))
           loadRegFromConst (hc08_reg_a, one);
         else
           loadRegFromConst (hc08_reg_a, zero);
@@ -2217,7 +2249,7 @@ asmopToBool (asmop *aop, bool resultInA)
                 emitcode ("tst", "%s", aopAdrStr (aop, 0, FALSE));
                 emitcode ("bne", "%05d$", (tlbl->key + 100));
                 emitcode ("tst", "%s", aopAdrStr (aop, 1, FALSE));
-                emitcode ("", "%05d$:", (tlbl->key + 100));
+                emitLabel (tlbl);
                 break;
               }
           }
@@ -2293,8 +2325,6 @@ genCpl (iCode * ic)
   int size;
   regs* reg = hc08_reg_a;
   
-//  symbol *tlbl;
-
   D(emitcode (";     genCpl",""));
 
   /* assign asmOps to operand & result */
@@ -2394,10 +2424,10 @@ genUminus (iCode * ic)
   else
     {
       if (IS_AOP_XA (AOP (IC_RESULT (ic))))
-        result = forceStackedAop (AOP (IC_RESULT (ic)));
+        result = forceStackedAop (AOP (IC_RESULT (ic)), FALSE);
       else
         result = AOP (IC_RESULT (ic));
-       
+        
       needpula = pushRegIfUsed (hc08_reg_a);
       sub="sub";
       while (size--)
@@ -2456,7 +2486,7 @@ saveRegisters (iCode * lic)
   /* safe the registers in use at this time but skip the
      ones for the result */
   rsave = bitVectCplAnd (bitVectCopy (ic->rMask), 
-                        hc08_rUmaskForOp (IC_RESULT(ic)));
+                         hc08_rUmaskForOp (IC_RESULT(ic)));
 
   ic->regsSaved = 1;
   for (i = 0; i < hc08_nRegs; i++)
@@ -2478,7 +2508,7 @@ unsaveRegisters (iCode * ic)
   /* restore the registers in use at this time but skip the
      ones for the result */
   rsave = bitVectCplAnd (bitVectCopy (ic->rMask), 
-                        hc08_rUmaskForOp (IC_RESULT(ic)));
+                         hc08_rUmaskForOp (IC_RESULT(ic)));
 
   for (i = hc08_nRegs; i >= 0; i--)
     {
@@ -2529,7 +2559,6 @@ static void
 genIpush (iCode * ic)
 {
   int size, offset = 0;
-//  char *l;
 
   D(emitcode (";     genIpush",""));
 
@@ -2540,7 +2569,7 @@ genIpush (iCode * ic)
 
       /* and the item is spilt then do nothing */
       if (OP_SYMBOL (IC_LEFT (ic))->isspilt)
-       return;
+        return;
 
       aopOp (IC_LEFT (ic), ic, FALSE);
       size = AOP_SIZE (IC_LEFT (ic));
@@ -2618,7 +2647,7 @@ genIpop (iCode * ic)
 
 
 /*-----------------------------------------------------------------*/
-/* genSend - gen code for SEND                                    */
+/* genSend - gen code for SEND                                     */
 /*-----------------------------------------------------------------*/
 static void genSend(set *sendSet)
 {
@@ -2626,19 +2655,19 @@ static void genSend(set *sendSet)
 
     for (sic = setFirstItem (sendSet); sic;
          sic = setNextItem (sendSet)) {
-         int size, offset = 0;
-         aopOp (IC_LEFT (sic), sic, FALSE);
-         size = AOP_SIZE (IC_LEFT (sic));
+          int size, offset = 0;
+          aopOp (IC_LEFT (sic), sic, FALSE);
+          size = AOP_SIZE (IC_LEFT (sic));
 
           if (sic->argreg) {
-             offset = size-1;
-             while (size--) {
-                 transferAopAop( AOP (IC_LEFT (sic)), offset,
-                                 hc08_aop_pass[offset+(sic->argreg-1)], 0);
-                 offset--;
-             }
-         }       
-         freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
+              offset = size-1;
+              while (size--) {
+                  transferAopAop( AOP (IC_LEFT (sic)), offset,
+                                  hc08_aop_pass[offset+(sic->argreg-1)], 0);
+                  offset--;
+              }
+          }       
+          freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
     }
 }
 
@@ -2658,11 +2687,11 @@ genCall (iCode * ic)
   /* if send set is not empty then assign */
   if (_G.sendSet)
     {
-       if (IFFUNC_ISREENT(dtype)) { /* need to reverse the send set */
-           genSend(reverseSet(_G.sendSet));
-       } else {
-           genSend(_G.sendSet);
-       }
+        if (IFFUNC_ISREENT(dtype)) { /* need to reverse the send set */
+            genSend(reverseSet(_G.sendSet));
+        } else {
+            genSend(_G.sendSet);
+        }
 
       _G.sendSet = NULL;
     }
@@ -2674,15 +2703,15 @@ genCall (iCode * ic)
 
   /* make the call */
   emitcode ("jsr", "%s", (OP_SYMBOL (IC_LEFT (ic))->rname[0] ?
-                         OP_SYMBOL (IC_LEFT (ic))->rname :
-                         OP_SYMBOL (IC_LEFT (ic))->name));
+                          OP_SYMBOL (IC_LEFT (ic))->rname :
+                          OP_SYMBOL (IC_LEFT (ic))->name));
 
 
   /* if we need assign a result value */
   if ((IS_ITEMP (IC_RESULT (ic)) &&
        (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
-       OP_SYMBOL (IC_RESULT (ic))->accuse || 
-       OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+        OP_SYMBOL (IC_RESULT (ic))->accuse || 
+        OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
       IS_TRUE_SYMOP (IC_RESULT (ic)))
     {
 
@@ -2735,6 +2764,8 @@ genPcall (iCode * ic)
   emitBranch ("bsr", tlbl);
   emitBranch ("bra", rlbl);
   emitLabel (tlbl);
+  _G.stackPushes += 2; /* account for the bsr return address now on stack */
+  updateCFA();
 
   /* Push the function's address */
   aopOp (IC_LEFT (ic), ic, FALSE);
@@ -2744,8 +2775,8 @@ genPcall (iCode * ic)
   /* if send set is not empty the assign */
   if (_G.sendSet)
     {
-       genSend(reverseSet(_G.sendSet));
-       _G.sendSet = NULL;
+        genSend(reverseSet(_G.sendSet));
+        _G.sendSet = NULL;
     }
 
 
@@ -2753,12 +2784,14 @@ genPcall (iCode * ic)
   emitcode ("rts", "");
 
   emitLabel (rlbl);
+  _G.stackPushes -= 4; /* account for rts here & in called function */
+  updateCFA();
 
 
   /* if we need assign a result value */
   if ((IS_ITEMP (IC_RESULT (ic)) &&
        (OP_SYMBOL (IC_RESULT (ic))->nRegs ||
-       OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
+        OP_SYMBOL (IC_RESULT (ic))->spildir)) ||
       IS_TRUE_SYMOP (IC_RESULT (ic)))
     {
 
@@ -2797,18 +2830,12 @@ resultRemat (iCode * ic)
     {
       symbol *sym = OP_SYMBOL (IC_RESULT (ic));
       if (sym->remat && !POINTER_SET (ic))
-       return 1;
+        return 1;
     }
 
   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   */
 /*-----------------------------------------------------------------*/
@@ -2850,6 +2877,7 @@ genFunction (iCode * ic)
   emitcode (";", "-----------------------------------------");
 
   emitcode ("", "%s:", sym->rname);
+  lineCurr->isLabel = 1;
   ftype = operandType (IC_LEFT (ic));
   
   _G.stackOfs = 0;
@@ -3003,37 +3031,37 @@ genEndFunction (iCode * ic)
 
       /* if debug then send end of function */
       if (options.debug && currFunc)
-       {
-         debugFile->writeEndFunction (currFunc, ic, 1);
-       }
+        {
+          debugFile->writeEndFunction (currFunc, ic, 1);
+        }
 
       emitcode ("rti", "");
     }
   else
     {
       if (IFFUNC_CALLEESAVES(sym->type))
-       {
-         int i;
-
-         /* if any registers used */
-         if (sym->regsUsed)
-           {
-             /* save the registers used */
-             for (i = sym->regsUsed->size; i >= 0; i--)
-               {
-                 if (bitVectBitValue (sym->regsUsed, i) ||
-                     (hc08_ptrRegReq && (i == HX_IDX || i == HX_IDX)))
-                   emitcode ("pop", "%s", hc08_regWithIdx (i)->name);
-               }
-           }
-
-       }
+        {
+          int i;
+
+          /* if any registers used */
+          if (sym->regsUsed)
+            {
+              /* save the registers used */
+              for (i = sym->regsUsed->size; i >= 0; i--)
+                {
+                  if (bitVectBitValue (sym->regsUsed, i) ||
+                      (hc08_ptrRegReq && (i == HX_IDX || i == HX_IDX)))
+                    emitcode ("pop", "%s", hc08_regWithIdx (i)->name);
+                }
+            }
+
+        }
 
       /* if debug then send end of function */
       if (options.debug && currFunc)
-       {
-         debugFile->writeEndFunction (currFunc, ic, 1);
-       }
+        {
+          debugFile->writeEndFunction (currFunc, ic, 1);
+        }
 
       emitcode ("rts", "");
     }
@@ -3100,7 +3128,7 @@ jumpret:
   /* generate a jump to the return label
      if the next is not the return statement */
   if (!(ic->next && ic->next->op == LABEL &&
-       IC_LABEL (ic->next) == returnLabel))
+        IC_LABEL (ic->next) == returnLabel))
 
     emitcode ("jmp", "%05d$", (returnLabel->key + 100));
 
@@ -3127,10 +3155,10 @@ genLabel (iCode * ic)
   /* special case never generate */
   if (IC_LABEL (ic) == entryLabel)
     return;
-         
+          
   debugFile->writeLabel(IC_LABEL (ic), ic);
 
-  emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100));
+  emitLabel (IC_LABEL (ic));
 
 }
 
@@ -3161,16 +3189,16 @@ findLabelBackwards (iCode * ic, int key)
       count++;
 
       /* If we have any pushes or pops, we cannot predict the distance.
-        I don't like this at all, this should be dealt with in the 
-        back-end */
+         I don't like this at all, this should be dealt with in the 
+         back-end */
       if (ic->op == IPUSH || ic->op == IPOP) {
-       return 0;
+        return 0;
       }
 
       if (ic->op == LABEL && IC_LABEL (ic)->key == key)
-       {
-         return count;
-       }
+        {
+          return count;
+        }
     }
 
   return 0;
@@ -3202,9 +3230,9 @@ genPlusIncr (iCode * ic)
   if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
     return FALSE;
 
-  icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+  icount = (unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
 
-  D(emitcode ("", "; IS_AOP_HX = %d", IS_AOP_HX (AOP (left))));
+  DD(emitcode ("", "; IS_AOP_HX = %d", IS_AOP_HX (AOP (left))));
   
   if ((IS_AOP_HX (AOP (left)) ||
        ( (AOP_TYPE (left) == AOP_DIR) && (AOP_TYPE (result) == AOP_DIR) )
@@ -3230,7 +3258,7 @@ genPlusIncr (iCode * ic)
       return TRUE;
     }
 
-  D(emitcode ("", "; icount = %d, sameRegs=%d", icount, 
+  DD(emitcode ("", "; icount = %d, sameRegs=%d", icount, 
             sameRegs (AOP (left), AOP (result))));
   
   if ((icount > 255) || (icount<0))
@@ -3315,9 +3343,9 @@ genPlus (iCode * ic)
   if (genPlusIncr (ic) == TRUE)
     goto release;
 
-  D(emitcode("",";  left size = %d", getDataSize (IC_LEFT(ic))));
-  D(emitcode("",";  right size = %d", getDataSize (IC_RIGHT(ic))));
-  D(emitcode("",";  result size = %d", getDataSize (IC_RESULT(ic))));
+  DD(emitcode("",";  left size = %d", getDataSize (IC_LEFT(ic))));
+  DD(emitcode("",";  right size = %d", getDataSize (IC_RIGHT(ic))));
+  DD(emitcode("",";  result size = %d", getDataSize (IC_RESULT(ic))));
   
   size = getDataSize (IC_RESULT (ic));
 
@@ -3368,7 +3396,7 @@ genMinusDec (iCode * ic)
   if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
     return FALSE;
 
-  icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
+  icount = (unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
 
   if ((AOP_TYPE (left) == AOP_DIR) && (AOP_TYPE (result) == AOP_DIR)
       && (icount>=-127) && (icount<=128) && (size==2))
@@ -3418,16 +3446,16 @@ addSign (operand * result, int offset, int sign)
   if (size > 0)
     {
       if (sign)
-       {
-         emitcode ("rola", "");
-         emitcode ("clra", "");
-         emitcode ("sbc", zero);
-         while (size--)
-           storeRegToAop (hc08_reg_a, AOP (result), offset++);
-       }
+        {
+          emitcode ("rola", "");
+          emitcode ("clra", "");
+          emitcode ("sbc", zero);
+          while (size--)
+            storeRegToAop (hc08_reg_a, AOP (result), offset++);
+        }
       else
-       while (size--)
-         storeConstToAop (zero, AOP (result), offset++);
+        while (size--)
+          storeConstToAop (zero, AOP (result), offset++);
     }
 }
 
@@ -3496,8 +3524,8 @@ release:
 /*-----------------------------------------------------------------*/
 static void
 genMultOneByte (operand * left,
-               operand * right,
-               operand * result)
+                operand * right,
+                operand * result)
 {
   /* sym_link *opetype = operandType (result); */
   symbol *tlbl1, *tlbl2, *tlbl3, *tlbl4;
@@ -3510,7 +3538,7 @@ genMultOneByte (operand * left,
   if (size<1 || size>2) {
     // this should never happen
       fprintf (stderr, "size!=1||2 (%d) in %s at line:%d \n", 
-              AOP_SIZE(result), __FILE__, lineno);
+               AOP_SIZE(result), __FILE__, lineno);
       exit (1);
   }
 
@@ -3548,7 +3576,7 @@ genMultOneByte (operand * left,
       || (lUnsigned && rUnsigned))
     {
       // just an unsigned 8*8=8/16 multiply
-      //D(emitcode (";","unsigned"));
+      //DD(emitcode (";","unsigned"));
 
       loadRegFromAop (hc08_reg_a, AOP (left), 0);
       loadRegFromAop (hc08_reg_x, AOP (right), 0);
@@ -3566,7 +3594,7 @@ genMultOneByte (operand * left,
   /* left unsigned, right signed literal -- literal determines sign handling */
   if (AOP_TYPE(right)==AOP_LIT && lUnsigned && !rUnsigned)
     {
-      signed char val=(signed char)floatFromVal (AOP (right)->aopu.aop_lit);
+      signed char val=(signed char) ulFromVal (AOP (right)->aopu.aop_lit);
       
       loadRegFromAop (hc08_reg_a, AOP (left), 0);
       if (val < 0)
@@ -3610,7 +3638,7 @@ genMultOneByte (operand * left,
 
   if (AOP_TYPE(right)==AOP_LIT && !rUnsigned)
     {
-      signed char val=(signed char)floatFromVal (AOP (right)->aopu.aop_lit);
+      signed char val=(signed char) ulFromVal (AOP (right)->aopu.aop_lit);
       /* AND literal negative */
       if (val < 0) {
         emitcode ("ldx", "#0x%02x", -val);
@@ -3688,9 +3716,9 @@ genMult (iCode * ic)
 
   /* should have been converted to function call */
     fprintf (stderr, "left: %d right: %d\n", getSize(OP_SYMBOL(left)->type),
-            getSize(OP_SYMBOL(right)->type));
+             getSize(OP_SYMBOL(right)->type));
     fprintf (stderr, "left: %d right: %d\n", AOP_SIZE (left),
-            AOP_SIZE (right));
+             AOP_SIZE (right));
   assert (0);
 
 release:
@@ -3704,8 +3732,8 @@ release:
 /*-----------------------------------------------------------------*/
 static void
 genDivOneByte (operand * left,
-              operand * right,
-              operand * result)
+               operand * right,
+               operand * result)
 {
   symbol *tlbl1, *tlbl2, *tlbl3;
   int size;
@@ -3751,7 +3779,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;
         }
@@ -3765,7 +3793,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;
         }
@@ -3787,7 +3815,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 ("ldx", "#0x%02x", -val);
@@ -3810,7 +3838,7 @@ genDivOneByte (operand * left,
 
   if (AOP_TYPE(left) == AOP_LIT)
     {
-      signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit);
+      signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit);
 
       if (!lUnsigned && val < 0)
         emitcode ("lda", "#0x%02x", -val);
@@ -3919,8 +3947,8 @@ release:
 /*-----------------------------------------------------------------*/
 static void
 genModOneByte (operand * left,
-              operand * right,
-              operand * result)
+               operand * right,
+               operand * result)
 {
   symbol *tlbl1, *tlbl2, *tlbl3;
   int size;
@@ -3954,7 +3982,7 @@ genModOneByte (operand * left,
   
   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 ("ldx", "#0x%02x", -val);
@@ -3983,7 +4011,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)
         {
@@ -4165,7 +4193,7 @@ exchangedCmp (int opcode)
       return EQ_OP;
     default:
       werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                 "opcode not a comparison");
+                  "opcode not a comparison");
     }
   return EQ_OP; /* shouldn't happen, but need to return something */
 }
@@ -4193,13 +4221,14 @@ negatedCmp (int opcode)
       return NE_OP;
     default:
       werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                 "opcode not a comparison");
+                  "opcode not a comparison");
     }
   return EQ_OP; /* shouldn't happen, but need to return something */
 }
 
-/* compile only if the debugging macro D is enabled */
-#if (D(1) -0)
+/*------------------------------------------------------------------*/
+/* nameCmp : helper function for human readable debug output        */
+/*------------------------------------------------------------------*/
 static char *
 nameCmp (int opcode)
 {
@@ -4221,7 +4250,6 @@ nameCmp (int opcode)
       return "invalid";
     }
 }
-#endif
 
 /*------------------------------------------------------------------*/
 /* branchInstCmp : returns the conditional branch instruction that  */
@@ -4236,7 +4264,7 @@ branchInstCmp (int opcode, int sign)
       if (sign)
         return "blt";
       else
-        return "bcs";  /* same as blo */
+        return "bcs";   /* same as blo */
     case '>':
       if (sign)
         return "bgt";
@@ -4251,14 +4279,14 @@ branchInstCmp (int opcode, int sign)
       if (sign)
         return "bge";
       else
-        return "bcc";  /* same as bhs */
+        return "bcc";   /* same as bhs */
     case NE_OP:
       return "bne";
     case EQ_OP:
       return "beq";
     default:
       werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
-                 "opcode not a comparison");
+                  "opcode not a comparison");
     }
   return "brn";
 }
@@ -4354,7 +4382,7 @@ genCmp (iCode * ic, iCode * ifx)
           
           if ((AOP_TYPE (right) == AOP_LIT) && !isOperandVolatile (left, FALSE))
             {
-              lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit);
+              lit = ulFromVal (AOP (right)->aopu.aop_lit);
               while ((size > 1) && (((lit >> (8*offset)) & 0xff) == 0))
                 {
                   offset++;
@@ -4586,19 +4614,19 @@ genPointerGetSetOfs (iCode *ic)
   asmop *derefaop;
 
   /* Make sure we have a next iCode */
-  D(emitcode("","; checking lic"));
+  DD(emitcode("","; checking lic"));
   if (!lic)
     return FALSE;
 
   /* Make sure the result of the addition is an iCode */
-  D(emitcode("","; checking IS_ITEMP"));
+  DD(emitcode("","; checking IS_ITEMP"));
   if (!IS_ITEMP (IC_RESULT (ic)))
     return FALSE;
 
   /* Make sure the next iCode is a pointer set or get */
   pset = POINTER_SET(lic);
   pget = POINTER_GET(lic);
-  D(emitcode("","; pset=%d, pget=%d",pset,pget));
+  DD(emitcode("","; pset=%d, pget=%d",pset,pget));
   if (!pset && !pget)
     return FALSE;
 
@@ -4606,25 +4634,25 @@ genPointerGetSetOfs (iCode *ic)
   if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) > 1)
     return FALSE;
     
-  D(emitcode("", "; checking pset operandsEqu"));
+  DD(emitcode("", "; checking pset operandsEqu"));
   if (pset & !operandsEqu (IC_RESULT (ic), IC_RESULT (lic)))
     return FALSE;
 
-  D(emitcode("", "; checking pget operandsEqu"));
+  DD(emitcode("", "; checking pget operandsEqu"));
   if (pget & !operandsEqu (IC_RESULT (ic), IC_LEFT (lic)))
     return FALSE;
 
-  D(emitcode("", "; checking IS_SYMOP"));
+  DD(emitcode("", "; checking IS_SYMOP"));
   if (!IS_SYMOP (IC_LEFT (ic)))
     return FALSE;
 
-  D(emitcode("", "; checking !IS_TRUE_SYMOP"));
+  DD(emitcode("", "; checking !IS_TRUE_SYMOP"));
   if (IS_TRUE_SYMOP (IC_LEFT (ic)))
     return FALSE;
 
   sym = OP_SYMBOL (IC_LEFT (ic));
   
-  D(emitcode("", "; checking remat"));
+  DD(emitcode("", "; checking remat"));
   if (!sym->remat)
     return FALSE;
     
@@ -4757,9 +4785,9 @@ hasInc (operand *op, iCode *ic,int osize)
   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) {
+        isOperandEqual(IC_RESULT(lic),op) && 
+        isOperandLiteral(IC_RIGHT(lic)) &&
+        operandLitValue(IC_RIGHT(lic)) == isize) {
       return lic;
     }
     /* if the operand used or deffed */
@@ -4949,12 +4977,12 @@ genAnd (iCode * ic, iCode * ifx)
   aopOp ((result = IC_RESULT (ic)), ic, TRUE);
 
 #ifdef DEBUG_TYPE
-  D(emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
-           AOP_TYPE (result),
-           AOP_TYPE (left), AOP_TYPE (right)));
-  D(emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
-           AOP_SIZE (result),
-           AOP_SIZE (left), AOP_SIZE (right)));
+  DD(emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+            AOP_TYPE (result),
+            AOP_TYPE (left), AOP_TYPE (right)));
+  DD(emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+            AOP_SIZE (result),
+            AOP_SIZE (left), AOP_SIZE (right)));
 #endif
 
   /* if left is a literal & right is not then exchange them */
@@ -4974,7 +5002,7 @@ genAnd (iCode * ic, iCode * ifx)
     }
 
   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 (left) >= AOP_SIZE (right)) ? AOP_SIZE (left) : AOP_SIZE (right);
   
@@ -5113,12 +5141,12 @@ genOr (iCode * ic, iCode * ifx)
   aopOp ((result = IC_RESULT (ic)), ic, TRUE);
 
 #ifdef DEBUG_TYPE
-  D(emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
-           AOP_TYPE (result),
-           AOP_TYPE (left), AOP_TYPE (right)));
-  D(emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
-           AOP_SIZE (result),
-           AOP_SIZE (left), AOP_SIZE (right)));
+  DD(emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+            AOP_TYPE (result),
+            AOP_TYPE (left), AOP_TYPE (right)));
+  DD(emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+            AOP_SIZE (result),
+            AOP_SIZE (left), AOP_SIZE (right)));
 #endif
 
   /* if left is a literal & right is not then exchange them */
@@ -5138,7 +5166,7 @@ genOr (iCode * ic, iCode * ifx)
     }
 
   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 (left) >= AOP_SIZE (right)) ? AOP_SIZE (left) : AOP_SIZE (right);
   
@@ -5206,7 +5234,7 @@ genOr (iCode * ic, iCode * ifx)
     }
   
   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);
 
@@ -5272,12 +5300,12 @@ genXor (iCode * ic, iCode * ifx)
   aopOp ((result = IC_RESULT (ic)), ic, TRUE);
 
 #ifdef DEBUG_TYPE
-  D(emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
-           AOP_TYPE (result),
-           AOP_TYPE (left), AOP_TYPE (right)));
-  D(emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
-           AOP_SIZE (result),
-           AOP_SIZE (left), AOP_SIZE (right)));
+  DD(emitcode ("", "; Type res[%d] = l[%d]&r[%d]",
+            AOP_TYPE (result),
+            AOP_TYPE (left), AOP_TYPE (right)));
+  DD(emitcode ("", "; Size res[%d] = l[%d]&r[%d]",
+            AOP_SIZE (result),
+            AOP_SIZE (left), AOP_SIZE (right)));
 #endif
 
   /* if left is a literal & right is not ||
@@ -5326,7 +5354,7 @@ genXor (iCode * ic, iCode * ifx)
     }
     
   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);
   offset = 0;
@@ -5423,44 +5451,51 @@ static void
 genInline (iCode * ic)
 {
   char *buffer, *bp, *bp1;
+  bool inComment = FALSE;
 
   D(emitcode (";     genInline",""));
 
   _G.inLine += (!options.asmpeep);
 
-  buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
-  strcpy (buffer, IC_INLINE (ic));
+  buffer = bp = bp1 = Safe_strdup (IC_INLINE(ic));
 
   /* emit each line as a code */
   while (*bp)
     {
-      if (*bp == '\n')
-       {
-         *bp++ = '\0';
-         /* emitcode (bp1, ""); */
-         emitinline (ic, bp1);
-         bp1 = bp;
-       }
-      else
-       {
-         if (*bp == ':')
-           {
-             bp++;
-             *bp = '\0';
-             bp++;
-             emitcode (bp1, "");
-             bp1 = bp;
-           }
-         else
-           bp++;
-       }
+      switch (*bp)
+        {
+        case ';':
+          inComment = TRUE;
+          ++bp;
+          break;
+
+        case '\n':
+          inComment = FALSE;
+          *bp++ = '\0';
+          emitinline (ic, bp1);
+          bp1 = bp;
+          break;
+
+        default:
+          /* Add \n for labels, not dirs such as c:\mydir */
+          if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+            {
+              ++bp;
+              *bp = '\0';
+              ++bp;
+              emitcode (bp1, "");
+              bp1 = bp;
+            }
+          else
+            ++bp;
+          break;
+        }
     }
   if (bp1 != bp)
-    {
-      /* emitcode (bp1, ""); */
-      emitinline (ic, bp1);
-    }
-  /*     emitcode("",buffer); */
+    emitinline (ic, bp1);
+
+  Safe_free (buffer);
+
   _G.inLine -= (!options.asmpeep);
 }
 
@@ -5671,7 +5706,7 @@ genSwap (iCode * ic)
       hc08_freeReg (hc08_reg_a);
       break;
     case 2: /* swap bytes in a word */
-      if (operandsEqu (left, result))
+      if (operandsEqu (left, result) || sameRegs (AOP (left), AOP (result)))
         {
           loadRegFromAop (hc08_reg_a, AOP (left), 0);
           hc08_useReg (hc08_reg_a);
@@ -5700,40 +5735,40 @@ genSwap (iCode * ic)
 static void
 AccRol (int shCount)
 {
-  shCount &= 0x0007;           // shCount : 0..7
+  shCount &= 0x0007;            // shCount : 0..7
 
   switch (shCount)
     {
     case 0:
       break;
     case 1:
-      emitcode ("rola", "");   /* 1 cycle */
+      emitcode ("rola", "");    /* 1 cycle */
       break;
     case 2:
-      emitcode ("rola", "");   /* 1 cycle */
-      emitcode ("rola", "");   /* 1 cycle */
+      emitcode ("rola", "");    /* 1 cycle */
+      emitcode ("rola", "");    /* 1 cycle */
       break;
     case 3:
       emitcode ("nsa", "");
       emitcode ("rora", "");
       break;
     case 4:
-      emitcode ("nsa", "");    /* 3 cycles */
+      emitcode ("nsa", "");     /* 3 cycles */
       break;
     case 5:
-      emitcode ("nsa", "");    /* 3 cycles */
-      emitcode ("rola", "");   /* 1 cycle */
+      emitcode ("nsa", "");     /* 3 cycles */
+      emitcode ("rola", "");    /* 1 cycle */
       break;
     case 6:
-      emitcode ("nsa", "");    /* 3 cycles */
-      emitcode ("rola", "");   /* 1 cycle */
-      emitcode ("rola", "");   /* 1 cycle */
+      emitcode ("nsa", "");     /* 3 cycles */
+      emitcode ("rola", "");    /* 1 cycle */
+      emitcode ("rola", "");    /* 1 cycle */
       break;
     case 7:
-      emitcode ("nsa", "");    /* 3 cycles */
-      emitcode ("rola", "");   /* 1 cycle */
-      emitcode ("rola", "");   /* 1 cycle */
-      emitcode ("rola", "");   /* 1 cycle */
+      emitcode ("nsa", "");     /* 3 cycles */
+      emitcode ("rola", "");    /* 1 cycle */
+      emitcode ("rola", "");    /* 1 cycle */
+      emitcode ("rola", "");    /* 1 cycle */
       break;
     }
 }
@@ -5748,7 +5783,7 @@ AccLsh (int shCount)
 {
   int i;
   
-  shCount &= 0x0007;           // shCount : 0..7
+  shCount &= 0x0007;            // shCount : 0..7
 
   /* Shift counts of 4 and 5 are currently optimized for code size.        */
   /* Falling through to the unrolled loop would be optimal for code speed. */
@@ -5800,7 +5835,7 @@ AccSRsh (int shCount)
 {
   int i;
   
-  shCount &= 0x0007;           // shCount : 0..7
+  shCount &= 0x0007;            // shCount : 0..7
 
   if (shCount == 7)
     {
@@ -5829,7 +5864,7 @@ AccRsh (int shCount, bool sign)
       return;
     }
   
-  shCount &= 0x0007;           // shCount : 0..7
+  shCount &= 0x0007;            // shCount : 0..7
 
   /* Shift counts of 4 and 5 are currently optimized for code size.        */
   /* Falling through to the unrolled loop would be optimal for code speed. */
@@ -5881,7 +5916,7 @@ XAccLsh (int shCount)
 {
   int i;
   
-  shCount &= 0x000f;           // shCount : 0..15
+  shCount &= 0x000f;            // shCount : 0..15
 
   if (shCount>=8)
     {
@@ -5932,7 +5967,7 @@ XAccSRsh (int shCount)
 {
   int i;
   
-  shCount &= 0x000f;           // shCount : 0..7
+  shCount &= 0x000f;            // shCount : 0..7
 
   /* if we can beat 2n cycles or bytes for some special case, do it here */
   switch (shCount)
@@ -6008,7 +6043,7 @@ XAccRsh (int shCount, bool sign)
       return;
     }
   
-  shCount &= 0x000f;           // shCount : 0..f
+  shCount &= 0x000f;            // shCount : 0..f
 
   /* if we can beat 2n cycles or bytes for some special case, do it here */
   switch (shCount)
@@ -6109,8 +6144,8 @@ XAccRsh (int shCount, bool sign)
 /*-----------------------------------------------------------------*/
 static void
 shiftR1Left2Result (operand * left, int offl,
-                   operand * result, int offr,
-                   int shCount, int sign)
+                    operand * result, int offr,
+                    int shCount, int sign)
 {
   loadRegFromAop (hc08_reg_a, AOP (left), offl);
   /* shift right accumulator */
@@ -6124,7 +6159,7 @@ shiftR1Left2Result (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 shiftL1Left2Result (operand * left, int offl,
-                   operand * result, int offr, int shCount)
+                    operand * result, int offr, int shCount)
 {
   loadRegFromAop (hc08_reg_a, AOP (left), offl);
   /* shift left accumulator */
@@ -6137,7 +6172,7 @@ shiftL1Left2Result (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 movLeft2Result (operand * left, int offl,
-               operand * result, int offr, int sign)
+                operand * result, int offr, int sign)
 {
   if (!sameRegs (AOP (left), AOP (result)) || (offl != offr))
     {
@@ -6151,7 +6186,7 @@ movLeft2Result (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 shiftL2Left2Result (operand * left, int offl,
-                   operand * result, int offr, int shCount)
+                    operand * result, int offr, int shCount)
 {
   int i;
   bool needpula = FALSE;
@@ -6198,8 +6233,8 @@ shiftL2Left2Result (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 shiftR2Left2Result (operand * left, int offl,
-                   operand * result, int offr,
-                   int shCount, int sign)
+                    operand * result, int offr,
+                    int shCount, int sign)
 {
   int i;
   bool needpula = FALSE;
@@ -6230,7 +6265,7 @@ shiftR2Left2Result (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 shiftLLeftOrResult (operand * left, int offl,
-                   operand * result, int offr, int shCount)
+                    operand * result, int offr, int shCount)
 {
   loadRegFromAop (hc08_reg_a, AOP (left), offl);
   /* shift left accumulator */
@@ -6248,7 +6283,7 @@ shiftLLeftOrResult (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 shiftRLeftOrResult (operand * left, int offl,
-                   operand * result, int offr, int shCount)
+                    operand * result, int offr, int shCount)
 {
   loadRegFromAop (hc08_reg_a, AOP (left), offl);
   /* shift left accumulator */
@@ -6290,11 +6325,11 @@ genlshTwo (operand * result, operand * left, int shCount)
       shCount -= 8;
 
       if (size > 1)
-       {
+        {
           loadRegFromAop (hc08_reg_a, AOP (left), 0);
           AccLsh (shCount);
-         storeRegToAop (hc08_reg_a, AOP (result), 1);
-       }
+          storeRegToAop (hc08_reg_a, AOP (result), 1);
+        }
       storeConstToAop(zero, AOP (result), LSB);
     }
 
@@ -6368,11 +6403,11 @@ genlshFour (operand * result, operand * left, int shCount)
     {
       shCount -= 24;
       if (shCount)
-       /* lowest order of left goes to the highest
-          order of the destination */
-       shiftL1Left2Result (left, LSB, result, MSB32, shCount);
+        /* lowest order of left goes to the highest
+           order of the destination */
+        shiftL1Left2Result (left, LSB, result, MSB32, shCount);
       else
-       movLeft2Result (left, LSB, result, MSB32, 0);
+        movLeft2Result (left, LSB, result, MSB32, 0);
       storeConstToAop (zero, AOP (result), LSB);
       storeConstToAop (zero, AOP (result), MSB16);
       storeConstToAop (zero, AOP (result), MSB24);
@@ -6386,12 +6421,12 @@ genlshFour (operand * result, operand * left, int shCount)
       shCount -= 16;
       /* if some more remaining */
       if (shCount)
-       shiftL2Left2Result (left, LSB, result, MSB24, shCount);
+        shiftL2Left2Result (left, LSB, result, MSB24, shCount);
       else
-       {
-         movLeft2Result (left, MSB16, result, MSB32, 0);
-         movLeft2Result (left, LSB, result, MSB24, 0);
-       }
+        {
+          movLeft2Result (left, MSB16, result, MSB32, 0);
+          movLeft2Result (left, LSB, result, MSB24, 0);
+        }
       storeConstToAop (zero, AOP (result), LSB);
       storeConstToAop (zero, AOP (result), MSB16);
       return;
@@ -6403,31 +6438,31 @@ genlshFour (operand * result, operand * left, int shCount)
       /* lower order three bytes goes to higher order  three bytes */
       shCount -= 8;
       if (size == 2)
-       {
-         if (shCount)
-           shiftL1Left2Result (left, LSB, result, MSB16, shCount);
-         else
-           movLeft2Result (left, LSB, result, MSB16, 0);
-       }
+        {
+          if (shCount)
+            shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+          else
+            movLeft2Result (left, LSB, result, MSB16, 0);
+        }
       else
-       {                       /* size = 4 */
-         if (shCount == 0)
-           {
-             movLeft2Result (left, MSB24, result, MSB32, 0);
-             movLeft2Result (left, MSB16, result, MSB24, 0);
-             movLeft2Result (left, LSB, result, MSB16, 0);
+        {                       /* size = 4 */
+          if (shCount == 0)
+            {
+              movLeft2Result (left, MSB24, result, MSB32, 0);
+              movLeft2Result (left, MSB16, result, MSB24, 0);
+              movLeft2Result (left, LSB, result, MSB16, 0);
               storeConstToAop (zero, AOP (result), LSB);
-           }
-         else if (shCount == 1)
-           shiftLLong (left, result, MSB16);
-         else
-           {
-             shiftL2Left2Result (left, MSB16, result, MSB24, shCount);
-             shiftL1Left2Result (left, LSB, result, MSB16, shCount);
-             shiftRLeftOrResult (left, LSB, result, MSB24, 8 - shCount);
+            }
+          else if (shCount == 1)
+            shiftLLong (left, result, MSB16);
+          else
+            {
+              shiftL2Left2Result (left, MSB16, result, MSB24, shCount);
+              shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+              shiftRLeftOrResult (left, LSB, result, MSB24, 8 - shCount);
               storeConstToAop (zero, AOP (result), LSB);
-           }
-       }
+            }
+        }
     }
 
   /* 1 <= shCount <= 7 */
@@ -6435,7 +6470,7 @@ genlshFour (operand * result, operand * left, int shCount)
     {
       shiftLLong (left, result, LSB);
       if (shCount == 2)
-       shiftLLong (result, result, LSB);
+        shiftLLong (result, result, LSB);
     }
   /* 3 <= shCount <= 7, optimize */
   else
@@ -6451,11 +6486,11 @@ genlshFour (operand * result, operand * left, int shCount)
 /*-----------------------------------------------------------------*/
 static void
 genLeftShiftLiteral (operand * left,
-                    operand * right,
-                    operand * result,
-                    iCode * ic)
+                     operand * right,
+                     operand * result,
+                     iCode * ic)
 {
-  int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+  int shCount = (int) ulFromVal (AOP (right)->aopu.aop_lit);
   int size;
 
   D(emitcode (";     genLeftShiftLiteral",""));
@@ -6469,8 +6504,8 @@ genLeftShiftLiteral (operand * left,
   size = AOP_SIZE (result);
 
 #if VIEW_SIZE
-  D(emitcode ("; shift left ", "result %d, left %d", size,
-           AOP_SIZE (left)));
+  DD(emitcode ("; shift left ", "result %d, left %d", size,
+            AOP_SIZE (left)));
 #endif
 
   if (shCount == 0)
@@ -6486,23 +6521,23 @@ genLeftShiftLiteral (operand * left,
   else
     {
       switch (size)
-       {
-       case 1:
-         genlshOne (result, left, shCount);
-         break;
-
-       case 2:
-         genlshTwo (result, left, shCount);
-         break;
-
-       case 4:
-         genlshFour (result, left, shCount);
-         break;
-       default:
-         werror (E_INTERNAL_ERROR, __FILE__, __LINE__, 
-                 "*** ack! mystery literal shift!\n");
-         break;
-       }
+        {
+        case 1:
+          genlshOne (result, left, shCount);
+          break;
+
+        case 2:
+          genlshTwo (result, left, shCount);
+          break;
+
+        case 4:
+          genlshFour (result, left, shCount);
+          break;
+        default:
+          werror (E_INTERNAL_ERROR, __FILE__, __LINE__, 
+                  "*** ack! mystery literal shift!\n");
+          break;
+        }
     }
   freeAsmop (left, NULL, ic, TRUE);
   freeAsmop (result, NULL, ic, TRUE);
@@ -6518,6 +6553,7 @@ genLeftShift (iCode * ic)
   int size, offset;
   symbol *tlbl, *tlbl1;
   char *shift;
+  asmop *aopResult;
 
   D(emitcode (";     genLeftShift",""));
 
@@ -6536,30 +6572,33 @@ genLeftShift (iCode * ic)
     }
 
   /* shift count is unknown then we have to form
-     a loop get the loop count in A : Note: we take
+     a loop get the loop count in X : Note: we take
      only the lower order byte since shifting
      more that 32 bits make no sense anyway, ( the
      largest size of an object can be only 32 bits ) */
 
   aopOp (result, ic, FALSE);
   aopOp (left, ic, FALSE);
+  aopResult = AOP (result);
 
-  if (sameRegs(AOP (right), AOP (result)) || IS_AOP_XA (AOP (result)))
-    AOP (result) = forceStackedAop (AOP (result));
+  if (sameRegs(AOP (right), AOP (result)) || IS_AOP_XA (AOP (result))
+      || isOperandVolatile (result, FALSE)) 
+    aopResult = forceStackedAop (AOP (result), sameRegs ( AOP (left), AOP (result)));
 
   /* now move the left to the result if they are not the
      same */
-  if (!sameRegs (AOP (left), AOP (result)))
+  if (!sameRegs (AOP (left), aopResult))
     {
       size = AOP_SIZE (result);
       offset = 0;
       while (size--)
-       {
-         transferAopAop (AOP (left), offset, AOP (result), offset);
-         offset++;
-       }
+        {
+          transferAopAop (AOP (left), offset, aopResult, offset);
+          offset++;
+        }
     }
   freeAsmop (left, NULL, ic, TRUE);
+  AOP (result) = aopResult;
   
   tlbl = newiTempLabel (NULL);
   size = AOP_SIZE (result);
@@ -6591,7 +6630,7 @@ genLeftShift (iCode * ic)
 /*-----------------------------------------------------------------*/
 static void
 genrshOne (operand * result, operand * left,
-          int shCount, int sign)
+           int shCount, int sign)
 {
   D(emitcode (";     genrshOne",""));
 
@@ -6605,7 +6644,7 @@ genrshOne (operand * result, operand * left,
 /*-----------------------------------------------------------------*/
 static void
 genrshTwo (operand * result, operand * left,
-          int shCount, int sign)
+           int shCount, int sign)
 {
   D(emitcode (";     genrshTwo",""));
 
@@ -6640,7 +6679,7 @@ genrshTwo (operand * result, operand * left,
 /*-----------------------------------------------------------------*/
 static void
 shiftRLong (operand * left, int offl,
-           operand * result, int sign)
+            operand * result, int sign)
 {
 //  char *l;
  // int size = AOP_SIZE (result);
@@ -6700,7 +6739,7 @@ shiftRLong (operand * left, int offl,
 /*-----------------------------------------------------------------*/
 static void
 genrshFour (operand * result, operand * left,
-           int shCount, int sign)
+            int shCount, int sign)
 {
   /* TODO: handle cases where left == result */
   
@@ -6724,51 +6763,51 @@ genrshFour (operand * result, operand * left,
   else if (shCount >= 8)
     {
       if (shCount == 1)
-       shiftRLong (left, MSB16, result, sign);
+        shiftRLong (left, MSB16, result, sign);
       else if (shCount == 8)
-       {
-         transferAopAop (AOP (left), 1, AOP (result), 0);
-         transferAopAop (AOP (left), 2, AOP (result), 1);
-         loadRegFromAop (hc08_reg_a, AOP (left), 3);
+        {
+          transferAopAop (AOP (left), 1, AOP (result), 0);
+          transferAopAop (AOP (left), 2, AOP (result), 1);
+          loadRegFromAop (hc08_reg_a, AOP (left), 3);
           storeRegToAop (hc08_reg_a, AOP (result), 2);
           storeRegSignToUpperAop (hc08_reg_a, AOP(result), 3, sign);
-       }
+        }
       else if (shCount == 9)
         {
-         shiftRLong (left, MSB16, result, sign);
+          shiftRLong (left, MSB16, result, sign);
         }
       else
-       {
-         loadRegFromAop (hc08_reg_xa, AOP (left), 1);
-         XAccRsh (shCount-8, FALSE);
-         storeRegToAop (hc08_reg_xa, AOP (result), 0);
-         loadRegFromAop (hc08_reg_x, AOP (left), 3);
-         loadRegFromConst (hc08_reg_a, zero);
-         XAccRsh (shCount-8, sign);
-         accopWithAop ("ora", AOP (result), 1);
-         storeRegToAop (hc08_reg_xa, AOP (result), 1);
+        {
+          loadRegFromAop (hc08_reg_xa, AOP (left), 1);
+          XAccRsh (shCount-8, FALSE);
+          storeRegToAop (hc08_reg_xa, AOP (result), 0);
+          loadRegFromAop (hc08_reg_x, AOP (left), 3);
+          loadRegFromConst (hc08_reg_a, zero);
+          XAccRsh (shCount-8, sign);
+          accopWithAop ("ora", AOP (result), 1);
+          storeRegToAop (hc08_reg_xa, AOP (result), 1);
           storeRegSignToUpperAop (hc08_reg_x, AOP(result), 3, sign);
-       }
+        }
     }
   else
-    {                          /* 1 <= shCount <= 7 */
+    {                           /* 1 <= shCount <= 7 */
       if (shCount == 1)
-       {
-         shiftRLong (left, LSB, result, sign);
-       }
+        {
+          shiftRLong (left, LSB, result, sign);
+        }
       else
-       {
-         loadRegFromAop (hc08_reg_xa, AOP (left), 0);
-         XAccRsh (shCount, FALSE);
-         storeRegToAop (hc08_reg_xa, AOP (result), 0);
-         loadRegFromAop (hc08_reg_a, AOP (left), 2);
-         AccLsh (8-shCount);
-         accopWithAop ("ora", AOP (result), 1);
-         storeRegToAop (hc08_reg_a, AOP (result), 1);
-         loadRegFromAop (hc08_reg_xa, AOP (left), 2);
-         XAccRsh (shCount, sign);
-         storeRegToAop (hc08_reg_xa, AOP (result), 2);
-       }
+        {
+          loadRegFromAop (hc08_reg_xa, AOP (left), 0);
+          XAccRsh (shCount, FALSE);
+          storeRegToAop (hc08_reg_xa, AOP (result), 0);
+          loadRegFromAop (hc08_reg_a, AOP (left), 2);
+          AccLsh (8-shCount);
+          accopWithAop ("ora", AOP (result), 1);
+          storeRegToAop (hc08_reg_a, AOP (result), 1);
+          loadRegFromAop (hc08_reg_xa, AOP (left), 2);
+          XAccRsh (shCount, sign);
+          storeRegToAop (hc08_reg_xa, AOP (result), 2);
+        }
     }
 }
 
@@ -6777,12 +6816,12 @@ genrshFour (operand * result, operand * left,
 /*-----------------------------------------------------------------*/
 static void
 genRightShiftLiteral (operand * left,
-                     operand * right,
-                     operand * result,
-                     iCode * ic,
-                     int sign)
+                      operand * right,
+                      operand * result,
+                      iCode * ic,
+                      int sign)
 {
-  int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+  int shCount = (int) ulFromVal (AOP (right)->aopu.aop_lit);
   int size;
 
   D(emitcode (";     genRightShiftLiteral",""));
@@ -6793,8 +6832,8 @@ genRightShiftLiteral (operand * left,
   aopOp (result, ic, FALSE);
 
 #if VIEW_SIZE
-  D(emitcode ("; shift right ", "result %d, left %d", AOP_SIZE (result),
-           AOP_SIZE (left)));
+  DD(emitcode ("; shift right ", "result %d, left %d", AOP_SIZE (result),
+            AOP_SIZE (left)));
 #endif
 
   size = getDataSize (left);
@@ -6805,34 +6844,34 @@ genRightShiftLiteral (operand * left,
     {
       size = getDataSize (result);
       while (size--)
-       transferAopAop (AOP (left), size, AOP(result), size);
+        transferAopAop (AOP (left), size, AOP(result), size);
     }
   else if (shCount >= (size * 8))
     {
       if (sign) {
-       /* get sign in acc.7 */
-       loadRegFromAop (hc08_reg_a, AOP (left), size -1);
+        /* get sign in acc.7 */
+        loadRegFromAop (hc08_reg_a, AOP (left), size -1);
       }
       addSign (result, LSB, sign);
     }
   else
     {
       switch (size)
-       {
-       case 1:
-         genrshOne (result, left, shCount, sign);
-         break;
-
-       case 2:
-         genrshTwo (result, left, shCount, sign);
-         break;
-
-       case 4:
-         genrshFour (result, left, shCount, sign);
-         break;
-       default:
-         break;
-       }
+        {
+        case 1:
+          genrshOne (result, left, shCount, sign);
+          break;
+
+        case 2:
+          genrshTwo (result, left, shCount, sign);
+          break;
+
+        case 4:
+          genrshFour (result, left, shCount, sign);
+          break;
+        default:
+          break;
+        }
     }
   freeAsmop (left, NULL, ic, TRUE);
   freeAsmop (result, NULL, ic, TRUE);
@@ -6851,6 +6890,7 @@ genRightShift (iCode * ic)
   symbol *tlbl, *tlbl1;
   char *shift;
   bool sign;
+  asmop *aopResult;
   
   D(emitcode (";     genRightShift",""));
 
@@ -6888,23 +6928,26 @@ genRightShift (iCode * ic)
 
   aopOp (result, ic, FALSE);
   aopOp (left, ic, FALSE);
+  aopResult = AOP (result);
+
+  if (sameRegs(AOP (right), AOP (result)) || IS_AOP_XA (AOP (result))
+      || isOperandVolatile (result, FALSE)) 
+    aopResult = forceStackedAop (AOP (result), sameRegs ( AOP (left), AOP (result)));
 
-  if (sameRegs(AOP (right), AOP (result)) || IS_AOP_XA (AOP (result)))
-    AOP (result) = forceStackedAop (AOP (result));
-  
   /* now move the left to the result if they are not the
      same */
-  if (!sameRegs (AOP (left), AOP (result)))
+  if (!sameRegs (AOP (left), aopResult))
     {
-      size = AOP_SIZE (result); 
+      size = AOP_SIZE (result);
       offset = 0;
       while (size--)
         {
-          transferAopAop (AOP (left), offset, AOP (result), offset);
+          transferAopAop (AOP (left), offset, aopResult, offset);
           offset++;
         }
     }
   freeAsmop (left, NULL, ic, TRUE);
+  AOP (result) = aopResult;
   
   tlbl = newiTempLabel (NULL);
   size = AOP_SIZE (result);
@@ -6938,12 +6981,12 @@ genRightShift (iCode * ic)
 static void
 genUnpackBits (operand * result, iCode *ifx)
 {
-  int offset = 0;      /* result byte offset */
-  int rsize;           /* result size */
-  int rlen = 0;                /* remaining bitfield length */
-  sym_link *etype;     /* bitfield type information */
-  int blen;            /* bitfield length */
-  int bstr;            /* bitfield starting bit within byte */
+  int offset = 0;       /* result byte offset */
+  int rsize;            /* result size */
+  int rlen = 0;         /* remaining bitfield length */
+  sym_link *etype;      /* bitfield type information */
+  int blen;             /* bitfield length */
+  int bstr;             /* bitfield starting bit within byte */
 
   D(emitcode (";     genUnpackBits",""));
 
@@ -7050,12 +7093,12 @@ genUnpackBitsImmed (operand * left,
                     iCode *ifx)
 {
   int size;
-  int offset = 0;      /* result byte offset */
-  int rsize;           /* result size */
-  int rlen = 0;                /* remaining bitfield length */
-  sym_link *etype;     /* bitfield type information */
-  int blen;            /* bitfield length */
-  int bstr;            /* bitfield starting bit within byte */
+  int offset = 0;       /* result byte offset */
+  int rsize;            /* result size */
+  int rlen = 0;         /* remaining bitfield length */
+  sym_link *etype;      /* bitfield type information */
+  int blen;             /* bitfield length */
+  int bstr;             /* bitfield starting bit within byte */
   asmop *derefaop;
   
   D(emitcode (";     genUnpackBitsImmed",""));
@@ -7217,8 +7260,8 @@ finish:
 /*-----------------------------------------------------------------*/
 static void
 genDataPointerGet (operand * left,
-                  operand * result,
-                  iCode * ic,
+                   operand * result,
+                   iCode * ic,
                    iCode * ifx)
 {
   int size;
@@ -7305,18 +7348,18 @@ genPointerGet (iCode * ic, iCode *pi, iCode *ifx)
       offset = size-1;
 
       while (size--)
-       {
-         accopWithMisc ("lda", ",x");
-         if (size || pi)
+        {
+          accopWithMisc ("lda", ",x");
+          if (size || pi)
             {
-             emitcode ("aix", "#1");
-             hc08_dirtyReg (hc08_reg_hx, FALSE);
+              emitcode ("aix", "#1");
+              hc08_dirtyReg (hc08_reg_hx, FALSE);
             }
           if (!ifx)
             storeRegToAop (hc08_reg_a, AOP (result), offset);
           offset--;
           hc08_freeReg (hc08_reg_a);
-       }
+        }
     }
 
   freeAsmop (left, NULL, ic, TRUE);
@@ -7343,14 +7386,14 @@ genPointerGet (iCode * ic, iCode *pi, iCode *ifx)
 /*-----------------------------------------------------------------*/
 static void
 genPackBits (sym_link * etype,
-            operand * right)
-{
-  int offset = 0;      /* source byte offset */
-  int rlen = 0;                /* remaining bitfield length */
-  int blen;            /* bitfield length */
-  int bstr;            /* bitfield starting bit within byte */
-  int litval;          /* source literal value (if AOP_LIT) */
-  unsigned char mask;  /* bitmask within current byte */
+             operand * right)
+{
+  int offset = 0;       /* source byte offset */
+  int rlen = 0;         /* remaining bitfield length */
+  int blen;             /* bitfield length */
+  int bstr;             /* bitfield starting bit within byte */
+  int litval;           /* source literal value (if AOP_LIT) */
+  unsigned char mask;   /* bitmask within current byte */
   int xoffset = 0;
 
   D(emitcode (";     genPackBits",""));
@@ -7362,13 +7405,13 @@ genPackBits (sym_link * etype,
   if (blen < 8)
     {
       mask = ((unsigned char) (0xFF << (blen + bstr)) |
-             (unsigned char) (0xFF >> (8 - bstr)));
+              (unsigned char) (0xFF >> (8 - bstr)));
 
       if (AOP_TYPE (right) == AOP_LIT)
         {
           /* 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;
 
@@ -7410,7 +7453,7 @@ genPackBits (sym_link * etype,
       if (AOP (right)->type == AOP_DIR)
         {
           emitcode ("mov", "%s,x+", aopAdrStr(AOP (right), offset, FALSE));
-         xoffset++;
+          xoffset++;
         }
       else
         {
@@ -7429,7 +7472,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;
           emitcode ("lda", "%d,x", offset - xoffset);
@@ -7469,12 +7512,12 @@ genPackBitsImmed (operand *result, sym_link * etype, operand * right, iCode * ic
 {
   asmop *derefaop;
   int size;
-  int offset = 0;      /* source byte offset */
-  int rlen = 0;                /* remaining bitfield length */
-  int blen;            /* bitfield length */
-  int bstr;            /* bitfield starting bit within byte */
-  int litval;          /* source literal value (if AOP_LIT) */
-  unsigned char mask;  /* bitmask within current byte */
+  int offset = 0;       /* source byte offset */
+  int rlen = 0;         /* remaining bitfield length */
+  int blen;             /* bitfield length */
+  int bstr;             /* bitfield starting bit within byte */
+  int litval;           /* source literal value (if AOP_LIT) */
+  unsigned char mask;   /* bitmask within current byte */
 
   D(emitcode (";     genPackBitsImmed",""));
 
@@ -7493,7 +7536,7 @@ genPackBitsImmed (operand *result, sym_link * etype, operand * right, iCode * ic
     {
       if (AOP_TYPE (right) == AOP_LIT)
         {
-          litval = (int) floatFromVal (AOP (right)->aopu.aop_lit);
+          litval = (int) ulFromVal (AOP (right)->aopu.aop_lit);
       
           emitcode ((litval & 1) ? "bset" : "bclr", 
                     "#%d,%s", bstr, aopAdrStr (derefaop, 0, FALSE));
@@ -7520,13 +7563,13 @@ genPackBitsImmed (operand *result, sym_link * etype, operand * right, iCode * ic
   if (blen < 8)
     {
       mask = ((unsigned char) (0xFF << (blen + bstr)) |
-             (unsigned char) (0xFF >> (8 - bstr)));
+              (unsigned char) (0xFF >> (8 - bstr)));
 
       if (AOP_TYPE (right) == AOP_LIT)
         {
           /* 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;
 
@@ -7578,7 +7621,7 @@ genPackBitsImmed (operand *result, sym_link * etype, operand * right, iCode * ic
         {
           /* 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;
           loadRegFromAop (hc08_reg_a, derefaop, size-offset-1);
@@ -7619,8 +7662,8 @@ release:
 /*-----------------------------------------------------------------*/
 static void
 genDataPointerSet (operand * right,
-                  operand * result,
-                  iCode * ic)
+                   operand * result,
+                   iCode * ic)
 {
   int size;
   asmop *derefaop;
@@ -7697,15 +7740,15 @@ genPointerSet (iCode * ic, iCode *pi)
       offset = size-1;
 
       while (size--)
-       {
+        {
           loadRegFromAop (hc08_reg_a, AOP (right), offset--);
-         accopWithMisc ("sta", ",x");
-         if (size || pi)
-           {
-             emitcode ("aix", "#1");
-           }
+          accopWithMisc ("sta", ",x");
+          if (size || pi)
+            {
+              emitcode ("aix", "#1");
+            }
           hc08_freeReg (hc08_reg_a);
-       }
+        }
     }
 
   freeAsmop (result, NULL, ic, TRUE);
@@ -7739,7 +7782,7 @@ genIfx (iCode * ic, iCode * popIc)
   /* branch or no branch */
   if (AOP_TYPE (cond) == AOP_LIT)
     {
-      unsigned long lit = (unsigned long) floatFromVal (AOP (cond)->aopu.aop_lit);
+      unsigned long lit = ulFromVal (AOP (cond)->aopu.aop_lit);
       freeAsmop (cond, NULL, ic, TRUE);
 
       /* if there was something to be popped then do it */
@@ -7831,15 +7874,15 @@ genAddrOf (iCode * ic)
       char s[SDCC_NAME_MAX+10];
       switch (offset) {
         case 0:
-         sprintf (s, "#%s", sym->rname);
-         break;
+          sprintf (s, "#%s", sym->rname);
+          break;
         case 1:
-         sprintf (s, "#>%s", sym->rname);
-         break;
+          sprintf (s, "#>%s", sym->rname);
+          break;
         default:
-         sprintf (s, "#(%s >> %d)",
-                  sym->rname,
-                  offset * 8);
+          sprintf (s, "#(%s >> %d)",
+                   sym->rname,
+                   offset * 8);
       }
       storeConstToAop(s, AOP (IC_RESULT (ic)), offset++);
     }
@@ -7986,17 +8029,17 @@ genCast (iCode * ic)
       /* if they are in the same place */
       #if 0
       if (sameRegs (AOP (right), AOP (result)))
-       goto release;
+        goto release;
       #endif
 
       /* if they in different places then copy */
       size = AOP_SIZE (result);
       offset = 0;
       while (size--)
-       {
-         transferAopAop(AOP (right), offset, AOP (result), offset);
-         offset++;
-       }
+        {
+          transferAopAop(AOP (right), offset, AOP (result), offset);
+          offset++;
+        }
       goto release;
     }
 
@@ -8011,55 +8054,55 @@ genCast (iCode * ic)
 
       /* pointer to generic pointer */
       if (IS_GENPTR (ctype))
-       {
-         if (IS_PTR (type))
-           p_type = DCL_TYPE (type);
-         else
-           {
-             if (SPEC_SCLS(etype)==S_REGISTER) {
-               // let's assume it is a generic pointer
-               p_type=GPOINTER;
-             } else {
-               /* we have to go by the storage class */
-               p_type = PTR_TYPE (SPEC_OCLS (etype));
-             }
-           }
-
-         /* the first two bytes are known */
-         size = GPTRSIZE - 1;
-         offset = 0;
-         while (size--)
-           {
+        {
+          if (IS_PTR (type))
+            p_type = DCL_TYPE (type);
+          else
+            {
+              if (SPEC_SCLS(etype)==S_REGISTER) {
+                // let's assume it is a generic pointer
+                p_type=GPOINTER;
+              } else {
+                /* we have to go by the storage class */
+                p_type = PTR_TYPE (SPEC_OCLS (etype));
+              }
+            }
+
+          /* the first two bytes are known */
+          size = GPTRSIZE - 1;
+          offset = 0;
+          while (size--)
+            {
               transferAopAop(AOP (right), offset, AOP (result), offset);
-             offset++;
-           }
-         /* the last byte depending on type */
+              offset++;
+            }
+          /* the last byte depending on type */
 #if 0
-           {
-               int gpVal = pointerTypeToGPByte(p_type, NULL, NULL);
-               char gpValStr[10];
-           
-               if (gpVal == -1)
-               {
-                   // pointerTypeToGPByte will have bitched.
-                   exit(1);
-               }
-           
-               sprintf(gpValStr, "#0x%x", gpVal);
-               aopPut (AOP (result), gpValStr, GPTRSIZE - 1);
-           }       
+            {
+                int gpVal = pointerTypeToGPByte(p_type, NULL, NULL);
+                char gpValStr[10];
+            
+                if (gpVal == -1)
+                {
+                    // pointerTypeToGPByte will have bitched.
+                    exit(1);
+                }
+            
+                sprintf(gpValStr, "#0x%x", gpVal);
+                aopPut (AOP (result), gpValStr, GPTRSIZE - 1);
+            }       
 #endif
-         goto release;
-       }
+          goto release;
+        }
 
       /* just copy the pointers */
       size = AOP_SIZE (result);
       offset = 0;
       while (size--)
-       {
+        {
           transferAopAop(AOP (right), offset, AOP (result), offset);
-         offset++;
-       }
+          offset++;
+        }
       goto release;
     }
 
@@ -8090,7 +8133,7 @@ genCast (iCode * ic)
       accopWithMisc ("clra", "");
       accopWithMisc ("sbc", zero);
       while (size--)
-       storeRegToAop (hc08_reg_a, AOP (result), offset++);
+        storeRegToAop (hc08_reg_a, AOP (result), offset++);
     }
 
   /* we are done hurray !!!! */
@@ -8148,7 +8191,7 @@ genDjnz (iCode * ic, iCode * ifx)
 
 
   emitcode ("dbnz", "%s,%05d$", aopAdrStr (AOP (IC_RESULT (ic)), 0, FALSE),
-               lbl->key + 100);
+                lbl->key + 100);
  
   emitBranch ("bra", lbl1);
   emitLabel (lbl);
@@ -8176,13 +8219,13 @@ genReceive (iCode * ic)
   
   if (ic->argreg) {
       while (size--) {
-         transferAopAop( hc08_aop_pass[offset+(ic->argreg-1)], 0,
-                         AOP (IC_RESULT (ic)), offset);
-         if (hc08_aop_pass[offset]->type == AOP_REG)
-           hc08_freeReg (hc08_aop_pass[offset]->aopu.aop_reg[0]);
-         offset++;
+          transferAopAop( hc08_aop_pass[offset+(ic->argreg-1)], 0,
+                          AOP (IC_RESULT (ic)), offset);
+          if (hc08_aop_pass[offset]->type == AOP_REG)
+            hc08_freeReg (hc08_aop_pass[offset]->aopu.aop_reg[0]);
+          offset++;
       }
-  }      
+  }       
 
   freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
 }
@@ -8301,7 +8344,7 @@ genhc08Code (iCode * lic)
 
   /* print the allocation information */
   if (allocInfo && currFunc)
-    printAllocInfo (currFunc, codeOutFile);
+    printAllocInfo (currFunc, codeOutBuf);
   /* if debug information required */
   if (options.debug && currFunc)
     {
@@ -8309,9 +8352,9 @@ genhc08Code (iCode * lic)
       #if 0
       _G.debugLine = 1;
       if (IS_STATIC (currFunc->etype))
-       emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
+        emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
       else
-       emitcode ("", "G$%s$0$0 ==.", currFunc->name);
+        emitcode ("", "G$%s$0$0 ==.", currFunc->name);
       _G.debugLine = 0;
       #endif
     }
@@ -8342,51 +8385,54 @@ genhc08Code (iCode * lic)
       _G.current_iCode = ic;
       
       if (ic->level != clevel || ic->block != cblock)
-       {
-         if (options.debug)
-           {
-             debugFile->writeScope(ic);
-           }
-         clevel = ic->level;
-         cblock = ic->block;
-       }
-       
+        {
+          if (options.debug)
+            {
+              debugFile->writeScope(ic);
+            }
+          clevel = ic->level;
+          cblock = ic->block;
+        }
+        
       if (ic->lineno && cln != ic->lineno)
-       {
-         if (options.debug)
-           {
-             debugFile->writeCLine(ic);
-             #if 0
-             _G.debugLine = 1;
-             emitcode ("", "C$%s$%d$%d$%d ==.",
-                       FileBaseName (ic->filename), ic->lineno,
-                       ic->level, ic->block);
-             _G.debugLine = 0;
-             #endif
-           }
-         if (!options.noCcodeInAsm) {
-           emitcode ("", ";%s:%d: %s", ic->filename, ic->lineno, 
-                     printCLine(ic->filename, ic->lineno));
-         }
-         cln = ic->lineno;
-       }
+        {
+          if (options.debug)
+            {
+              debugFile->writeCLine(ic);
+              #if 0
+              _G.debugLine = 1;
+              emitcode ("", "C$%s$%d$%d$%d ==.",
+                        FileBaseName (ic->filename), ic->lineno,
+                        ic->level, ic->block);
+              _G.debugLine = 0;
+              #endif
+            }
+          if (!options.noCcodeInAsm) {
+            emitcode ("", ";%s:%d: %s", ic->filename, ic->lineno, 
+                      printCLine(ic->filename, ic->lineno));
+          }
+          cln = ic->lineno;
+        }
       if (options.iCodeInAsm) {
-       char regsInUse[80];
-       int i;
-
-       for (i=0; i<6; i++) {
-         sprintf (&regsInUse[i],
-                  "%c", ic->riu & (1<<i) ? i+'0' : '-'); 
-       }
-       regsInUse[i]=0;
-       emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+        char regsInUse[80];
+        int i;
+        char *iLine;
+
+        for (i=0; i<6; i++) {
+          sprintf (&regsInUse[i],
+                   "%c", ic->riu & (1<<i) ? i+'0' : '-'); 
+        }
+        regsInUse[i]=0;
+        iLine = printILine(ic);
+        emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic));
+        dbuf_free(iLine);
       }
       /* if the result is marked as
          spilt and rematerializable or code for
          this has already been generated then
          do nothing */
       if (resultRemat (ic) || ic->generated)
-       continue;
+        continue;
 
       {
         int i;
@@ -8435,212 +8481,212 @@ genhc08Code (iCode * lic)
       
       /* depending on the operation */
       switch (ic->op)
-       {
-       case '!':
-         genNot (ic);
-         break;
-
-       case '~':
-         genCpl (ic);
-         break;
-
-       case UNARYMINUS:
-         genUminus (ic);
-         break;
-
-       case IPUSH:
-         genIpush (ic);
-         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);
-         break;
-
-       case CALL:
-         genCall (ic);
-         break;
-
-       case PCALL:
-         genPcall (ic);
-         break;
-
-       case FUNCTION:
-         genFunction (ic);
-         break;
-
-       case ENDFUNCTION:
-         genEndFunction (ic);
-         break;
-
-       case RETURN:
-         genRet (ic);
-         break;
-
-       case LABEL:
-         genLabel (ic);
-         break;
-
-       case GOTO:
-         genGoto (ic);
-         break;
-
-       case '+':
+        {
+        case '!':
+          genNot (ic);
+          break;
+
+        case '~':
+          genCpl (ic);
+          break;
+
+        case UNARYMINUS:
+          genUminus (ic);
+          break;
+
+        case IPUSH:
+          genIpush (ic);
+          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);
+          break;
+
+        case CALL:
+          genCall (ic);
+          break;
+
+        case PCALL:
+          genPcall (ic);
+          break;
+
+        case FUNCTION:
+          genFunction (ic);
+          break;
+
+        case ENDFUNCTION:
+          genEndFunction (ic);
+          break;
+
+        case RETURN:
+          genRet (ic);
+          break;
+
+        case LABEL:
+          genLabel (ic);
+          break;
+
+        case GOTO:
+          genGoto (ic);
+          break;
+
+        case '+':
           if (!genPointerGetSetOfs (ic))
-           genPlus (ic);
-         break;
-
-       case '-':
-         if (!genDjnz (ic, ifxForOp (IC_RESULT (ic), ic)))
-           genMinus (ic);
-         break;
-
-       case '*':
-         genMult (ic);
-         break;
-
-       case '/':
-         genDiv (ic);
-         break;
-
-       case '%':
-         genMod (ic);
-         break;
-
-       case '>':
-       case '<':
-       case LE_OP:
-       case GE_OP:
+            genPlus (ic);
+          break;
+
+        case '-':
+          if (!genDjnz (ic, ifxForOp (IC_RESULT (ic), ic)))
+            genMinus (ic);
+          break;
+
+        case '*':
+          genMult (ic);
+          break;
+
+        case '/':
+          genDiv (ic);
+          break;
+
+        case '%':
+          genMod (ic);
+          break;
+
+        case '>':
+        case '<':
+        case LE_OP:
+        case GE_OP:
           genCmp (ic, ifxForOp (IC_RESULT (ic), ic));
           break;
 
         case NE_OP:
-       case EQ_OP:
+        case EQ_OP:
           genCmpEQorNE (ic, ifxForOp (IC_RESULT (ic), ic));
           break;
 
-       case AND_OP:
-         genAndOp (ic);
-         break;
+        case AND_OP:
+          genAndOp (ic);
+          break;
 
-       case OR_OP:
-         genOrOp (ic);
-         break;
+        case OR_OP:
+          genOrOp (ic);
+          break;
 
-       case '^':
-         genXor (ic, ifxForOp (IC_RESULT (ic), ic));
-         break;
+        case '^':
+          genXor (ic, ifxForOp (IC_RESULT (ic), ic));
+          break;
 
-       case '|':
-         genOr (ic, ifxForOp (IC_RESULT (ic), ic));
-         break;
+        case '|':
+          genOr (ic, ifxForOp (IC_RESULT (ic), ic));
+          break;
 
-       case BITWISEAND:
-         genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
-         break;
+        case BITWISEAND:
+          genAnd (ic, ifxForOp (IC_RESULT (ic), ic));
+          break;
 
-       case INLINEASM:
-         genInline (ic);
-         break;
+        case INLINEASM:
+          genInline (ic);
+          break;
 
-       case RRC:
-         genRRC (ic);
-         break;
+        case RRC:
+          genRRC (ic);
+          break;
 
-       case RLC:
-         genRLC (ic);
-         break;
+        case RLC:
+          genRLC (ic);
+          break;
 
-       case GETHBIT:
-         genGetHbit (ic);
-         break;
+        case GETHBIT:
+          genGetHbit (ic);
+          break;
 
-       case LEFT_OP:
-         genLeftShift (ic);
-         break;
+        case LEFT_OP:
+          genLeftShift (ic);
+          break;
 
-       case RIGHT_OP:
-         genRightShift (ic);
-         break;
+        case RIGHT_OP:
+          genRightShift (ic);
+          break;
 
-       case GET_VALUE_AT_ADDRESS:
-         genPointerGet (ic,
+        case GET_VALUE_AT_ADDRESS:
+          genPointerGet (ic,
                          hasInc (IC_LEFT (ic), ic,
                                  getSize (operandType (IC_RESULT (ic)))),
                          ifxForOp (IC_RESULT (ic), ic) );
-         break;
-
-       case '=':
-         if (POINTER_SET (ic))
-           genPointerSet (ic, hasInc (IC_RESULT(ic),ic,getSize(operandType(IC_RIGHT(ic)))));
-         else
-           genAssign (ic);
-         break;
-
-       case IFX:
-         genIfx (ic, NULL);
-         break;
-
-       case ADDRESS_OF:
-         genAddrOf (ic);
-         break;
-
-       case JUMPTABLE:
-         genJumpTab (ic);
-         break;
-
-       case CAST:
-         genCast (ic);
-         break;
-
-       case RECEIVE:
-         genReceive (ic);
-         break;
-
-       case SEND:
-         addSet (&_G.sendSet, ic);
-         break;
-
-       case DUMMY_READ_VOLATILE:
-         genDummyRead (ic);
-         break;
-
-       case CRITICAL:
-         genCritical (ic);
-         break;
-
-       case ENDCRITICAL:
-         genEndCritical (ic);
-         break;
-       
+          break;
+
+        case '=':
+          if (POINTER_SET (ic))
+            genPointerSet (ic, hasInc (IC_RESULT(ic),ic,getSize(operandType(IC_RIGHT(ic)))));
+          else
+            genAssign (ic);
+          break;
+
+        case IFX:
+          genIfx (ic, NULL);
+          break;
+
+        case ADDRESS_OF:
+          genAddrOf (ic);
+          break;
+
+        case JUMPTABLE:
+          genJumpTab (ic);
+          break;
+
+        case CAST:
+          genCast (ic);
+          break;
+
+        case RECEIVE:
+          genReceive (ic);
+          break;
+
+        case SEND:
+          addSet (&_G.sendSet, ic);
+          break;
+
+        case DUMMY_READ_VOLATILE:
+          genDummyRead (ic);
+          break;
+
+        case CRITICAL:
+          genCritical (ic);
+          break;
+
+        case ENDCRITICAL:
+          genEndCritical (ic);
+          break;
+        
         case SWAP:
-         genSwap (ic);
+          genSwap (ic);
           break;
 
-       default:
-         ic = ic;
-       }
+        default:
+          ic = ic;
+        }
 
       if (!hc08_reg_a->isFree)
-        D(emitcode("","; forgot to free a"));
+        DD(emitcode("","; forgot to free a"));
       if (!hc08_reg_x->isFree)
-        D(emitcode("","; forgot to free x"));
+        DD(emitcode("","; forgot to free x"));
       if (!hc08_reg_h->isFree)
-        D(emitcode("","; forgot to free h"));
+        DD(emitcode("","; forgot to free h"));
       if (!hc08_reg_hx->isFree)
-        D(emitcode("","; forgot to free hx"));
+        DD(emitcode("","; forgot to free hx"));
       if (!hc08_reg_xa->isFree)
-        D(emitcode("","; forgot to free xa"));
+        DD(emitcode("","; forgot to free xa"));
     }
 
   debugFile->writeFrameAddress (NULL, NULL, 0);  /* have no idea where frame is now */
@@ -8652,6 +8698,6 @@ genhc08Code (iCode * lic)
     peepHole (&lineHead);
 
   /* now do the actual printing */
-  printLine (lineHead, codeOutFile);
+  printLine (lineHead, codeOutBuf);
   return;
 }