PIC Port - Totally rewrote signed comparisons. It was a horrendously hideous bitch...
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 23 Nov 2001 17:54:03 +0000 (17:54 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 23 Nov 2001 17:54:03 +0000 (17:54 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1630 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/genarith.c
src/regression/Makefile
src/regression/compare4.c
src/regression/compare5.c
src/regression/compare6.c

index 260ca0fde635ab2a6c33f7029784b6a97dd5de7f..d3ba5a18a1a61f576baa51fd56433f66cda23835 100644 (file)
 #include "pcode.h"
 #include "gen.h"
 
-/*
-  if(IC_RESULT(ic) && AOP(IC_RESULT(ic)))
-    DEBUGpic14_emitcode ("; ","result %s",
-                        AopType(AOP_TYPE(IC_RESULT(ic))));
-
-  if(IC_LEFT(ic) && AOP(IC_LEFT(ic)))
-    DEBUGpic14_emitcode ("; ","left %s",
-                      AopType(AOP_TYPE(IC_LEFT(ic))));
-
-  if(IC_RIGHT(ic) && AOP(IC_RIGHT(ic)))
-    DEBUGpic14_emitcode ("; ","right %s",
-                      AopType(AOP_TYPE(IC_RIGHT(ic))));
-*/
-
 
 static int labelOffset=0;
 static int debug_verbose=1;
@@ -87,6 +73,7 @@ static int GpsuedoStkPtr=0;
 
 unsigned int pic14aopLiteral (value *val, int offset);
 const char *AopType(short type);
+static iCode *ifxForOp ( operand *op, iCode *ic );
 
 #define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff)
 
@@ -1619,21 +1606,21 @@ int pic14_getDataSize(operand *op)
 /*-----------------------------------------------------------------*/
 void pic14_outAcc(operand *result)
 {
+  int size,offset;
+  DEBUGpic14_emitcode ("; ***","%s  %d - ",__FUNCTION__,__LINE__);
+  DEBUGpic14_AopType(__LINE__,NULL,NULL,result);
 
-    DEBUGpic14_emitcode ("; ***","%s  %d - Warning no code will be generated here",__FUNCTION__,__LINE__);
 
-#if 0
-    size = pic14_getDataSize(result);
-    if(size){
-        aopPut(AOP(result),"a",0);
-        size--;
-        offset = 1;
-        /* unsigned or positive */
-        while(size--){
-            aopPut(AOP(result),zero,offset++);
-        }
-    }
-#endif
+  size = pic14_getDataSize(result);
+  if(size){
+    emitpcode(POC_MOVWF,popGet(AOP(result),0));
+    size--;
+    offset = 1;
+    /* unsigned or positive */
+    while(size--)
+      emitpcode(POC_CLRF,popGet(AOP(result),offset++));
+  }
+
 }
 
 /*-----------------------------------------------------------------*/
@@ -1678,40 +1665,49 @@ void pic14_toBoolean(operand *oper)
 /*-----------------------------------------------------------------*/
 static void genNot (iCode *ic)
 {
-    symbol *tlbl;
-    sym_link *optype = operandType(IC_LEFT(ic));
-
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    /* assign asmOps to operand & result */
-    aopOp (IC_LEFT(ic),ic,FALSE);
-    aopOp (IC_RESULT(ic),ic,TRUE);
+  symbol *tlbl;
+  sym_link *optype = operandType(IC_LEFT(ic));
+  int size;
 
-    /* if in bit space then a special case */
-    if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
-      pic14_emitcode("movlw","1<<%s");
-      //pic14_emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir); 
-      //pic14_emitcode("cpl","c"); 
-      //pic14_outBitC(IC_RESULT(ic));
-      goto release;
-    }
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  /* assign asmOps to operand & result */
+  aopOp (IC_LEFT(ic),ic,FALSE);
+  aopOp (IC_RESULT(ic),ic,TRUE);
+
+  DEBUGpic14_AopType(__LINE__,IC_LEFT(ic),NULL,IC_RESULT(ic));
+  /* if in bit space then a special case */
+  if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) {
+    pic14_emitcode("movlw","1<<%s");
+    //pic14_emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir); 
+    //pic14_emitcode("cpl","c"); 
+    //pic14_outBitC(IC_RESULT(ic));
+    goto release;
+  }
 
-    /* if type float then do float */
-    if (IS_FLOAT(optype)) {
-        genNotFloat(IC_LEFT(ic),IC_RESULT(ic));
-        goto release;
-    }
+  /* if type float then do float */
+  if (IS_FLOAT(optype)) {
+    genNotFloat(IC_LEFT(ic),IC_RESULT(ic));
+    goto release;
+  }
 
-    pic14_toBoolean(IC_LEFT(ic));
+  size = AOP_SIZE(IC_RESULT(ic));
+  if(size == 1) {
+    emitpcode(POC_COMFW,popGet(AOP(IC_LEFT(ic)),0));
+    emitpcode(POC_ANDLW,popGetLit(1));
+    emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0));
+    goto release;
+  }
+  pic14_toBoolean(IC_LEFT(ic));
 
-    tlbl = newiTempLabel(NULL);
-    pic14_emitcode("cjne","a,#0x01,%05d_DS_",tlbl->key+100);
-    pic14_emitcode("","%05d_DS_:",tlbl->key+100);
-    pic14_outBitC(IC_RESULT(ic));
+  tlbl = newiTempLabel(NULL);
+  pic14_emitcode("cjne","a,#0x01,%05d_DS_",tlbl->key+100);
+  pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+  pic14_outBitC(IC_RESULT(ic));
 
-release:    
-    /* release the aops */
-    freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
-    freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ release:    
+  /* release the aops */
+  freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
+  freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
 }
 
 
@@ -1787,64 +1783,58 @@ static void genUminusFloat(operand *op,operand *result)
 /*-----------------------------------------------------------------*/
 static void genUminus (iCode *ic)
 {
-    int offset ,size ;
-    sym_link *optype, *rtype;
+  int size, i;
+  sym_link *optype, *rtype;
 
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    /* assign asmops */
-    aopOp(IC_LEFT(ic),ic,FALSE);
-    aopOp(IC_RESULT(ic),ic,TRUE);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  /* assign asmops */
+  aopOp(IC_LEFT(ic),ic,FALSE);
+  aopOp(IC_RESULT(ic),ic,TRUE);
 
-    /* if both in bit space then special
-    case */
-    if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
-        AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) { 
+  /* if both in bit space then special
+     case */
+  if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY &&
+      AOP_TYPE(IC_LEFT(ic)) == AOP_CRY ) { 
 
-        pic14_emitcode("mov","c,%s",IC_LEFT(ic)->aop->aopu.aop_dir); 
-        pic14_emitcode("cpl","c"); 
-        pic14_emitcode("mov","%s,c",IC_RESULT(ic)->aop->aopu.aop_dir); 
-        goto release; 
-    } 
+    emitpcode(POC_BCF,   popGet(AOP(IC_RESULT(ic)),0));
+    emitpcode(POC_BTFSS, popGet(AOP(IC_LEFT(ic)),0));
+    emitpcode(POC_BSF,   popGet(AOP(IC_RESULT(ic)),0));
 
