PIC Port Added support for subtraction
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 25 Mar 2001 18:24:53 +0000 (18:24 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 25 Mar 2001 18:24:53 +0000 (18:24 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@711 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/pcode.c
src/regression/Makefile
src/regression/b.c
src/regression/sub.c [new file with mode: 0644]

index 0ce2ee34338864828891c5b9279c58e117148390..1d1916c29f3fee91a2c2bf25c3eb32773c0237f7 100644 (file)
@@ -90,6 +90,8 @@ static struct {
     set *sendSet;
 } _G;
 
+char *Safe_strdup(char *str);  // in pcode.c
+
 extern int pic14_ptrRegReq ;
 extern int pic14_nRegs;
 extern FILE *codeOutFile;
@@ -120,7 +122,7 @@ static unsigned char   SRMask[] = {0xFF, 0x7F, 0x3F, 0x1F, 0x0F,
 
 #define FUNCTION_LABEL_INC  20
 static int labelOffset=0;
-static int debug_verbose=0;
+static int debug_verbose=1;
 
 static  pBlock *pb;
 
@@ -1085,7 +1087,16 @@ static pCodeOp *popGet (asmop *aop, int offset, bool bit16, bool dname)
     case AOP_DPTR2:
     case AOP_ACC:
         DEBUGemitcode(";8051 legacy","%d",__LINE__);
-       return NULL;
+       pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
+       pcop->type = PO_SFR_REGISTER;
+
+       PCOR(pcop)->rIdx = -1;
+       PCOR(pcop)->r = NULL;
+       // Really nasty hack to check for temporary registers
+
+       pcop->name = Safe_strdup("BAD_REGISTER");
+
+       return pcop;
        
     case AOP_IMMD:
       DEBUGemitcode(";","%d",__LINE__);
@@ -3220,17 +3231,6 @@ static void genPlus (iCode *ic)
              emitpcode(POC_BCF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
              emitSKPZ;
              emitpcode(POC_BSF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
-/*
-             emitcode("andlw","1");
-             emitcode("bcf","(%s >> 3), (%s & 7)",
-                      AOP(IC_RESULT(ic))->aopu.aop_dir,
-                      AOP(IC_RESULT(ic))->aopu.aop_dir);
-             emitSKPZ;
-             emitcode("bsf","(%s >> 3), (%s & 7)",
-                      AOP(IC_RESULT(ic))->aopu.aop_dir,
-                      AOP(IC_RESULT(ic))->aopu.aop_dir);
-*/
-
            } else {
              emitpcode(POC_MOVWF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
              emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
@@ -3357,7 +3357,9 @@ static bool genMinusDec (iCode *ic)
     /* will try to generate an increment */
     /* if the right side is not a literal 
     we cannot */
-    if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
+    if ((AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT) || 
+       (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY) || 
+       (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) )
         return FALSE ;
 
     DEBUGemitcode ("; lit val","%d",(unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
@@ -3373,11 +3375,22 @@ static bool genMinusDec (iCode *ic)
         (icount == 1)) {
 
       if(size == 2) { 
+       emitpcode(POC_DECF,    popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
+       emitpcode(POC_INCFSZW, popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
+       emitpcode(POC_DECF,    popGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
+
        emitcode("decf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
        emitcode("incfsz","%s,w",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
        emitcode(" decf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
       } else {
        /* size is 3 or 4 */
+       emitpcode(POC_MOVLW,  popGetLit(0xff));
+       emitpcode(POC_ADDWF,  popGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
+       emitSKPNC;
+       emitpcode(POC_ADDWF,  popGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
+       emitSKPNC;
+       emitpcode(POC_ADDWF,  popGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
+
        emitcode("movlw","0xff");
        emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
 
@@ -3387,6 +3400,9 @@ static bool genMinusDec (iCode *ic)
        emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
 
        if(size > 3) {
+         emitSKPNC;
+         emitpcode(POC_ADDWF,  popGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
+
          emitcode("skpnc","");
          emitSKPNC;
          emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
@@ -3420,8 +3436,13 @@ static bool genMinusDec (iCode *ic)
                   aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
                   aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
     if(size==1) {
+
       emitcode("decf","%s,w",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
       emitcode("movwf","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+
+      emitpcode(POC_DECFW,  popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+      emitpcode(POC_MOVWF,  popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+
       return TRUE;
     }
 
@@ -3477,81 +3498,227 @@ static void genMinusBits (iCode *ic)
 /*-----------------------------------------------------------------*/
 static void genMinus (iCode *ic)
 {
-    int size, offset = 0;
-    unsigned long lit = 0L;
+  int size, offset = 0;
+  unsigned long lit = 0L;
 
-    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    aopOp (IC_LEFT(ic),ic,FALSE);
-    aopOp (IC_RIGHT(ic),ic,FALSE);
-    aopOp (IC_RESULT(ic),ic,TRUE);
+  DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  aopOp (IC_LEFT(ic),ic,FALSE);
+  aopOp (IC_RIGHT(ic),ic,FALSE);
+  aopOp (IC_RESULT(ic),ic,TRUE);
+
+  if (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY  &&
+      AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
+    operand *t = IC_RIGHT(ic);
+    IC_RIGHT(ic) = IC_LEFT(ic);
+    IC_LEFT(ic) = t;
+  }
 
-    /* special cases :- */
-    /* if both left & right are in bit space */
-    if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
-        AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
-        genMinusBits (ic);
-        goto release ;
+  /* special cases :- */
+  /* if both left & right are in bit space */
+  if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
+      AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
+    genPlusBits (ic);
+    goto release ;
+  }
+
+  /* if I can do an decrement instead
+     of subtract then GOOD for ME */
+  if (genMinusDec (ic) == TRUE)
+    goto release;   
+
+  size = getDataSize(IC_RESULT(ic));   
+
+  if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
+    /* Add a literal to something else */
+
+    lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
+    lit = - (long)lit;
+
+    /* add the first byte: */
+    emitcode("movlw","0x%x", lit & 0xff);
+    emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+    emitpcode(POC_MOVLW,  popGetLit(lit & 0xff));
+    emitpcode(POC_ADDWF,  popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+
+
+    offset = 1;
+    size--;
+
+    while(size-- > 0) {
+
+      lit >>= 8;
+
+      if(lit & 0xff) {
+
+       if((lit & 0xff) == 0xff) {
+         emitpcode(POC_MOVLW,  popGetLit(0xff));
+         emitSKPC;
+         emitpcode(POC_ADDWF,  popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+       } else {
+         emitpcode(POC_MOVLW,  popGetLit(lit & 0xff));
+         emitSKPNC;
+         emitpcode(POC_MOVLW,  popGetLit((lit+1) & 0xff));
+         emitpcode(POC_ADDWF,  popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+       }
+
+      } else {
+       /* do the rlf known zero trick here */
+       emitpcode(POC_MOVLW,  popGetLit(1));
+       emitSKPNC;
+       emitpcode(POC_ADDWF,  popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+      }
+      offset++;
     }
 
-    /* if I can do an decrement instead
-    of subtract then GOOD for ME */
-    if (genMinusDec (ic) == TRUE)
-        goto release;   
+  } else if(AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
+    // bit subtraction
 
-    size = getDataSize(IC_RESULT(ic));   
+    emitcode(";bitsub","right is bit: %s",aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+    emitcode(";bitsub","left is bit: %s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+    emitcode(";bitsub","result is bit: %s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
 
-    if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
-      /* Add a literal to something else */
+    /* here we are subtracting a bit from a char or int */
+    if(size == 1) {
+      if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
 
-      lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
-      lit = - (long)lit;
+       emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+       emitpcode(POC_DECF ,  popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
 
-      /* add the first byte: */
-      emitcode("movlw","0x%x", lit & 0xff);
-      emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+       emitcode("btfsc","(%s >> 3), (%s & 7)",
+                AOP(IC_RIGHT(ic))->aopu.aop_dir,
+                AOP(IC_RIGHT(ic))->aopu.aop_dir);
+       emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+      } else {
 
-      offset = 1;
-      size--;
+       if(AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
+         emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+         emitpcode(POC_XORLW , popGetLit(1));
+       }else  if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
+             (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
 
-      while(size--){
+         lit = (unsigned long)floatFromVal(AOP(IC_LEFT(ic))->aopu.aop_lit);
 
-       emitcode("rlf","_known_zero,w");
-       emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+         if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
+           if (sameRegs(AOP(IC_RIGHT(ic)), AOP(IC_RESULT(ic))) ) {
+             if(lit & 1) {
+               emitpcode(POC_MOVLW , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+               emitpcode(POC_XORWF , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+             }
+           }else{
+             emitpcode(POC_BCF ,     popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+             if(lit & 1) 
+               emitpcode(POC_BTFSS , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+             else
+               emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+             emitpcode(POC_BSF ,     popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+           }
+           goto release;
+         } else {
+           emitpcode(POC_MOVLW , popGetLit(lit & 0xff));
+           emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+           emitpcode(POC_MOVLW , popGetLit((lit-1) & 0xff));
+           emitpcode(POC_MOVWF , popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
 
-       lit >>= 8;
-       if(lit & 0xff) {
-         emitcode("movlw","0x%x", lit & 0xff);
-         emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+         }
+
+       } else {
+         emitpcode(POC_MOVFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+         emitpcode(POC_BTFSC , popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+         emitpcode(POC_DECFW , popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+       }
          
+       if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
+           
+         emitpcode(POC_MOVWF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+
+       } else  {
+         emitpcode(POC_ANDLW , popGetLit(1));
+/*
+         emitpcode(POC_BCF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+         emitSKPZ;
+         emitpcode(POC_BSF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+*/
        }
-       offset++;
+
       }
 
+    }
+  } else {
+
+    if(strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a") == 0 ) {
+      DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+      emitpcode(POC_SUBFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+      emitpcode(POC_SUBLW, popGetLit(0));
+      emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
     } else {
 
-      emitcode("movf","%s", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
-      emitcode("subwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+      if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
+       emitpcode(POC_SUBFW, popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+       emitpcode(POC_SUBLW, popGetLit(0));
+       if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
+         emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+      } else {
 
-      offset = 1;
-      size--;
+       DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+       if(AOP_TYPE(IC_RIGHT(ic)) != AOP_ACC) 
+         emitpcode(POC_MOVFW,popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
 
-      while(size--){
-       emitcode("movf","%s,w",  aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
-       emitSKPNC;
-       emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
-       emitcode("subwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
-       
+       if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
+         emitpcode(POC_SUBWF, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+       else {
+         if( (AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) ||
+             (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ) {
+           emitpcode(POC_SUBLW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+         } else {
+           emitpcode(POC_SUBFW, popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+         }
+         if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
+           if ( AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
+             emitpcode(POC_BCF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+             emitSKPZ;
+             emitpcode(POC_BSF ,   popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+           }else
+             emitpcode(POC_MOVWF,popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+         }
+       }
+      }
+    }
+
+    /*
+      emitpcode(POC_MOVFW,  popGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+
+      if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
+      emitpcode(POC_SUBFW,  popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+      } else {
+      emitpcode(POC_SUBFW,  popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+      emitpcode(POC_MOVWF,  popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+      }
+    */
+    offset = 1;
+    size--;
+
+    while(size--){
+      if (!sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
+       emitpcode(POC_MOVFW,  popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+       emitpcode(POC_MOVWF,  popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
       }
+      emitpcode(POC_MOVFW,  popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+      emitSKPNC;
+      emitpcode(POC_INCFSZW,popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
+      emitpcode(POC_SUBWF,  popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
 
+      offset++;
     }
 
+  }
+
 
-    //    adjustArithmeticResult(ic);
+  //    adjustArithmeticResult(ic);
         
-release:
-    freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
-    freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
-    freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+ release:
+  freeAsmop(IC_LEFT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+  freeAsmop(IC_RIGHT(ic),NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+  freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
 }
 
 
@@ -8097,7 +8264,7 @@ static void genGenPointerSet (operand *right,
         offset = 0 ;
 
         while (--size) {
-            char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
+         //char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
            if(size)
              emitcode("incf","fsr,f");
            emitcode("movf","%s,w",aopGet(AOP(right),offset++,FALSE,FALSE));
@@ -8375,7 +8542,7 @@ static void genAssign (iCode *ic)
         if (AOP_TYPE(right) == AOP_CRY) {
          emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
          emitpcode(POC_BTFSC,  popGet(AOP(right),0,FALSE,FALSE));
-         emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
+         emitpcode(POC_BSF,    popGet(AOP(result),0,FALSE,FALSE));
 
          emitcode("bcf","(%s >> 3),(%s & 7)",
                   AOP(result)->aopu.aop_dir,
@@ -8390,8 +8557,11 @@ static void genAssign (iCode *ic)
         }
 
         /* we need to or */
+       emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
         toBoolean(right);
-        aopPut(AOP(result),"a",0);
+       emitSKPZ;
+       emitpcode(POC_BSF,    popGet(AOP(result),0,FALSE,FALSE));
+        //aopPut(AOP(result),"a",0);
         goto release ;
     }
 
@@ -8419,14 +8589,21 @@ static void genAssign (iCode *ic)
        }
     } else {
        while (size--) {
-         if(AOP_TYPE(right) == AOP_LIT)
+         if(AOP_TYPE(right) == AOP_LIT) {
            emitpcode(POC_MOVLW, popGet(AOP(right),offset,FALSE,FALSE));
-         //emitcode("movlw","%s", aopGet(AOP(right),offset,FALSE,FALSE));
-         else
+           emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
+
+         } else if (AOP_TYPE(right) == AOP_CRY) {
+           emitpcode(POC_CLRF, popGet(AOP(result),offset,FALSE,FALSE));
+           if(offset == 0) {
+             emitpcode(POC_BTFSS, popGet(AOP(right),0,FALSE,FALSE));
+             emitpcode(POC_INCF, popGet(AOP(result),0,FALSE,FALSE));
+           }
+         } else {
            emitpcode(POC_MOVFW, popGet(AOP(right),offset,FALSE,FALSE));
-         //emitcode("movf","%s,w", aopGet(AOP(right),offset,FALSE,FALSE));
+           emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
+         }
            
-         emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
          //emitcode("movwf","%s", aopGet(AOP(result),offset,FALSE,FALSE));
          offset++;
        }
index 3b464c3480bd23c63cc35ebec6625fd01501ffb2..545909eb7b481299fe09c70f47ff034a81368da6 100644 (file)
@@ -65,7 +65,7 @@ static char *scpXORWF = "XORWF";
 
 
 static pFile *the_pFile = NULL;
-static int peepOptimizing = 1;
+static int peepOptimizing = 0;
 static int GpCodeSequenceNumber = 1;
 
 /****************************************************************/
index 31b090bfb291cc20c9db8b5dd8374f0c5928aee2..d1ce27ad31432c0a3b79f24dd649c8208671edd2 100644 (file)
@@ -61,6 +61,7 @@ SRC = b.c \
        compare.c \
        compare2.c \
        for.c \
+       sub.c \
        while.c
 
 COD := $(patsubst %.c, %.cod, $(SRC))
index 144f5ae8f16506d24219a7aee444da88d3b19d10..4335f7913456c6efd89374d86deb8f176bdf6b2f 100644 (file)
@@ -10,12 +10,12 @@ void done(void)
 {
   success++;
 }
-
+/*
 void incptr(unsigned char *ucP)
 {
   *ucP = *ucP + 1;
 }
-
+*/
 
 void inc(unsigned char k)
 {
diff --git a/src/regression/sub.c b/src/regression/sub.c
new file mode 100644 (file)
index 0000000..fd3a6f1
--- /dev/null
@@ -0,0 +1,208 @@
+//#include "p16c84.h"
+// Addition tests
+
+/* bit types are not ANSI - so provide a way of disabling bit types
+ * if this file is used to test other compilers besides SDCC */
+#define SUPPORT_BIT_TYPES 1
+
+/* Some compilers that support bit types do not support bit arithmetic 
+ * (like bitx = bity + bitz;) */
+#define SUPPORT_BIT_ARITHMETIC 1
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+#if SUPPORT_BIT_TYPES
+
+bit bit0 = 0;
+bit bit1 = 0;
+bit bit2 = 0;
+bit bit3 = 0;
+bit bit4 = 0;
+bit bit5 = 0;
+bit bit6 = 0;
+bit bit7 = 0;
+bit bit8 = 0;
+bit bit9 = 0;
+bit bit10 = 0;
+bit bit11 = 0;
+
+#endif
+
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+unsigned char achar2 = 0;
+unsigned char achar3 = 0;
+unsigned char *acharP = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void sub_lit_from_uchar(void)
+{
+
+  achar0 = achar0 - 5;
+
+  if(achar0 != 0xfb)
+    failures++;
+
+  achar0 -= 10;
+
+  if(achar0 != 0xf1)
+    failures++;
+
+  achar0 = achar0 -1;  // Should be a decrement
+  if(achar0 != 0xf0)
+    failures++;
+
+  for(achar1 = 0; achar1 < 100; achar1++)
+    achar0 -= 2;
+
+  if(achar0 != 40)
+    failures++;
+
+}
+
+// achar0 = 1
+// achar1 = 100
+
+void sub_uchar2uchar(void)
+{
+
+  achar1 = achar1 - achar0;
+
+  if(achar1 != 99)
+    failures++;
+
+  for(achar2 = 0; achar2<7; achar2++)
+    achar1 -= achar0;
+
+  if(achar1 != 92)
+    failures++;
+
+}
+
+// assumes
+//  achar0 = 10
+//  achar1 = 32
+//  achar2, achar3 can be anything.
+
+void sub_uchar2uchar2(void)
+{
+
+
+  achar0--;
+  achar0 = achar0 - 1;
+  achar0 = achar0 - 2;
+  achar0 = achar0 - 3;
+  if(achar0 != 3)
+    failures++;
+
+
+  achar1 -= achar0;
+  if(achar1 != 29)
+    failures++;
+
+  achar2 = achar1 - achar0;
+  if(achar2 != 26)
+    failures++;
+
+
+  achar3 = achar2 - achar1 - achar0;
+  if(achar3 != 0xfa)
+    failures++;
+
+}
+
+// sub_bits
+// all bit variables are 0 upon entry.
+
+#if SUPPORT_BIT_TYPES
+void sub_bits(void)
+{
+
+  bit1 = bit0;
+
+  bit0 = 1;
+
+  if(bit1 != 0)
+    failures++;
+
+  bit1 = bit0-bit1;   // 1 - 0 => 1
+  if(bit1 != 1)
+    failures++;
+
+#if SUPPORT_BIT_ARITHMETIC
+  bit2 = bit1-bit0;   // 1 - 1 => 0
+  if(bit2)
+    failures++;
+
+  bit7 = bit4-bit5;
+  bit6 = bit4+bit5;
+  bit3 = bit4-bit5-bit6-bit7-bit0; // 0-0-0-0-1 => 1
+  if(!bit3)
+    failures++;
+#endif
+}
+#endif
+
+/* add_bit2uchar(void) - assumes bit0 = 1, achar0 = 7  */
+
+void add_bit2uchar(void)
+{
+
+  achar0 -= bit0;
+
+  if(achar0 != 6)
+    failures++;
+
+  if(achar0 == bit0)
+    failures++;
+
+}
+
+void add_bit2uint(void)
+{
+
+  if(aint0 != bit11)
+    failures++;
+
+  aint0 += bit0;
+  if(aint0!=1)
+    failures++;
+
+}
+void main(void)
+{
+
+  sub_lit_from_uchar();
+
+  achar0=1;
+  achar1=100;
+  sub_uchar2uchar();
+
+
+  achar0 = 10;
+  achar1 = 32;
+  sub_uchar2uchar2();
+
+#if SUPPORT_BIT_TYPES
+  sub_bits();
+
+  achar0 = 7;
+  bit0 = 1;
+  add_bit2uchar();
+  //add_bit2uint();
+#endif
+
+
+  success = failures;
+  done();
+}