* src/mcs51/peeph.def: renamed rule 400 to 500, moved rule 253.x to 400.x for better...
[fw/sdcc] / src / mcs51 / gen.c
index 7f091daed7d43da26dd2210af8abca3a11e8b75a..ad53c30b2e4eb649a499c9945cee344d72e292ba 100644 (file)
@@ -198,6 +198,7 @@ static void
 emitLabel (symbol *tlbl)
 {
   emitcode ("", "%05d$:", tlbl->key + 100);
+  lineCurr->isLabel = 1;
 }
 
 /*-----------------------------------------------------------------*/
@@ -244,9 +245,9 @@ movb (const char *x)
 static void
 movc (const char *s)
 {
-  if (s == zero)
+  if (!strcmp (s, zero))
     CLRC;
-  else if (s == one)
+  else if (!strcmp (s, one))
     SETC;
   else if (strcmp (s, "c"))
     {/* it's not in carry already */
@@ -649,7 +650,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
                   if (accuse)
                     emitcode ("push", "acc");
                   emitcode ("mov", "a,%s", SYM_BP (sym));
-                  emitcode ("add", "a,#0x%02x", offset);
+                  emitcode ("add", "a,#0x%02x", offset & 0xff);
                   emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name);
                   if (accuse)
                     emitcode ("pop", "acc");
@@ -967,8 +968,7 @@ aopOp (operand * op, iCode * ic, bool result)
       /* rematerialize it NOW */
       if (sym->remat)
         {
-          sym->aop = op->aop = aop =
-            aopForRemat (sym);
+          sym->aop = op->aop = aop = aopForRemat (sym);
           aop->size = getSize (sym->type);
           return;
         }
@@ -3256,6 +3256,7 @@ genFunction (iCode * ic)
   emitcode (";", "-----------------------------------------");
 
   emitcode ("", "%s:", sym->rname);
+  lineCurr->isLabel = 1;
   ftype = operandType (IC_LEFT (ic));
   _G.currentFunc = sym;
 
@@ -3617,14 +3618,14 @@ genFunction (iCode * ic)
       if (i > 3 && accIsFree)
         {
           emitcode ("mov", "a,_spx");
-          emitcode ("add", "a,#0x%02x", i);
+          emitcode ("add", "a,#0x%02x", i & 0xff);
           emitcode ("mov", "_spx,a");
         }
       else if (i > 5)
         {
           emitcode ("push", "acc");
           emitcode ("mov", "a,_spx");
-          emitcode ("add", "a,#0x%02x", i);
+          emitcode ("add", "a,#0x%02x", i & 0xff);
           emitcode ("mov", "_spx,a");
           emitcode ("pop", "acc");
         }
@@ -4021,7 +4022,7 @@ genLabel (iCode * ic)
   if (IC_LABEL (ic) == entryLabel)
     return;
 
-  emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100));
+  emitLabel (IC_LABEL (ic));
 }
 
 /*-----------------------------------------------------------------*/
@@ -4082,7 +4083,7 @@ genPlusIncr (iCode * ic)
 
   icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit);
 
-  D(emitcode (";     genPlusIncr",""));
+  D(emitcode (";","genPlusIncr"));
 
   /* if increment >=16 bits in register or direct space */
   if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || 
@@ -9738,18 +9739,17 @@ genDataPointerGet (operand * left,
 
   /* get the string representation of the name */
   l = aopGet (left, 0, FALSE, TRUE);
+  l++; // remove #
   size = AOP_SIZE (result);
   while (size--)
     {
       if (offset)
         {
-          SNPRINTF (buffer, sizeof(buffer),
-                    "(%s + %d)", l + 1, offset);
+          SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l, offset);
         }
       else
         {
-          SNPRINTF (buffer, sizeof(buffer),
-                    "%s", l + 1);
+          SNPRINTF (buffer, sizeof(buffer), "%s", l);
         }
       aopPut (result, buffer, offset++);
     }
@@ -10434,13 +10434,14 @@ genDataPointerSet (operand * right,
   aopOp (right, ic, FALSE);
 
   l = aopGet (result, 0, FALSE, TRUE);
+  l++; //remove #
   size = AOP_SIZE (right);
   while (size--)
     {
       if (offset)
-        SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l + 1, offset);
+        SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l, offset);
       else
-        SNPRINTF (buffer, sizeof(buffer), "%s", l + 1);
+        SNPRINTF (buffer, sizeof(buffer), "%s", l);
       emitcode ("mov", "%s,%s", buffer,
                 aopGet (right, offset++, FALSE, FALSE));
     }
@@ -10913,7 +10914,7 @@ genAddrOf (iCode * ic)
           else
             {
               emitcode ("mov", "a,%s", SYM_BP (sym));
-              emitcode ("add", "a,#0x%02x", stack_offset);
+              emitcode ("add", "a,#0x%02x", stack_offset & 0xff);
               aopPut (IC_RESULT (ic), "a", 0);
             }
         }