-    optype = operandType(IC_LEFT(ic));
-    rtype = operandType(IC_RESULT(ic));
+    goto release; 
+  } 
 
-    /* if float then do float stuff */
-    if (IS_FLOAT(optype)) {
-        genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
-        goto release;
-    }
+  optype = operandType(IC_LEFT(ic));
+  rtype = operandType(IC_RESULT(ic));
 
-    /* otherwise subtract from zero */
-    size = AOP_SIZE(IC_LEFT(ic));
-    offset = 0 ;
-    CLRC ;
-    while(size--) {
-        char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE);
-        if (!strcmp(l,"a")) {
-            pic14_emitcode("cpl","a");
-            pic14_emitcode("inc","a");
-        } else {
-            pic14_emitcode("clr","a");
-            pic14_emitcode("subb","a,%s",l);
-        }       
-        aopPut(AOP(IC_RESULT(ic)),"a",offset++);
+  /* if float then do float stuff */
+  if (IS_FLOAT(optype)) {
+    genUminusFloat(IC_LEFT(ic),IC_RESULT(ic));
+    goto release;
+  }
+
+  /* otherwise subtract from zero by taking the 2's complement */
+  size = AOP_SIZE(IC_LEFT(ic));
+
+  for(i=0; i<size; i++) {
+    if (pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
+      emitpcode(POC_COMF,  popGet(AOP(IC_LEFT(ic)),i));
+    else {
+      emitpcode(POC_COMFW, popGet(AOP(IC_LEFT(ic)),i));
+      emitpcode(POC_MOVWF, popGet(AOP(IC_RESULT(ic)),i));
     }
+  }
 
-    /* if any remaining bytes in the result */
-    /* we just need to propagate the sign   */
-    if ((size = (AOP_SIZE(IC_RESULT(ic)) - AOP_SIZE(IC_LEFT(ic))))) {
-        pic14_emitcode("rlc","a");
-        pic14_emitcode("subb","a,acc");
-        while (size--) 
-            aopPut(AOP(IC_RESULT(ic)),"a",offset++);
-    }       
+  emitpcode(POC_INCF,  popGet(AOP(IC_RESULT(ic)),0));
+  for(i=1; i<size; i++) {
+    emitSKPNZ;
+    emitpcode(POC_INCF,  popGet(AOP(IC_RESULT(ic)),i));
+  }
 
-release:
-    /* release the aops */
-    freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
-    freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);    
+ release:
+  /* release the aops */
+  freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? 0 : 1));
+  freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);    
 }
 
 /*-----------------------------------------------------------------*/
@@ -1995,50 +1985,18 @@ static void assignResultValue(operand * oper)
 }
 
 
-/*-----------------------------------------------------------------*/
-/* genXpush - pushes onto the external stack                       */
-/*-----------------------------------------------------------------*/
-static void genXpush (iCode *ic)
-{
-    asmop *aop = newAsmop(0);
-    regs *r ;
-    int size,offset = 0;
-
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    aopOp(IC_LEFT(ic),ic,FALSE);
-    r = getFreePtr(ic,&aop,FALSE);
-
-    
-    pic14_emitcode("mov","%s,_spx",r->name);
-
-    size = AOP_SIZE(IC_LEFT(ic));
-    while(size--) {
-
-       char *l = aopGet(AOP(IC_LEFT(ic)),
-                        offset++,FALSE,FALSE); 
-       MOVA(l);            
-       pic14_emitcode("movx","@%s,a",r->name); 
-       pic14_emitcode("inc","%s",r->name);
-
-    }
-
-       
-    pic14_emitcode("mov","_spx,%s",r->name);
-
-    freeAsmop(NULL,aop,ic,TRUE);
-    freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
-}
-
 /*-----------------------------------------------------------------*/
 /* genIpush - genrate code for pushing this gets a little complex  */
 /*-----------------------------------------------------------------*/
 static void genIpush (iCode *ic)
 {
+
+  DEBUGpic14_emitcode ("; ***","%s  %d - WARNING no code generated",__FUNCTION__,__LINE__);
+#if 0
     int size, offset = 0 ;
     char *l;
 
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* if this is not a parm push : ie. it is spill push 
     and spill push is always done on the local stack */
     if (!ic->parmPush) {
@@ -2066,13 +2024,6 @@ static void genIpush (iCode *ic)
     registers that need to be saved */   
     saveRegisters(ic);
 
-    /* if use external stack then call the external
-    stack pushing routine */
-    if (options.useXstack) {
-        genXpush(ic);
-        return ;
-    }
-
     /* then do the push */
     aopOp(IC_LEFT(ic),ic,FALSE);
 
@@ -2092,6 +2043,7 @@ static void genIpush (iCode *ic)
     }       
 
     freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+#endif
 }
 
 /*-----------------------------------------------------------------*/
@@ -2099,10 +2051,11 @@ static void genIpush (iCode *ic)
 /*-----------------------------------------------------------------*/
 static void genIpop (iCode *ic)
 {
+  DEBUGpic14_emitcode ("; ***","%s  %d - WARNING no code generated",__FUNCTION__,__LINE__);
+#if 0
     int size,offset ;
 
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* if the temp was not pushed then */
     if (OP_SYMBOL(IC_LEFT(ic))->isspilt)
         return ;
@@ -2115,6 +2068,7 @@ static void genIpop (iCode *ic)
                                    FALSE,TRUE));
 
     freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+#endif
 }
 
 /*-----------------------------------------------------------------*/
@@ -2122,6 +2076,8 @@ static void genIpop (iCode *ic)
 /*-----------------------------------------------------------------*/
 static void unsaverbank (int bank,iCode *ic,bool popPsw)
 {
+  DEBUGpic14_emitcode ("; ***","%s  %d - WARNING no code generated",__FUNCTION__,__LINE__);
+#if 0
     int i;
     asmop *aop ;
     regs *r = NULL;
@@ -2159,7 +2115,8 @@ static void unsaverbank (int bank,iCode *ic,bool popPsw)
        pic14_emitcode("mov","_spx,%s",r->name);
        freeAsmop(NULL,aop,ic,TRUE);
 
-    } 
+    }
+#endif 
 }
 
 /*-----------------------------------------------------------------*/
@@ -2167,6 +2124,8 @@ static void unsaverbank (int bank,iCode *ic,bool popPsw)
 /*-----------------------------------------------------------------*/
 static void saverbank (int bank, iCode *ic, bool pushPsw)
 {
+  DEBUGpic14_emitcode ("; ***","%s  %d - WARNING no code generated",__FUNCTION__,__LINE__);
+#if 0
     int i;
     asmop *aop ;
     regs *r = NULL;
@@ -2205,7 +2164,7 @@ static void saverbank (int bank, iCode *ic, bool pushPsw)
        pic14_emitcode("mov","psw,#0x%02x",(bank << 3)&0x00ff);
     }
     ic->bankSaved = 1;
-
+#endif
 }
 
 /*-----------------------------------------------------------------*/
