Added regression tests for compound comparisons.
[fw/sdcc] / src / pic / genarith.c
index 9bdf0bd306d6e7d55fce645b7fa6779fa15015d1..241ca2f3171b244374aec5ded7dd7d65ec5b15e4 100644 (file)
@@ -738,34 +738,50 @@ static void genAddLit (iCode *ic, int lit)
       }
 
     } else {
+      int clear_carry=0;
 
       /* left is not the accumulator */
       if(lit & 0xff) {
        emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
        emitpcode(POC_ADDFW, popGet(AOP(left),0));
-      } else
+      } else {
        emitpcode(POC_MOVFW, popGet(AOP(left),0));
-
+       /* We don't know the state of the carry bit at this point */
+       clear_carry = 1;
+      }
       //emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
       emitMOVWF(result,0);
-      lit >>= 8;
       while(--size) {
       
+       lit >>= 8;
        if(lit & 0xff) {
-         emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
-         //emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
-         emitMOVWF(result,offset);
-         emitpcode(POC_MOVFW, popGet(AOP(left),offset));
-         emitSKPNC;
-         emitpcode(POC_INCFSZW,popGet(AOP(left),offset));
-         emitpcode(POC_ADDWF,  popGet(AOP(result),offset));
+         if(clear_carry) {
+           /* The ls byte of the lit must've been zero - that 
+              means we don't have to deal with carry */
+
+           emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+           emitpcode(POC_ADDFW,  popGet(AOP(left),offset));
+           emitpcode(POC_MOVWF, popGet(AOP(left),offset));
+
+           clear_carry = 0;
+
+         } else {
+           emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+           //emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
+           emitMOVWF(result,offset);
+           emitpcode(POC_MOVFW, popGet(AOP(left),offset));
+           emitSKPNC;
+           emitpcode(POC_INCFSZW,popGet(AOP(left),offset));
+           emitpcode(POC_ADDWF,  popGet(AOP(result),offset));
+         }
+
        } else {
          emitpcode(POC_CLRF,  popGet(AOP(result),offset));
          emitpcode(POC_RLF,   popGet(AOP(result),offset));
          emitpcode(POC_MOVFW, popGet(AOP(left),offset));
          emitpcode(POC_ADDWF, popGet(AOP(result),offset));
        }
-      offset++;
+       offset++;
       }
     }
   }