@@ -2263,8 +2222,6 @@ static void genCall (iCode *ic)
 
 
       while (size--) {
-       char *l = aopGet(AOP(IC_LEFT(sic)),offset,
-                        FALSE,FALSE);
        DEBUGpic14_emitcode ("; ","%d left %s",__LINE__,
                             AopType(AOP_TYPE(IC_LEFT(sic))));
 
@@ -2482,6 +2439,8 @@ static int resultRemat (iCode *ic)
 /*-----------------------------------------------------------------*/
 static bool inExcludeList(char *s)
 {
+  DEBUGpic14_emitcode ("; ***","%s  %d - WARNING no code generated",__FUNCTION__,__LINE__);
+#if 0
     int i =0;
     
     DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
@@ -2494,6 +2453,7 @@ static bool inExcludeList(char *s)
         STRCASECMP(s,options.excludeRegs[i]) == 0)
            return TRUE;
     }
+#endif
     return FALSE ;
 }
 
@@ -2915,33 +2875,6 @@ static void genGoto (iCode *ic)
   pic14_emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100)+labelOffset);
 }
 
-/*-----------------------------------------------------------------*/
-/* findLabelBackwards: walks back through the iCode chain looking  */
-/* for the given label. Returns number of iCode instructions      */
-/* between that label and given ic.                               */
-/* Returns zero if label not found.                               */
-/*-----------------------------------------------------------------*/
-#if 0
-static int findLabelBackwards(iCode *ic, int key)
-{
-    int count = 0;
-    
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    while (ic->prev)
-    {
-        ic = ic->prev;
-        count++;
-        
-        if (ic->op == LABEL && IC_LABEL(ic)->key == key)
-        {
-            /* printf("findLabelBackwards = %d\n", count); */
-            return count;
-        }
-    }
-    
-    return 0;
-}
-#endif
 
 /*-----------------------------------------------------------------*/
 /* genMultbits :- multiplication of bits                           */
@@ -2950,11 +2883,15 @@ static void genMultbits (operand *left,
                          operand *right, 
                          operand *result)
 {
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+  if(!pic14_sameRegs(AOP(result),AOP(right)))
+    emitpcode(POC_BSF,  popGet(AOP(result),0));
+
+  emitpcode(POC_BTFSC,popGet(AOP(right),0));
+  emitpcode(POC_BTFSS,popGet(AOP(left),0));
+  emitpcode(POC_BCF,  popGet(AOP(result),0));
 
-    pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
-    pic14_emitcode("anl","c,%s",AOP(right)->aopu.aop_dir);
-    pic14_outBitC(result);
 }
 
 
@@ -2971,6 +2908,8 @@ static void genMultOneByte (operand *left,
     int size,offset;
 
     DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic14_AopType(__LINE__,left,right,result);
+
     /* (if two literals, the value is computed before) */
     /* if one literal, literal on the right */
     if (AOP_TYPE(left) == AOP_LIT){
@@ -3059,6 +2998,8 @@ static void genMult (iCode *ic)
     aopOp (right,ic,FALSE);
     aopOp (result,ic,TRUE);
 
+  DEBUGpic14_AopType(__LINE__,left,right,result);
+
     /* special cases first */
     /* both are bits */
     if (AOP_TYPE(left) == AOP_CRY &&
@@ -3477,6 +3418,23 @@ static void genSkipc(resolvedIfx *rifx)
   rifx->generated = 1;
 }
 
+/*-----------------------------------------------------------------*/
+/* genSkipz2                                                       */
+/*-----------------------------------------------------------------*/
+static void genSkipz2(resolvedIfx *rifx)
+{
+  if(!rifx)
+    return;
+
+  if(rifx->condition)
+    emitSKPZ;
+  else
+    emitSKPNZ;
+
+  emitpcode(POC_GOTO,popGetLabel(rifx->lbl->key));
+  rifx->generated = 1;
+}
+
 /*-----------------------------------------------------------------*/
 /* genSkipz                                                        */
 /*-----------------------------------------------------------------*/
@@ -3502,6 +3460,23 @@ static void genSkipz(iCode *ifx, int condition)
 
 }
 /*-----------------------------------------------------------------*/
+/* genSkipCond                                                     */
+/*-----------------------------------------------------------------*/
+static void genSkipCond(resolvedIfx *rifx,operand *op, int offset, int bit)
+{
+  if(!rifx)
+    return;
+
+  if(rifx->condition)
+    emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(op),offset,FALSE,FALSE),bit,0));
+  else
+    emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(op),offset,FALSE,FALSE),bit,0));
+
+
+  emitpcode(POC_GOTO,popGetLabel(rifx->lbl->key));
+  rifx->generated = 1;
+}
+/*-----------------------------------------------------------------*/
 /* genCmp :- greater or less than comparison                       */
 /*-----------------------------------------------------------------*/
 static void genCmp (operand *left,operand *right,
@@ -3541,43 +3516,92 @@ static void genCmp (operand *left,operand *right,
       pic14_emitcode("","%05d_DS_:",lbl->key+100);
     } else {
 
+      symbol *lbl  = newiTempLabel(NULL);
+      int flag;
+      symbol *truelbl  = newiTempLabel(NULL);
+
+
       if(AOP_TYPE(right) == AOP_LIT) {
-       symbol *lbl = newiTempLabel(NULL);
 
        lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
 
-       DEBUGpic14_emitcode(";right lit","lit = %d,sign=%d",lit,sign);
+       DEBUGpic14_emitcode(";right lit","lit = 0x%x,sign=%d",lit,sign);
+
 
+
+       if(lit == 0 && sign == 0) {
+         /* no need to compare to 0...*/
+         if(ifx) ifx->generated = 1;
+         return;
+
+       }
        size--;
-       i = (lit >> (size*8)) & 0xff;
-       if(sign) {
-         if(i & 0x80) {
-           emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
-         } else {
-           emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+
+       if(size == 0) {
+         i = (lit >> (size*8)) & 0xff;
+         DEBUGpic14_emitcode(";right lit","line = %d",__LINE__);
+       
+         switch(i) {
+         case 0:
+           if(sign) 
+             genSkipCond(&rIfx,left,0,7);
+           break;
+         default:
+           emitpcode(POC_MOVFW, popGet(AOP(left),size));
+
+           i = ((0-i) & 0xff);
+           if(sign) {
+             emitpcode(POC_ADDLW, popGetLit(0x80));
+             emitpcode(POC_ADDLW, popGetLit(i^0x80));
+           } else {
+             emitpcode(POC_ADDLW, popGetLit(i));
+           }
+           genSkipc(&rIfx);
          }
-         emitpcode(POC_GOTO,popGetLabel(lbl->key));
+
+         if(ifx) ifx->generated = 1;
+         return;
        }
 
-       emitpcode(POC_MOVLW, popGetLit(i));
-       emitpcode(POC_SUBFW, popGet(AOP(left),size));
+
+
+
+       DEBUGpic14_emitcode(";right lit","line = %d",__LINE__);
+       
+       flag=1;
+       size++;
        while(size--) {
          i = (lit >> (size*8)) & 0xff;
-         emitpcode(POC_MOVLW, popGetLit(i));
-         emitSKPNC;
-         emitpcode(POC_SUBFW, popGet(AOP(left),size));
-       }
+         if(sign && flag) {
+           /* handle the first byte differently in signed compares */
 
-       if(ifx) {
-         DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-         //genSkipc(ifx,0,1); //IC_TRUE(ifx) == NULL);
-         genSkipc(&rIfx);
-         //if(sign)
-           emitpLabel(lbl->key);
+             emitpcode(POC_MOVFW, popGet(AOP(left),size));
+             emitpcode(POC_ADDLW, popGetLit(0x80));
+             emitpcode(POC_ADDLW, popGetLit(((-i)&0xff) ^ 0x80));
+             genSkipc(&rIfx);
+             emitSKPZ;
+             emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
 
-         ifx->generated = 1;
+           flag=0;
+         } else {
+
+           emitpcode(POC_MOVLW, popGetLit(i));
+           emitpcode(POC_SUBFW, popGet(AOP(left),size));
+           if(size) {
+             emitSKPZ;
+             emitpcode(POC_GOTO,  popGetLabel(lbl->key));
+           }
+         }
        }
+       emitpLabel(lbl->key);
+       genSkipc(&rIfx);
+       if(sign)
+         emitpLabel(truelbl->key);
+
+       if(ifx) ifx->generated = 1;
        return;
+
+
       }
 
       if(AOP_TYPE(left) == AOP_LIT) {
@@ -3587,81 +3611,157 @@ static void genCmp (operand *left,operand *right,
 
        DEBUGpic14_emitcode(";left lit","lit = %d,sign=%d",lit,sign);
 
+       /* Special cases */
+       if((lit == 0)&& (sign==0)) {
+
+         size--;
+         emitpcode(POC_MOVFW, popGet(AOP(right),size));
+         while(size) 
+           emitpcode(POC_IORFW, popGet(AOP(right),--size));
+         genSkipz2(&rIfx);
+         if(ifx) ifx->generated = 1;
+         return;
+       }
+
        if(size==1) {
          if(sign) {
-           if(lit & 0x80) {
-             emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),7,0));
+           if((lit+1)&0xff) {
+             emitpcode(POC_MOVFW, popGet(AOP(right),0));
+             emitpcode(POC_ADDLW, popGetLit(0x80));
+             emitpcode(POC_ADDLW, popGetLit(((-(lit+1)) & 0xff) ^ 0x80));
+             rIfx.condition ^= 1;
+             genSkipc(&rIfx);
            } else {
-             emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),7,0));
+             genSkipCond(&rIfx,right,0,7);
            }
-           if(ifx) {
-             if(IC_TRUE(ifx) != NULL)
-               emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
-             else
-               emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
+           
+         } else {
+           if(lit & 0xff) {
+             emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
+             emitpcode(POC_SUBFW, popGet(AOP(right),0));
+             DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+             rIfx.condition ^= 1;
+             genSkipc(&rIfx);
+           } else { 
+             emitpcode(POC_MOVFW, popGet(AOP(right),0));
+             genSkipz2(&rIfx);
            }
          }
-         emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
-         emitpcode(POC_SUBFW, popGet(AOP(right),0));
-         DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-         rIfx.condition ^= 1;
-         genSkipc(&rIfx);//      if(ifx) genSkipc(ifx,1,1);//IC_TRUE(ifx)!=NULL);
        } else {
-         size--;
-         //lit++;
-         i = (lit >> (size*8)) & 0xff;
 
-         if(sign) {
-           if(i & 0x80) {
-             emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+         flag = 1;
+         while(size--) {
+           i = (lit >> (size*8)) & 0xff;
+
+           if(flag && sign) {
+             /* Handle first byte of compare differently */
+
+             DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+             if(i) {
+               emitpcode(POC_MOVFW, popGet(AOP(right),size));
+               emitpcode(POC_ADDLW, popGetLit(0x80));
+               emitpcode(POC_SUBLW, popGetLit( (i & 0xff) ^ 0x80));
+               //rIfx.condition ^= 1;
+               genSkipc(&rIfx);
+               emitSKPZ;
+               emitpcode(POC_GOTO,  popGetLabel(truelbl->key));
+             } else {
+               rIfx.condition ^= 1;
+               genSkipCond(&rIfx,right,size,7);
+               rIfx.condition ^= 1;
+             }
+
+             flag = 0;
            } else {
-             emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
-           }
-           if(ifx) {
-             if(IC_TRUE(ifx) != NULL)
-               emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
-             else
-               emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
+
+             if(size) {
+               DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+               emitpcode(POC_MOVLW, popGetLit(i&0xff));
+               emitpcode(POC_SUBFW, popGet(AOP(right),size));
+               emitSKPZ;
+               emitpcode(POC_GOTO,  popGetLabel(lbl->key));
+             } else {
+             DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+               emitpcode(POC_MOVLW, popGetLit((i+1)&0xff));
+               emitpcode(POC_SUBFW, popGet(AOP(right),size));
+
+             }
            }
          }
 
-         emitpcode(POC_MOVFW, popGet(AOP(right),size));
-         emitpcode(POC_SUBLW, popGetLit((i)&0xff));
-         while(size--) {
-           i = (lit >> (size*8)) & 0xff;
-           emitpcode(POC_MOVFW, popGet(AOP(right),size));
-           emitSKPNC;
-           emitpcode(POC_SUBLW, popGetLit((i)&0xff));
-         }
-  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-         genSkipc(&rIfx);//      if(ifx) genSkipc(ifx,0,1);  //IC_TRUE(ifx) == NULL);
+         DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+         emitpLabel(lbl->key);
+
+         rIfx.condition ^= 1;
+         genSkipc(&rIfx);
 
        }
-/*
        if(sign)
-         emitpLabel(lbl->key);
-*/
+         emitpLabel(truelbl->key);
        if(ifx) ifx->generated = 1;
        return;
       }
 
+      /* Compare two variables */
 
-      // CLRC;
       DEBUGpic14_emitcode(";sign","%d",sign);
 
-      emitpcode(POC_MOVFW, popGet(AOP(right),offset));
-      emitpcode(POC_SUBFW, popGet(AOP(left),offset++));
-
       size--;
-      while (size--) {
+      if(sign) {
+       /* Sigh. thus sucks... */
+       if(size) {
+         emitpcode(POC_MOVFW, popGet(AOP(left),size));
+         emitpcode(POC_MOVWF, popRegFromIdx(Gstack_base_addr));
+         emitpcode(POC_MOVLW, popGetLit(0x80));
+         emitpcode(POC_XORWF, popRegFromIdx(Gstack_base_addr));
+         emitpcode(POC_XORFW, popGet(AOP(right),size));
+         emitpcode(POC_SUBFW, popRegFromIdx(Gstack_base_addr));
+       } else {
+         /* Signed char comparison */
+         /* Special thanks to Nikolai Golovchenko for this snippet */
+         emitpcode(POC_MOVFW, popGet(AOP(right),0));
+         emitpcode(POC_SUBFW, popGet(AOP(left),0));
+         emitpcode(POC_RRFW,  popGet(AOP(left),0)); /* could be any register */
+         emitpcode(POC_XORFW, popGet(AOP(left),0));
+         emitpcode(POC_XORFW, popGet(AOP(right),0));
+         emitpcode(POC_ADDLW, popGetLit(0x80));
+
+         DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+         genSkipc(&rIfx);
+         
+         if(ifx) ifx->generated = 1;
+         return;
+       }
+
+      } else {
+
+       emitpcode(POC_MOVFW, popGet(AOP(right),size));
+       emitpcode(POC_SUBFW, popGet(AOP(left),size));
+      }
+
+
+      /* The rest of the bytes of a multi-byte compare */
+      while (size) {
+
+       emitSKPZ;
+       emitpcode(POC_GOTO,  popGetLabel(lbl->key));
+       size--;
+
+       emitpcode(POC_MOVFW, popGet(AOP(right),size));
+       emitpcode(POC_SUBFW, popGet(AOP(left),size));
 
-       emitpcode(POC_MOVFW,   popGet(AOP(right),offset));
-       emitSKPC;
-       emitpcode(POC_INCFSZW, popGet(AOP(right),offset));
-       emitpcode(POC_SUBFW,   popGet(AOP(left),offset));
 
-       offset++;
       }
+
+      emitpLabel(lbl->key);
+
+      DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+      genSkipc(&rIfx);
+      if(ifx) ifx->generated = 1;
+      return;
+
     }
   }
 
@@ -3794,7 +3894,7 @@ static void genc16bit2lit(operand *op, int lit, int offset)
 /*-----------------------------------------------------------------*/
 /* gencjneshort - compare and jump if not equal                    */
 /*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, iCode *ifx)
+static void gencjne(operand *left, operand *right, operand *result, iCode *ifx)
 {
   int size = max(AOP_SIZE(left),AOP_SIZE(right));
   int offset = 0;
@@ -3895,12 +3995,22 @@ static void gencjne(operand *left, operand *right, iCode *ifx)
          emitpcode(POC_MOVF,popGet(AOP(left),offset));
        }
        if(emit_skip) {
-         pic14_emitcode(";***","%s  %d",__FUNCTION__,__LINE__);
-         if(rIfx.condition)
-           emitSKPNZ;
-         else
-           emitSKPZ;
-         emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+         if(AOP_TYPE(result) == AOP_CRY) {
+           pic14_emitcode(";***","%s  %d",__FUNCTION__,__LINE__);
+           if(rIfx.condition)
+             emitSKPNZ;
+           else
+             emitSKPZ;
+           emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+         } else {
+           /* fix me. probably need to check result size too */
+           emitpcode(POC_CLRF,popGet(AOP(result),0));
+           if(rIfx.condition)
+             emitSKPNZ;
+           else
+             emitSKPZ;
+           emitpcode(POC_INCF,popGet(AOP(result),0));
+         }
          if(ifx)
            ifx->generated=1;
        }
@@ -4210,7 +4320,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
         pic14_outBitC(result);
     } else {
       
-      gencjne(left,right,ifx);
+      gencjne(left,right,result,ifx);
 /*
       if(ifx) 
        gencjne(left,right,newiTempLabel(NULL));
@@ -4234,8 +4344,10 @@ static void genCmpEq (iCode *ic, iCode *ifx)
 */
       /* if the result is used in an arithmetic operation
         then put the result in place */
+/*
       if (AOP_TYPE(result) != AOP_CRY) 
        pic14_outAcc(result);
+*/
       /* leave the result in acc */
     }
 
@@ -5310,37 +5422,40 @@ static void genInline (iCode *ic)
 /*-----------------------------------------------------------------*/
 static void genRRC (iCode *ic)
 {
-    operand *left , *result ;
-    int size, offset = 0;
-    char *l;    
+  operand *left , *result ;
+  int size, offset = 0, same;
 
-    /* rotate right with carry */
-    left = IC_LEFT(ic);
-    result=IC_RESULT(ic);
-    aopOp (left,ic,FALSE);
-    aopOp (result,ic,FALSE);
+  /* rotate right with carry */
+  left = IC_LEFT(ic);
+  result=IC_RESULT(ic);
+  aopOp (left,ic,FALSE);
+  aopOp (result,ic,FALSE);
 
-    /* move it to the result */
-    size = AOP_SIZE(result);    
-    offset = size - 1 ;
-    CLRC;
-    while (size--) {
-        l = aopGet(AOP(left),offset,FALSE,FALSE);
-        MOVA(l);
-        pic14_emitcode("rrc","a");
-        if (AOP_SIZE(result) > 1)
-            aopPut(AOP(result),"a",offset--);
-    }
-    /* now we need to put the carry into the
-    highest order byte of the result */
-    if (AOP_SIZE(result) > 1) {
-        l = aopGet(AOP(result),AOP_SIZE(result)-1,FALSE,FALSE);
-        MOVA(l);
+  DEBUGpic14_AopType(__LINE__,left,NULL,result);
+
+  same = pic14_sameRegs(AOP(result),AOP(left));
+
+  size = AOP_SIZE(result);    
+
+  /* get the lsb and put it into the carry */
+  emitpcode(POC_RRFW, popGet(AOP(left),size-1));
+
+  offset = 0 ;
+
+  while(size--) {
+
+    if(same) {
+      emitpcode(POC_RRF, popGet(AOP(left),offset));
+    } else {
+      emitpcode(POC_RRFW, popGet(AOP(left),offset));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offset));
     }
-    pic14_emitcode("mov","acc.7,c");
-    aopPut(AOP(result),"a",AOP_SIZE(result)-1);
-    freeAsmop(left,NULL,ic,TRUE);
-    freeAsmop(result,NULL,ic,TRUE);
+
+    offset++;
+  }
+
+  freeAsmop(left,NULL,ic,TRUE);
+  freeAsmop(result,NULL,ic,TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -5348,44 +5463,44 @@ static void genRRC (iCode *ic)
 /*-----------------------------------------------------------------*/
 static void genRLC (iCode *ic)
 {    
-    operand *left , *result ;
-    int size, offset = 0;
-    char *l;    
+  operand *left , *result ;
+  int size, offset = 0;
+  int same;
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    /* rotate right with carry */
-    left = IC_LEFT(ic);
-    result=IC_RESULT(ic);
-    aopOp (left,ic,FALSE);
-    aopOp (result,ic,FALSE);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  /* rotate right with carry */
+  left = IC_LEFT(ic);
+  result=IC_RESULT(ic);
+  aopOp (left,ic,FALSE);
+  aopOp (result,ic,FALSE);
 
-    /* move it to the result */
-    size = AOP_SIZE(result);    
-    offset = 0 ;
-    if (size--) {
-        l = aopGet(AOP(left),offset,FALSE,FALSE);
-        MOVA(l);
-        pic14_emitcode("add","a,acc");
-        if (AOP_SIZE(result) > 1)
-            aopPut(AOP(result),"a",offset++);
-        while (size--) {
-            l = aopGet(AOP(left),offset,FALSE,FALSE);
-            MOVA(l);
-            pic14_emitcode("rlc","a");
-            if (AOP_SIZE(result) > 1)
-                aopPut(AOP(result),"a",offset++);
-        }
-    }
-    /* now we need to put the carry into the
-    highest order byte of the result */
-    if (AOP_SIZE(result) > 1) {
-        l = aopGet(AOP(result),0,FALSE,FALSE);
-        MOVA(l);
+  DEBUGpic14_AopType(__LINE__,left,NULL,result);
+
+  same = pic14_sameRegs(AOP(result),AOP(left));
+
+  /* move it to the result */
+  size = AOP_SIZE(result);    
+
+  /* get the msb and put it into the carry */
+  emitpcode(POC_RLFW, popGet(AOP(left),size-1));
+
+  offset = 0 ;
+
+  while(size--) {
+
+    if(same) {
+      emitpcode(POC_RLF, popGet(AOP(left),offset));
+    } else {
+      emitpcode(POC_RLFW, popGet(AOP(left),offset));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offset));
     }
-    pic14_emitcode("mov","acc.0,c");
-    aopPut(AOP(result),"a",0);
-    freeAsmop(left,NULL,ic,TRUE);
-    freeAsmop(result,NULL,ic,TRUE);
+
+    offset++;
+  }
+
+
+  freeAsmop(left,NULL,ic,TRUE);
+  freeAsmop(result,NULL,ic,TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -5767,222 +5882,6 @@ static void movLeft2Result (operand *left, int offl,
     }
 }
 
-/*-----------------------------------------------------------------*/
-/* AccAXRrl1 - right rotate c->a:x->c by 1                         */
-/*-----------------------------------------------------------------*/
-static void AccAXRrl1 (char *x)
-{
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    pic14_emitcode("rrc","a");
-    pic14_emitcode("xch","a,%s", x);
-    pic14_emitcode("rrc","a");
-    pic14_emitcode("xch","a,%s", x);
-}
-
-/*-----------------------------------------------------------------*/
-/* AccAXLrl1 - left rotate c<-a:x<-c by 1                          */
-/*-----------------------------------------------------------------*/
-static void AccAXLrl1 (char *x)
-{
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    pic14_emitcode("xch","a,%s",x);
-    pic14_emitcode("rlc","a");
-    pic14_emitcode("xch","a,%s",x);
-    pic14_emitcode("rlc","a");
-}
-#if 0
-/*-----------------------------------------------------------------*/
-/* AccAXLsh1 - left shift a:x<-0 by 1                              */
-/*-----------------------------------------------------------------*/
-static void AccAXLsh1 (char *x)
-{
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    pic14_emitcode("xch","a,%s",x);
-    pic14_emitcode("add","a,acc");
-    pic14_emitcode("xch","a,%s",x);
-    pic14_emitcode("rlc","a");
-}
-#endif
-#if 0
-/*-----------------------------------------------------------------*/
-/* AccAXLsh - left shift a:x by known count (0..7)                 */
-/*-----------------------------------------------------------------*/
-static void AccAXLsh (char *x, int shCount)
-{
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    switch(shCount){
-        case 0 :
-            break;
-        case 1 :
-            AccAXLsh1(x);
-            break;
-        case 2 :
-            AccAXLsh1(x);
-            AccAXLsh1(x);
-            break;
-        case 3 :
-        case 4 :
-        case 5 :                        // AAAAABBB:CCCCCDDD
-            AccRol(shCount);            // BBBAAAAA:CCCCCDDD
-            pic14_emitcode("anl","a,#0x%02x",
-                     SLMask[shCount]);  // BBB00000:CCCCCDDD
-            pic14_emitcode("xch","a,%s",x);   // CCCCCDDD:BBB00000
-            AccRol(shCount);            // DDDCCCCC:BBB00000
-            pic14_emitcode("xch","a,%s",x);   // BBB00000:DDDCCCCC
-            pic14_emitcode("xrl","a,%s",x);   // (BBB^DDD)CCCCC:DDDCCCCC
-            pic14_emitcode("xch","a,%s",x);   // DDDCCCCC:(BBB^DDD)CCCCC
-            pic14_emitcode("anl","a,#0x%02x",
-                     SLMask[shCount]);  // DDD00000:(BBB^DDD)CCCCC
-            pic14_emitcode("xch","a,%s",x);   // (BBB^DDD)CCCCC:DDD00000
-            pic14_emitcode("xrl","a,%s",x);   // BBBCCCCC:DDD00000            
-            break;
-        case 6 :                        // AAAAAABB:CCCCCCDD
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000000BB:CCCCCCDD
-            pic14_emitcode("mov","c,acc.0");  // c = B
-            pic14_emitcode("xch","a,%s",x);   // CCCCCCDD:000000BB
-            AccAXRrl1(x);               // BCCCCCCD:D000000B
-            AccAXRrl1(x);               // BBCCCCCC:DD000000
-            break;
-        case 7 :                        // a:x <<= 7
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 0000000B:CCCCCCCD
-            pic14_emitcode("mov","c,acc.0");  // c = B
-            pic14_emitcode("xch","a,%s",x);   // CCCCCCCD:0000000B
-            AccAXRrl1(x);               // BCCCCCCC:D0000000
-            break;
-        default :
-            break;
-    }
-}
-#endif
-#if 0
-/*-----------------------------------------------------------------*/
-/* AccAXRsh - right shift a:x known count (0..7)                   */
-/*-----------------------------------------------------------------*/
-static void AccAXRsh (char *x, int shCount)
-{   
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    switch(shCount){
-        case 0 :
-            break;
-        case 1 :
-            CLRC;
-            AccAXRrl1(x);               // 0->a:x
-            break;
-        case 2 :
-            CLRC;
-            AccAXRrl1(x);               // 0->a:x
-            CLRC;
-            AccAXRrl1(x);               // 0->a:x
-            break;
-        case 3 :
-        case 4 :
-        case 5 :                        // AAAAABBB:CCCCCDDD = a:x
-            AccRol(8 - shCount);        // BBBAAAAA:DDDCCCCC
-            pic14_emitcode("xch","a,%s",x);   // CCCCCDDD:BBBAAAAA
-            AccRol(8 - shCount);        // DDDCCCCC:BBBAAAAA
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000CCCCC:BBBAAAAA
-            pic14_emitcode("xrl","a,%s",x);   // BBB(CCCCC^AAAAA):BBBAAAAA
-            pic14_emitcode("xch","a,%s",x);   // BBBAAAAA:BBB(CCCCC^AAAAA)
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000AAAAA:BBB(CCCCC^AAAAA)
-            pic14_emitcode("xch","a,%s",x);   // BBB(CCCCC^AAAAA):000AAAAA
-            pic14_emitcode("xrl","a,%s",x);   // BBBCCCCC:000AAAAA
-            pic14_emitcode("xch","a,%s",x);   // 000AAAAA:BBBCCCCC
-            break;
-        case 6 :                        // AABBBBBB:CCDDDDDD
-            pic14_emitcode("mov","c,acc.7");
-            AccAXLrl1(x);               // ABBBBBBC:CDDDDDDA
-            AccAXLrl1(x);               // BBBBBBCC:DDDDDDAA
-            pic14_emitcode("xch","a,%s",x);   // DDDDDDAA:BBBBBBCC
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000000AA:BBBBBBCC
-            break;
-        case 7 :                        // ABBBBBBB:CDDDDDDD
-            pic14_emitcode("mov","c,acc.7");  // c = A
-            AccAXLrl1(x);               // BBBBBBBC:DDDDDDDA
-            pic14_emitcode("xch","a,%s",x);   // DDDDDDDA:BBBBBBCC
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 0000000A:BBBBBBBC
-            break;
-        default :
-            break;
-    }
-}
-#endif
-/*-----------------------------------------------------------------*/
-/* AccAXRshS - right shift signed a:x known count (0..7)           */
-/*-----------------------------------------------------------------*/
-static void AccAXRshS (char *x, int shCount)
-{   
-    symbol *tlbl ;
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    switch(shCount){
-        case 0 :
-            break;
-        case 1 :
-            pic14_emitcode("mov","c,acc.7");
-            AccAXRrl1(x);               // s->a:x
-            break;
-        case 2 :
-            pic14_emitcode("mov","c,acc.7");
-            AccAXRrl1(x);               // s->a:x
-            pic14_emitcode("mov","c,acc.7");
-            AccAXRrl1(x);               // s->a:x
-            break;
-        case 3 :
-        case 4 :
-        case 5 :                        // AAAAABBB:CCCCCDDD = a:x
-            tlbl = newiTempLabel(NULL);
-            AccRol(8 - shCount);        // BBBAAAAA:CCCCCDDD
-            pic14_emitcode("xch","a,%s",x);   // CCCCCDDD:BBBAAAAA
-            AccRol(8 - shCount);        // DDDCCCCC:BBBAAAAA
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000CCCCC:BBBAAAAA
-            pic14_emitcode("xrl","a,%s",x);   // BBB(CCCCC^AAAAA):BBBAAAAA
-            pic14_emitcode("xch","a,%s",x);   // BBBAAAAA:BBB(CCCCC^AAAAA)
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000AAAAA:BBB(CCCCC^AAAAA)
-            pic14_emitcode("xch","a,%s",x);   // BBB(CCCCC^AAAAA):000AAAAA
-            pic14_emitcode("xrl","a,%s",x);   // BBBCCCCC:000AAAAA
-            pic14_emitcode("xch","a,%s",x);   // 000SAAAA:BBBCCCCC
-            pic14_emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100); 
-            pic14_emitcode("orl","a,#0x%02x",
-                     (unsigned char)~SRMask[shCount]);  // 111AAAAA:BBBCCCCC
-            pic14_emitcode("","%05d_DS_:",tlbl->key+100);
-            break;                      // SSSSAAAA:BBBCCCCC
-        case 6 :                        // AABBBBBB:CCDDDDDD
-            tlbl = newiTempLabel(NULL);
-            pic14_emitcode("mov","c,acc.7");
-            AccAXLrl1(x);               // ABBBBBBC:CDDDDDDA
-            AccAXLrl1(x);               // BBBBBBCC:DDDDDDAA
-            pic14_emitcode("xch","a,%s",x);   // DDDDDDAA:BBBBBBCC
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 000000AA:BBBBBBCC
-            pic14_emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100); 
-            pic14_emitcode("orl","a,#0x%02x",
-                     (unsigned char)~SRMask[shCount]);  // 111111AA:BBBBBBCC
-            pic14_emitcode("","%05d_DS_:",tlbl->key+100);
-            break;
-        case 7 :                        // ABBBBBBB:CDDDDDDD
-            tlbl = newiTempLabel(NULL);
-            pic14_emitcode("mov","c,acc.7");  // c = A
-            AccAXLrl1(x);               // BBBBBBBC:DDDDDDDA
-            pic14_emitcode("xch","a,%s",x);   // DDDDDDDA:BBBBBBCC
-            pic14_emitcode("anl","a,#0x%02x",
-                     SRMask[shCount]);  // 0000000A:BBBBBBBC
-            pic14_emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100); 
-            pic14_emitcode("orl","a,#0x%02x",
-                     (unsigned char)~SRMask[shCount]);  // 1111111A:BBBBBBBC
-            pic14_emitcode("","%05d_DS_:",tlbl->key+100);
-            break;
-        default :
-            break;
-    }
-}
-
 /*-----------------------------------------------------------------*/
 /* shiftL2Left2Result - shift left two bytes from left to result   */
 /*-----------------------------------------------------------------*/
@@ -6132,103 +6031,104 @@ static void shiftR2Left2Result (operand *left, int offl,
     MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
   }
   /* a:x >> shCount (x = lsb(result))*/
+/*
   if(sign)
     AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
   else {
-    //AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
-    
-    switch(shCount) {
-    case 0:
-      break;
-    case 1:
-    case 2:
-    case 3:
+    AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
+*/
+  switch(shCount) {
+  case 0:
+    break;
+  case 1:
+  case 2:
+  case 3:
+    emitCLRC;
+    if(same) {
+      emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RRF,popGet(AOP(result),offr));
+    } else {
+
+      emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16));
+      emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RRFW, popGet(AOP(left),offl));
+      emitpcode(POC_MOVWF,popGet(AOP(result),offr));
+    }
+
+    while(--shCount) {
       emitCLRC;
-      if(same) {
-       emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RRF,popGet(AOP(result),offr));
-      } else {
+      emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RRF,popGet(AOP(result),offr));
+    }
+    break;
+  case 4:
+  case 5:
+    if(same) {
 
-       emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16));
-       emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RRFW, popGet(AOP(left),offl));
-       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
-      }
+      emitpcode(POC_MOVLW, popGetLit(0xf0));
+      emitpcode(POC_ANDWF, popGet(AOP(result),offr));
+      emitpcode(POC_SWAPF, popGet(AOP(result),offr));
 
-      while(--shCount) {
-       emitCLRC;
-       emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RRF,popGet(AOP(result),offr));
-      }
-      break;
-    case 4:
-    case 5:
-      if(same) {
+      emitpcode(POC_SWAPF, popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_ANDFW, popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_ADDWF, popGet(AOP(result),offr));
+    } else {
+      emitpcode(POC_SWAPF, popGet(AOP(left),offl));
+      emitpcode(POC_ANDLW, popGetLit(0x0f));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr));
 
-       emitpcode(POC_MOVLW, popGetLit(0xf0));
-       emitpcode(POC_ANDWF, popGet(AOP(result),offr));
-       emitpcode(POC_SWAPF, popGet(AOP(result),offr));
+      emitpcode(POC_SWAPF, popGet(AOP(left),offl+MSB16));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_ANDLW, popGetLit(0xf0));
+      emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_ADDWF, popGet(AOP(result),offr));
+    }
 
-       emitpcode(POC_SWAPF, popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_ANDFW, popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_ADDWF, popGet(AOP(result),offr));
-      } else {
-       emitpcode(POC_SWAPF, popGet(AOP(left),offl));
-       emitpcode(POC_ANDLW, popGetLit(0x0f));
-       emitpcode(POC_MOVWF, popGet(AOP(result),offr));
-
-       emitpcode(POC_SWAPF, popGet(AOP(left),offl+MSB16));
-       emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_ANDLW, popGetLit(0xf0));
-       emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_ADDWF, popGet(AOP(result),offr));
-      }
+    if(shCount >=5) {
+      emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RRF, popGet(AOP(result),offr));
+    }
 
-      if(shCount >=5) {
-       emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RRF, popGet(AOP(result),offr));
-      }
+    break;
 
-      break;
+  case 6:
+    if(same) {
 
-    case 6:
-      if(same) {
-
-       emitpcode(POC_RLF,  popGet(AOP(result),offr));
-       emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
-
-       emitpcode(POC_RLF,  popGet(AOP(result),offr));
-       emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RLFW, popGet(AOP(result),offr));
-       emitpcode(POC_ANDLW,popGetLit(0x03));
-       emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_XORWF,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
-      } else {
-       emitpcode(POC_RLFW, popGet(AOP(left),offl));
-       emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RLFW, popGet(AOP(result),offl+MSB16));
-       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
-       emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
-       emitpcode(POC_RLF,  popGet(AOP(result),offr));
-       emitpcode(POC_RLFW, popGet(AOP(result),offr));
-       emitpcode(POC_ANDLW,popGetLit(0x03));
-       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
-      }
+      emitpcode(POC_RLF,  popGet(AOP(result),offr));
+      emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
 
-      break;
-    case 7:
+      emitpcode(POC_RLF,  popGet(AOP(result),offr));
+      emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RLFW, popGet(AOP(result),offr));
+      emitpcode(POC_ANDLW,popGetLit(0x03));
+      emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_XORWF,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_MOVWF,popGet(AOP(result),offr));
+    } else {
       emitpcode(POC_RLFW, popGet(AOP(left),offl));
-      emitpcode(POC_RLFW, popGet(AOP(left),offl+MSB16));
+      emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RLFW, popGet(AOP(result),offl+MSB16));
       emitpcode(POC_MOVWF,popGet(AOP(result),offr));
-      emitpcode(POC_CLRF, popGet(AOP(result),offr+MSB16));
       emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
+      emitpcode(POC_RLF,  popGet(AOP(result),offr));
+      emitpcode(POC_RLFW, popGet(AOP(result),offr));
+      emitpcode(POC_ANDLW,popGetLit(0x03));
+      emitpcode(POC_MOVWF,popGet(AOP(result),offr));
     }
+
+    break;
+  case 7:
+    emitpcode(POC_RLFW, popGet(AOP(left),offl));
+    emitpcode(POC_RLFW, popGet(AOP(left),offl+MSB16));
+    emitpcode(POC_MOVWF,popGet(AOP(result),offr));
+    emitpcode(POC_CLRF, popGet(AOP(result),offr+MSB16));
+    emitpcode(POC_RLF,  popGet(AOP(result),offr+MSB16));
   }
 }
 
+
 /*-----------------------------------------------------------------*/
 /* shiftLLeftOrResult - shift left one byte from left, or to result*/
 /*-----------------------------------------------------------------*/
index c932153768122eb46a36e875d4f5e35b39fbf6a0..a35f558983201b034eaa47aa7e91a625854f70a8 100644 (file)
@@ -1267,9 +1267,11 @@ void genMinus (iCode *ic)
       /* res = 0 - right */
       if (pic14_sameRegs(AOP(IC_RIGHT(ic)), AOP(IC_RESULT(ic))) ) {
        emitpcode(POC_COMF,  popGet(AOP(IC_RIGHT(ic)),0));
+       emitpcode(POC_INCF,  popGet(AOP(IC_RIGHT(ic)),0));
       } else { 
-       emitpcode(POC_MOVFW,  popGet(AOP(IC_RIGHT(ic)),0));
+       emitpcode(POC_COMFW,  popGet(AOP(IC_RIGHT(ic)),0));
        emitpcode(POC_MOVWF,  popGet(AOP(IC_RESULT(ic)),0));
+       emitpcode(POC_INCF,   popGet(AOP(IC_RESULT(ic)),0));
       }
       goto release;
     }
index 196222c6f907f5b1f489ef9a7759d2ed94d9317b..d5fe5caee08a0822469bfcb6945fef71b47e8f14 100644 (file)
@@ -79,6 +79,7 @@ SRC = b.c \
        rotate1.c \
        rotate2.c \
        rotate3.c \
+       rotate4.c \
        struct1.c \
        sub.c \
        sub2.c \
@@ -86,6 +87,8 @@ SRC = b.c \
        while.c \
        xor.c
 
+#      mul1.c \
+
 COD := $(patsubst %.c, %.cod, $(SRC))
 ASM := $(patsubst %.c, %.asm, $(SRC))
 STC := $(patsubst %.c, %.stc, $(SRC))
index 6875a5eaa37ddacaf532fca15ee30b5e4915f18b..b04fde3395039a544e7331d8dedf20318c77cdac 100644 (file)
@@ -266,6 +266,13 @@ void c_minus1(void)
     failures++;
 }
 
+void c_c0gtc1(void)
+{
+
+  if(char0 < char1)
+    failures++;
+}
+
 void
 main (void)
 {
@@ -301,6 +308,14 @@ main (void)
   int0 = -1;
   c_minus1();
 
+
+  char0 = 5;
+  char1 = 3;
+  c_c0gtc1();
+
+  char1 = -3;
+  c_c0gtc1();
+
   success = failures;
   done ();
 }
index 4b923dae77b170871b2293d43aaa2ca971ac129a..368d8fde72070d2d9fb1e3ef9cd3fa1712f0fbaa 100644 (file)
@@ -47,8 +47,6 @@ void c_0(void)
   if(ulong0 > 0)
     failures++;
 
-  if(ulong0 < 0)
-    failures++;
 }
 
 // compare to 1
@@ -74,9 +72,6 @@ void c_1(void)
   if(long1 < 0)
     failures++;
 
-  if(ulong1 < 0)
-    failures++;
-
   if(long1 < 1)
     failures++;
 
@@ -160,8 +155,10 @@ void c_200(void)
 
 // compare to 0x20000
 // assumes
-// achar0 == 0x20000
-// aint0  == 0x20000
+// long0  == 0x20000
+// ulong0 == 0x20000
+// long1  != 0x20000
+// ulong1 != 0x20000
 
 void c_20000(void)
 {
@@ -369,6 +366,32 @@ void c_long2long_neq(void)
     failures++;
 
 }
+
+
+//  long0=-100;
+//  long1=-1000;
+void
+c_long2neglit(void)
+{
+
+  if(long0>0)
+    failures++;
+  if(long1>0)
+    failures++;
+
+  if(long1 > long0)
+    failures++;
+
+  if(long1 > 100)
+    failures++;
+
+  if(long0 > -50)
+    failures++;
+
+  if(long1 < -5000)
+    failures++;
+}
+
 void
 main (void)
 {
@@ -401,6 +424,10 @@ main (void)
   long0 = -1;
   c_minus1();
 
+  long0=-100;
+  long1=-1000;
+  c_long2neglit();
+
   success = failures;
   done ();
 }
index e5c817749bdb3eb918febe9cdab2091e5aa5aa16..437f82c13a7480c2cda51548b084225aa2646d7b 100644 (file)
@@ -4,7 +4,7 @@ unsigned char success = 0;
 unsigned char failures = 0;
 unsigned char dummy = 0;
 
-bit bit0 = 0;
+//bit bit0 = 0;
 int int0 = 0;
 int int1 = 0;
 unsigned char uchar0 = 0;
@@ -152,6 +152,14 @@ void c_long(void)
 
 }
 
+void c_uminus(void)
+{
+
+  int1 = -int0;
+  if(int1 < 0)
+    failures++;
+}
+
 void
 main (void)
 {
@@ -160,6 +168,11 @@ main (void)
   c_int();
   c_long();
 
+  int0 = -1;
+  c_uminus();
+  if(int1 != 1)
+    failures++;
+
   success = failures;
   done ();
 }