]> git.gag.com Git - fw/sdcc/commitdiff
PIC port on going development.most of addition, arrays, pointers,
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 31 Dec 2000 16:40:27 +0000 (16:40 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 31 Dec 2000 16:40:27 +0000 (16:40 +0000)
for loops, while loops, and structure operations are now working

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@519 4a8a32a2-be11-0410-ad9d-d568d2c75423

16 files changed:
src/pic/gen.c
src/pic/glue.c
src/pic/main.c
src/pic/peeph.def
src/pic/ralloc.c
src/regression/Makefile
src/regression/add.c [new file with mode: 0644]
src/regression/arrays.c [new file with mode: 0644]
src/regression/b.c
src/regression/bool1.c [new file with mode: 0644]
src/regression/call1.c [new file with mode: 0644]
src/regression/compare2.c [new file with mode: 0644]
src/regression/for.c [new file with mode: 0644]
src/regression/pointer1.c [new file with mode: 0644]
src/regression/struct1.c [new file with mode: 0644]
src/regression/while.c [new file with mode: 0644]

index 57659bd4bfebf525389c006573db438cfb7bde3f..fa03b64a543f75f181c83a929a2d0e78134290ff 100644 (file)
@@ -65,14 +65,14 @@ static char *zero = "#0x00";
 static char *one  = "#0x01";
 static char *spname = "sp";
 
-char *fReturnpic14[] = {"dpl","dph","b","a" };
+char *fReturnpic14[] = {"fsr","dph","b","a" };
 //char *fReturn390[] = {"dpl","dph","dpx", "b","a" };
 static unsigned fReturnSize = 4; /* shared with ralloc.c */
 static char **fReturn = fReturnpic14;
 
 static char *accUse[] = {"a","b"};
 
-static short rbank = -1;
+//static short rbank = -1;
 
 static struct {
     short r0Pushed;
@@ -95,6 +95,9 @@ static void saverbank (int, iCode *,bool);
 #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) emitcode(";XXX mov","a,%s  %s,%d",x,__FILE__,__LINE__);
 #define CLRC    emitcode(";XXX clr","c %s,%d",__FILE__,__LINE__);
 
+#define BIT_NUMBER(x) (x & 7)
+#define BIT_REGISTER(x) (x>>3)
+
 static lineNode *lineHead = NULL;
 static lineNode *lineCurr = NULL;
 
@@ -113,6 +116,15 @@ static unsigned char   SRMask[] = {0xFF, 0x7F, 0x3F, 0x1F, 0x0F,
 static int labelOffset=0;
 static int debug_verbose=1;
 
+
+/*-----------------------------------------------------------------*/
+/* Macros for emitting instructions                                */
+/*-----------------------------------------------------------------*/
+#define emitSKPC    emitcode("btfss","status,c")
+#define emitSKPNC   emitcode("btfsc","status,c")
+#define emitSKPZ    emitcode("btfss","status,z")
+#define emitSKPNZ   emitcode("btfsc","status,z")
+
 /*-----------------------------------------------------------------*/
 /*  my_powof2(n) - If `n' is an integaer power of 2, then the      */
 /*                 exponent of 2 is returned, otherwise -1 is      */
@@ -330,6 +342,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
     asmop *aop;
     memmap *space= SPEC_OCLS(sym->etype);
 
+    DEBUGemitcode("; ***","%s %d",__FUNCTION__,__LINE__);
     /* if already has one */
     if (sym->aop)
         return sym->aop;
@@ -376,6 +389,8 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
          * far data space.
          */
          
+      //DEBUGemitcode(";","%d",__LINE__);
+
         if ( _G.accInUse )
                emitcode("push","acc");
 
@@ -399,11 +414,13 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
        return aop;
     }
 
+    //DEBUGemitcode(";","%d",__LINE__);
     /* if in bit space */
     if (IN_BITSPACE(space)) {
         sym->aop = aop = newAsmop (AOP_CRY);
         aop->aopu.aop_dir = sym->rname ;
         aop->size = getSize(sym->type);
+       DEBUGemitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
         return aop;
     }
     /* if it is in direct space */
@@ -411,6 +428,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
         sym->aop = aop = newAsmop (AOP_DIR);
         aop->aopu.aop_dir = sym->rname ;
         aop->size = getSize(sym->type);
+       DEBUGemitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
         return aop;
     }
 
@@ -423,12 +441,14 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
         return aop;
     }
 
+
     /* only remaining is far space */
     /* in which case DPTR gets the address */
     sym->aop = aop = newAsmop(AOP_DPTR);
     emitcode ("mov","dptr,#%s", sym->rname);
     aop->size = getSize(sym->type);
 
+    DEBUGemitcode(";","%d size = %d",__LINE__,aop->size);
     /* if it is in code space */
     if (IN_CODESPACE(space))
         aop->code = 1;
@@ -444,7 +464,7 @@ static asmop *aopForRemat (symbol *sym)
     iCode *ic = sym->rematiCode;
     asmop *aop = newAsmop(AOP_IMMD);
     int val = 0;
-    emitcode(";","%s",__FUNCTION__);
+    DEBUGemitcode(";","%s %d",__FUNCTION__,__LINE__);
     for (;;) {
        if (ic->op == '+')
            val += operandLitValue(IC_RIGHT(ic));
@@ -464,6 +484,7 @@ static asmop *aopForRemat (symbol *sym)
     else
        strcpy(buffer,OP_SYMBOL(IC_LEFT(ic))->rname);
 
+    //DEBUGemitcode(";","%s",buffer);
     ALLOC_ATOMIC(aop->aopu.aop_immd,strlen(buffer)+1);
     strcpy(aop->aopu.aop_immd,buffer);    
     return aop;        
@@ -586,8 +607,10 @@ static void aopOp (operand *op, iCode *ic, bool result)
     if (!op)
         return ;
 
+    DEBUGemitcode(";","%d",__LINE__);
     /* if this a literal */
     if (IS_OP_LITERAL(op)) {
+      DEBUGemitcode(";","%d",__LINE__);
         op->aop = aop = newAsmop(AOP_LIT);
         aop->aopu.aop_lit = op->operand.valOperand;
         aop->size = getSize(operandType(op));
@@ -600,12 +623,14 @@ static void aopOp (operand *op, iCode *ic, bool result)
 
     /* if the underlying symbol has a aop */
     if (IS_SYMOP(op) && OP_SYMBOL(op)->aop) {
+      DEBUGemitcode(";","%d",__LINE__);
         op->aop = OP_SYMBOL(op)->aop;
         return;
     }
 
     /* if this is a true symbol */
     if (IS_TRUE_SYMOP(op)) {    
+      DEBUGemitcode(";","%d",__LINE__);
         op->aop = aopForSym(ic,OP_SYMBOL(op),result);
         return ;
     }
@@ -623,6 +648,7 @@ static void aopOp (operand *op, iCode *ic, bool result)
 
     /* if the type is a conditional */
     if (sym->regType == REG_CND) {
+      DEBUGemitcode(";","%d",__LINE__);
         aop = op->aop = sym->aop = newAsmop(AOP_CRY);
         aop->size = 0;
         return;
@@ -633,11 +659,13 @@ static void aopOp (operand *op, iCode *ic, bool result)
     b) has a spill location */
     if (sym->isspilt || sym->nRegs == 0) {
 
+      DEBUGemitcode(";","%d",__LINE__);
         /* rematerialize it NOW */
         if (sym->remat) {
             sym->aop = op->aop = aop =
                                       aopForRemat (sym);
             aop->size = getSize(sym->type);
+           DEBUGemitcode(";","%d",__LINE__);
             return;
         }
 
@@ -647,6 +675,7 @@ static void aopOp (operand *op, iCode *ic, bool result)
             aop->size = getSize(sym->type);
             for ( i = 0 ; i < 2 ; i++ )
                 aop->aopu.aop_str[i] = accUse[i];
+           DEBUGemitcode(";","%d",__LINE__);
             return;  
        }
 
@@ -656,10 +685,12 @@ static void aopOp (operand *op, iCode *ic, bool result)
             aop->size = getSize(sym->type);
             for ( i = 0 ; i < fReturnSize ; i++ )
              aop->aopu.aop_str[i] = fReturn[i];
+           DEBUGemitcode(";","%d",__LINE__);
             return;
         }
 
         /* else spill location  */
+       DEBUGemitcode(";","%s %d %s",__FUNCTION__,__LINE__,sym->usl.spillLoc->rname);
         sym->aop = op->aop = aop = 
                                   aopForSym(ic,sym->usl.spillLoc,result);
         aop->size = getSize(sym->type);
@@ -855,14 +886,14 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
     case AOP_IMMD:
       DEBUGemitcode(";","%d",__LINE__);
        if (bit16) 
-           sprintf (s,"#%s",aop->aopu.aop_immd);
+           sprintf (s,"%s",aop->aopu.aop_immd);
        else
            if (offset) 
-               sprintf(s,"#(%s >> %d)",
+               sprintf(s,"(%s >> %d)",
                        aop->aopu.aop_immd,
                        offset*8);
            else
-               sprintf(s,"#%s",
+               sprintf(s,"%s",
                        aop->aopu.aop_immd);
        ALLOC_ATOMIC(rs,strlen(s)+1);
        strcpy(rs,s);   
@@ -892,7 +923,7 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
       //emitcode("mov","c,%s",aop->aopu.aop_dir);
       //emitcode("rlc","a") ;
       //return (dname ? "acc" : "a");
-      return "bit";
+      return aop->aopu.aop_dir;
        
     case AOP_ACC:
         DEBUGemitcode(";Warning -pic port ignoring get(AOP_ACC)","%d",__LINE__);
@@ -947,8 +978,9 @@ static void aopPut (asmop *aop, char *s, int offset)
            sprintf(d,"%s",aop->aopu.aop_dir);
        
        if (strcmp(d,s)) {
-           emitcode("movf","%s,w ; %d",s,__LINE__);
-           emitcode("movwf","%s",d);
+         DEBUGemitcode(";","%d",__LINE__);
+         emitcode("movf","%s,w",s);
+         emitcode("movwf","%s",d);
        }
        break;
        
@@ -1199,6 +1231,7 @@ static void genNotFloat (operand *op, operand *res)
         aopPut(res->aop,zero,offset++);
 }
 
+#if 0
 /*-----------------------------------------------------------------*/
 /* opIsGptr: returns non-zero if the passed operand is            */   
 /* a generic pointer type.                                        */
@@ -1214,14 +1247,22 @@ static int opIsGptr(operand *op)
     }
     return 0;        
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* getDataSize - get the operand data size                         */
 /*-----------------------------------------------------------------*/
 static int getDataSize(operand *op)
 {
-    int size;
     DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+
+    return AOP_SIZE(op);
+
+    // tsd- in the pic port, the genptr size is 1, so this code here
+    // fails. ( in the 8051 port, the size was 4).
+#if 0
+    int size;
     size = AOP_SIZE(op);
     if (size == GPTRSIZE)
     {
@@ -1232,9 +1273,11 @@ static int getDataSize(operand *op)
              * should ignore the high byte (pointer type).
              */
             size--;
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
         }
     }
     return size;
+#endif
 }
 
 /*-----------------------------------------------------------------*/
@@ -1848,15 +1891,22 @@ static void genCall (iCode *ic)
        for (sic = setFirstItem(_G.sendSet) ; sic ; 
             sic = setNextItem(_G.sendSet)) {
            int size, offset = 0;
+
            aopOp(IC_LEFT(sic),sic,FALSE);
            size = AOP_SIZE(IC_LEFT(sic));
            while (size--) {
                char *l = aopGet(AOP(IC_LEFT(sic)),offset,
                                FALSE,FALSE);
-               if (strcmp(l,fReturn[offset]))
-                   emitcode("mov","%s,%s",
-                            fReturn[offset],
-                            l);
+               DEBUGemitcode(";","%d",__LINE__);
+
+               if (strcmp(l,fReturn[offset])) {
+
+                 if ( (AOP(IC_LEFT(sic))->type) == AOP_IMMD)
+                   emitcode("movlw","%s",l);
+                 else
+                   emitcode("movf","%s,w",l);
+                 emitcode("movwf","%s",fReturn[offset]);
+               }
                offset++;
            }
            freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
@@ -2411,8 +2461,13 @@ static void genRet (iCode *ic)
            } else {
                    l = aopGet(AOP(IC_LEFT(ic)),offset,
                               FALSE,FALSE);
-                   if (strcmp(fReturn[offset],l))
-                           emitcode("mov","%s,%s",fReturn[offset++],l);
+                   if (strcmp(fReturn[offset],l)) {
+                     if ( (AOP(IC_LEFT(ic))->type) == AOP_IMMD)
+                       emitcode("movlw","%s",l);
+                     else
+                       emitcode("movf","%s,w",l);
+                     emitcode("movwf","%s",fReturn[offset++]);
+                   }
            }
     }    
 
@@ -2433,7 +2488,7 @@ static void genRet (iCode *ic)
     if (!(ic->next && ic->next->op == LABEL &&
          IC_LABEL(ic->next) == returnLabel))
        
-       emitcode("goto","_%05d_DS_",(returnLabel->key+100));
+       emitcode("goto","_%05d_DS_",returnLabel->key+100 + labelOffset);
     
 }
 
@@ -2456,7 +2511,7 @@ static void genLabel (iCode *ic)
 //tsd
 static void genGoto (iCode *ic)
 {
-    emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100));
+    emitcode ("goto","_%05d_DS_",(IC_LABEL(ic)->key+100)+labelOffset);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2465,6 +2520,7 @@ static void genGoto (iCode *ic)
 /* between that label and given ic.                               */
 /* Returns zero if label not found.                               */
 /*-----------------------------------------------------------------*/
+#if 0
 static int findLabelBackwards(iCode *ic, int key)
 {
     int count = 0;
@@ -2484,7 +2540,7 @@ static int findLabelBackwards(iCode *ic, int key)
     
     return 0;
 }
-
+#endif
 /*-----------------------------------------------------------------*/
 /* genPlusIncr :- does addition with increment if possible         */
 /*-----------------------------------------------------------------*/
@@ -2492,14 +2548,20 @@ static bool genPlusIncr (iCode *ic)
 {
     unsigned int icount ;
     unsigned int size = getDataSize(IC_RESULT(ic));
-    
+
     DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+    DEBUGemitcode ("; ","result %d, left %d, right %d",
+                  AOP_TYPE(IC_RESULT(ic)),
+                  AOP_TYPE(IC_LEFT(ic)),
+                  AOP_TYPE(IC_RIGHT(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)
         return FALSE ;
     
+    DEBUGemitcode ("; ","%s  %d",__FUNCTION__,__LINE__);
     /* if the literal value of the right hand side
        is greater than 1 then it is faster to add */
     if ((icount =  floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
@@ -2514,13 +2576,36 @@ static bool genPlusIncr (iCode *ic)
       emitcode("incf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
 
       while(--size) {
-       emitcode("skpnz","");
+       emitSKPNZ;
        emitcode(" incf","%s,f",aopGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
       }
 
       return TRUE;
     }
     
+    DEBUGemitcode ("; ","%s  %d",__FUNCTION__,__LINE__);
+    /* if left is in accumulator  - probably a bit operation*/
+    if( strcmp(aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE),"a")  &&
+       (AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) ) {
+      
+      emitcode("bcf","(%s >> 3), (%s & 7)",
+              AOP(IC_RESULT(ic))->aopu.aop_dir,
+              AOP(IC_RESULT(ic))->aopu.aop_dir);
+      if(icount)
+       emitcode("xorlw","1");
+      else
+       emitcode("andlw","1");
+
+      emitSKPZ;
+      emitcode("bsf","(%s >> 3), (%s & 7)",
+              AOP(IC_RESULT(ic))->aopu.aop_dir,
+              AOP(IC_RESULT(ic))->aopu.aop_dir);
+
+      return TRUE;
+    }
+
+
+
     /* if the sizes are greater than 1 then we cannot */
     if (AOP_SIZE(IC_RESULT(ic)) > 1 ||
         AOP_SIZE(IC_LEFT(ic)) > 1   )
@@ -2536,6 +2621,9 @@ static bool genPlusIncr (iCode *ic)
       return TRUE ;
     }
     
+    DEBUGemitcode ("; ","couldn't increment result-%s  left-%s",
+                  aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
+                  aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
     return FALSE ;
 }
 
@@ -2572,6 +2660,9 @@ static void genPlusBits (iCode *ic)
       the carry (C in the status register).
       It won't work if the 'Z' bit is a source or destination.
     */
+
+    /* If the result is stored in the accumulator (w) */
+    if(strcmp(aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),"a") == 0 ) {
        emitcode("movlw","(1 << (%s & 7))",
                 AOP(IC_RESULT(ic))->aopu.aop_dir,
                 AOP(IC_RESULT(ic))->aopu.aop_dir);
@@ -2581,13 +2672,26 @@ static void genPlusBits (iCode *ic)
        emitcode("btfsc","(%s >> 3), (%s & 7)",
                 AOP(IC_RIGHT(ic))->aopu.aop_dir,
                 AOP(IC_RIGHT(ic))->aopu.aop_dir);
-       emitcode("xorwf","%s,f",
+       emitcode("xorwf","(%s >>3),f",
                 AOP(IC_RESULT(ic))->aopu.aop_dir);
        emitcode("btfsc","(%s >> 3), (%s & 7)",
                 AOP(IC_LEFT(ic))->aopu.aop_dir,
                 AOP(IC_LEFT(ic))->aopu.aop_dir);
-       emitcode("xorwf","%s,f",
+       emitcode("xorwf","(%s>>3),f",
                 AOP(IC_RESULT(ic))->aopu.aop_dir);
+    } else { 
+
+      emitcode("clrw","");
+      emitcode("btfsc","(%s >> 3), (%s & 7)",
+                AOP(IC_RIGHT(ic))->aopu.aop_dir,
+                AOP(IC_RIGHT(ic))->aopu.aop_dir);
+      emitcode("xorlw","1");
+      emitcode("btfsc","(%s >> 3), (%s & 7)",
+              AOP(IC_LEFT(ic))->aopu.aop_dir,
+              AOP(IC_LEFT(ic))->aopu.aop_dir);
+      emitcode("xorlw","1");
+    }
+
 }
 
 #if 0
@@ -2622,7 +2726,7 @@ static void adjustArithmeticResult(iCode *ic)
        aopPut(AOP(IC_RESULT(ic)),buffer,2);
     }
 }
-#else
+//#else
 /* This is the pure and virtuous version of this code.
  * I'm pretty certain it's right, but not enough to toss the old 
  * code just yet...
@@ -2676,16 +2780,14 @@ static void genPlus (iCode *ic)
     /* if literal, literal on the right or
        if left requires ACC or right is already
        in ACC */
-    if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
-       (AOP_NEEDSACC(IC_LEFT(ic))) ||
-       AOP_TYPE(IC_RIGHT(ic)) == AOP_ACC ){
+
+    if (AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) {
         operand *t = IC_RIGHT(ic);
         IC_RIGHT(ic) = IC_LEFT(ic);
         IC_LEFT(ic) = t;
     }
 
-    /* if both left & right are in bit
-    space */
+    /* 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);
@@ -2695,12 +2797,17 @@ static void genPlus (iCode *ic)
     /* if left in bit space & right literal */
     if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
         AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT) {
-        emitcode("mov","c,%s  ;%d",AOP(IC_LEFT(ic))->aopu.aop_dir,__LINE__);
         /* if result in bit space */
         if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY){
-            if((unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit) != 0L)
-                emitcode("cpl","c   ;%d",__LINE__);
-            outBitC(IC_RESULT(ic));
+         if((unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit) != 0L) {
+           emitcode("movlw","(1 << (%s & 7)) ;%d",AOP(IC_RESULT(ic))->aopu.aop_dir,__LINE__);
+           if (!sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
+             emitcode("btfsc","(%s >> 3), (%s & 7)",
+                      AOP(IC_LEFT(ic))->aopu.aop_dir,
+                      AOP(IC_LEFT(ic))->aopu.aop_dir);
+
+           emitcode("xorwf","(%s>>3),f",AOP(IC_RESULT(ic))->aopu.aop_dir);
+         }
         } else {
             size = getDataSize(IC_RESULT(ic));
             while (size--) {
@@ -2721,32 +2828,66 @@ static void genPlus (iCode *ic)
 
     if(AOP(IC_RIGHT(ic))->type == AOP_LIT) {
       /* Add a literal to something else */
-
+      bool know_W=0;
       unsigned lit = floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
+      unsigned l1=0;
 
-      /* add the first byte: */
-      emitcode("movlw","0x%x", lit & 0xff);
-      emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-
-      offset = 1;
-      size--;
-
+      offset = 0;
+      DEBUGemitcode(";","adding lit to something. size %d",size);
       while(size--){
 
-       emitcode("rlf","_known_zero,w");
-       emitcode(" addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+      DEBUGemitcode(";","size %d",size);
 
-       lit >>= 8;
-       if(lit & 0xff) {
-         emitcode("movlw","0x%x", lit & 0xff);
-         emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
-         
+       switch (lit & 0xff) {
+       case 0:
+         break;
+       case 1:
+         if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
+           emitcode("incf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+         else {
+           know_W = 0;
+           emitcode("incf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+           emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
+         }
+         break;
+       case 0xff:
+         if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
+           emitcode("decf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+         else {
+           know_W = 0;
+           emitcode("decf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+           emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
+         }
+         break;
+       default:
+         if( !know_W || ( (lit&0xff) != l1)  ) {
+           know_W = 1;
+           emitcode("movlw","0x%x", lit&0xff);
+         }
+         if(sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))))
+           emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+         else {
+           know_W = 0;
+           emitcode("addwf","%s,w", aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+           emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
+           if(size) {
+             emitSKPNC;
+             emitcode("incf","%s,f", aopGet(AOP(IC_LEFT(ic)),offset+1,FALSE,FALSE));
+           }
+         }
        }
+
+       l1 = lit & 0xff;
+       lit >>= 8;
        offset++;
       }
 
     } else if(AOP_TYPE(IC_RIGHT(ic)) == AOP_CRY) {
 
+      emitcode(";bitadd","right is bit: %s",aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+      emitcode(";bitadd","left is bit: %s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+      emitcode(";bitadd","result is bit: %s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+
       /* here we are adding a bit to a char or int */
       if(size == 1) {
        if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
@@ -2757,12 +2898,34 @@ static void genPlus (iCode *ic)
          emitcode(" incf","%s,f", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
        } else {
 
-         emitcode("movf","%s,w", 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,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-         emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+         if(AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
+           emitcode("btfsc","(%s >> 3), (%s & 7)",
+                    AOP(IC_RIGHT(ic))->aopu.aop_dir,
+                    AOP(IC_RIGHT(ic))->aopu.aop_dir);
+           emitcode(" xorlw","1");
+         } else {
+           emitcode("movf","%s,w", 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,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+         }
+         
+         if(AOP_TYPE(IC_RESULT(ic)) != AOP_ACC) {
+           
+           if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
+             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
+               emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+         }
        }
 
       } else {
@@ -2788,7 +2951,7 @@ static void genPlus (iCode *ic)
        }
 
        while(--size){
-         emitcode("skpz","");
+         emitSKPZ;
          emitcode(" incf","%s,f", aopGet(AOP(IC_RIGHT(ic)),offset++,FALSE,FALSE));
        }
 
@@ -2800,17 +2963,26 @@ static void genPlus (iCode *ic)
        emitcode("addwf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
        emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
       } else {
-       emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+       //if ( (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) || (AOP_TYPE(IC_RESULT(ic)) == AOP_ACC) )
+       if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
+         emitcode("addwf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
+         if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
+           emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+       } else {
 
-       if ( (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) || (AOP_TYPE(IC_RESULT(ic)) == AOP_ACC) )
-         emitcode("addwf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-       else {
+       emitcode("movf","%s,w", aopGet(AOP(IC_RIGHT(ic)),0,FALSE,FALSE));
 
          if (sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) )
-           emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+             emitcode("addwf","%s,f", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
          else {
-           emitcode("addwf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-           emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+           emitcode(";ic_left type","%d",AOP_TYPE(IC_LEFT(ic)));
+           if(AOP_TYPE(IC_LEFT(ic)) == AOP_IMMD) {
+             emitcode("addlw","%s", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+           } else {
+             emitcode("addwf","%s,w", aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+             if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
+               emitcode("movwf","%s", aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+           }
          }
        }
       }
@@ -2824,7 +2996,7 @@ static void genPlus (iCode *ic)
          emitcode("movwf","%s",  aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
        }
        emitcode("movf","%s,w",  aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
-       emitcode("skpnc","");
+       emitSKPNC;
        emitcode("incfsz","%s,w",aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
        emitcode("addwf","%s,f", aopGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
        
@@ -2841,7 +3013,7 @@ static void genPlus (iCode *ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* genMinusDec :- does subtraction with deccrement if possible     */
+/* genMinusDec :- does subtraction with decrement if possible     */
 /*-----------------------------------------------------------------*/
 static bool genMinusDec (iCode *ic)
 {
@@ -2855,6 +3027,8 @@ static bool genMinusDec (iCode *ic)
     if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)
         return FALSE ;
 
+    DEBUGemitcode ("; lit val","%d",(unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit));
+
     /* if the literal value of the right hand side
     is greater than 4 then it is not worth it */
     if ((icount = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit)) > 2)
@@ -2874,13 +3048,14 @@ static bool genMinusDec (iCode *ic)
        emitcode("movlw","0xff");
        emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
 
-       emitcode("skpnc","");
+       emitSKPNC;
        emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB16,FALSE,FALSE));
-       emitcode("skpnc","");
+       emitSKPNC;
        emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB24,FALSE,FALSE));
 
        if(size > 3) {
          emitcode("skpnc","");
+         emitSKPNC;
          emitcode("addwf","%s,f",aopGet(AOP(IC_RESULT(ic)),MSB32,FALSE,FALSE));
        }
 
@@ -2906,6 +3081,15 @@ static bool genMinusDec (iCode *ic)
         return TRUE ;
     }
 
+    DEBUGemitcode ("; returning"," result=%s, left=%s",
+                  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));
+      return TRUE;
+    }
+
     return FALSE ;
 }
 
@@ -3018,7 +3202,7 @@ static void genMinus (iCode *ic)
 
       while(size--){
        emitcode("movf","%s,w",  aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
-       emitcode("skpnc","");
+       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));
        
@@ -3460,9 +3644,6 @@ release :
 /*-----------------------------------------------------------------*/
 static void genIfxJump (iCode *ic, char *jval)
 {
-    symbol *jlbl ;
-    symbol *tlbl = newiTempLabel(NULL);
-    char *inst;
 
     DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* if true label then we jump if condition
@@ -3470,11 +3651,11 @@ static void genIfxJump (iCode *ic, char *jval)
     if ( IC_TRUE(ic) ) {
 
        if(strcmp(jval,"a") == 0)
-         emitcode("skpz","");
+         emitSKPZ;
        else if (strcmp(jval,"c") == 0)
-         emitcode("skpc","");
+         emitSKPC;
        else
-         emitcode("skpnc","");
+         emitcode("btfsc","(%s >> 3),(%s & 7)",jval,jval);
 
        emitcode(" goto","_%05d_DS_",IC_TRUE(ic)->key+100 + labelOffset);
 
@@ -3482,15 +3663,14 @@ static void genIfxJump (iCode *ic, char *jval)
     else {
         /* false label is present */
        if(strcmp(jval,"a") == 0)
-         emitcode("skpnz","");
+         emitSKPNZ;
        else if (strcmp(jval,"c") == 0)
-         emitcode("skpnc","");
+         emitSKPNC;
        else
-         emitcode("skpc","");
+         emitcode("btfss","(%s >> 3),(%s & 7)",jval,jval);
 
        emitcode(" goto","_%05d_DS_",IC_FALSE(ic)->key+100 + labelOffset);
 
-
     }
 
 
@@ -3509,11 +3689,11 @@ static void genSkip(iCode *ifx,int status_bit)
   if ( IC_TRUE(ifx) ) {
     switch(status_bit) {
     case 'z':
-      emitcode("skpnz","");
+      emitSKPNZ;
       break;
 
     case 'c':
-      emitcode("skpnc","");
+      emitSKPNC;
       break;
 
     case 'd':
@@ -3529,11 +3709,11 @@ static void genSkip(iCode *ifx,int status_bit)
     switch(status_bit) {
 
     case 'z':
-      emitcode("skpz","");
+      emitSKPZ;
       break;
 
     case 'c':
-      emitcode("skpc","");
+      emitSKPC;
       break;
 
     case 'd':
@@ -3555,9 +3735,9 @@ static void genSkipc(iCode *ifx, int condition)
     return;
 
   if(condition)
-    emitcode("skpnc","");
+    emitSKPNC;
   else
-    emitcode("skpc","");
+    emitSKPC;
 
   if ( IC_TRUE(ifx) )
     emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
@@ -3575,9 +3755,9 @@ static void genSkipz(iCode *ifx, int condition)
     return;
 
   if(condition)
-    emitcode("skpnz","");
+    emitSKPNZ;
   else
-    emitcode("skpz","");
+    emitSKPZ;
 
   if ( IC_TRUE(ifx) )
     emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
@@ -3686,7 +3866,7 @@ static void genCmp (operand *left,operand *right,
          emitcode("subb","a,%s",aopGet(AOP(right),offset++,FALSE,FALSE));
        */
        emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
-       emitcode("skpc","");
+       emitSKPC;
        emitcode("incfsz","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
        emitcode("subwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
        offset++;
@@ -3801,7 +3981,7 @@ static void gencjneshort(operand *left, operand *right, symbol *lbl)
          } else
            emitcode("movf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
 
-         emitcode("skpnz","");
+         emitSKPNZ;
          emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
          offset++;
          lit >>= 8;
@@ -3823,7 +4003,7 @@ static void gencjneshort(operand *left, operand *right, symbol *lbl)
          } else
            emitcode("movf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
 
-         emitcode("skpz","");
+         emitSKPZ;
          emitcode("goto","_%05d_DS_",lbl->key+100+labelOffset);
          offset++;
 /*
@@ -3933,7 +4113,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
                 emitcode("jc","%05d_DS_",tlbl->key+100);
                 emitcode("ljmp","%05d_DS_",IC_FALSE(ifx)->key+100);
             }
-            emitcode("","%05d_DS_:",tlbl->key+100);                
+            emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
         } else {
 
          /* They're not both bit variables. Is the right a literal? */
@@ -3996,7 +4176,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
                    emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
                    emitcode("xorlw","0x%x",l);
                    emitcode("movlw","0x%x",h);
-                   emitcode("skpz","");
+                   emitSKPZ;
                    emitcode("xorwf","%s,w",aopGet(AOP(left),offset+1,FALSE,FALSE));
                    optimized++;
                    genSkip(ifx,'z');
@@ -4017,7 +4197,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
              case 1:
                if ( IC_TRUE(ifx) ) {
                  emitcode("decf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 emitcode("skpnz","");
+                 emitSKPNZ;
                  emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
                } else {
                  emitcode("decfsz","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
@@ -4027,7 +4207,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
              case 0xff:
                if ( IC_TRUE(ifx) ) {
                  emitcode("incf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
-                 emitcode("skpnz","");
+                 emitSKPNZ;
                  emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
                } else {
                  emitcode("incfsz","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
@@ -4048,6 +4228,35 @@ static void genCmpEq (iCode *ic, iCode *ifx)
              lit >>= 8;
            }
 
+         } else if(AOP_TYPE(right) == AOP_CRY ) {
+           /* we know the left is not a bit, but that the right is */
+           emitcode("movf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
+           if ( IC_TRUE(ifx) )
+             emitcode("btfsc","(%s >> 3), (%s & 7)",
+                      AOP(right)->aopu.aop_dir,
+                      AOP(right)->aopu.aop_dir);
+           else
+             emitcode("btfss","(%s >> 3), (%s & 7)",
+                      AOP(right)->aopu.aop_dir,
+                      AOP(right)->aopu.aop_dir);
+
+           emitcode("xorlw","1");
+
+           /* if the two are equal, then W will be 0 and the Z bit is set
+            * we could test Z now, or go ahead and check the high order bytes if
+            * the variable we're comparing is larger than a byte. */
+
+           while(--size)
+             emitcode("iorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
+
+           if ( IC_TRUE(ifx) ) {
+             emitSKPNZ;
+             emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+           } else {
+             emitSKPZ;
+             emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
+           }
+
          } else {
            /* They're both variables that are larger than bits */
            int s = size;
@@ -4061,20 +4270,20 @@ static void genCmpEq (iCode *ic, iCode *ifx)
 
              if ( IC_TRUE(ifx) ) {
                if(size) {
-                 emitcode("skpz","");
-                 emitcode(" goto","_%05d_DS_",tlbl->key+100);
+                 emitSKPZ;
+                 emitcode(" goto","_%05d_DS_",tlbl->key+100+labelOffset);
                } else {
-                 emitcode("skpnz","");
+                 emitSKPNZ;
                  emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
                }
              } else {
-               emitcode("skpz","");
+               emitSKPZ;
                emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
              }
              offset++;
            }
            if(s>1 && IC_TRUE(ifx))
-             emitcode("","_%05d_DS_:",tlbl->key+100);                
+             emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);                
          }
         }
         /* mark the icode as generated */
@@ -4232,10 +4441,10 @@ static void genOrOp (iCode *ic)
     } else {
         tlbl = newiTempLabel(NULL);
         toBoolean(left);
-       emitcode("skpz","");
-        emitcode("goto","%05d_DS_",tlbl->key+100);
+       emitSKPZ;
+        emitcode("goto","%05d_DS_",tlbl->key+100+labelOffset);
         toBoolean(right);
-        emitcode("","%05d_DS_:",tlbl->key+100);
+        emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
 
         outBitAcc(result);
     }
@@ -6505,14 +6714,16 @@ static void genDataPointerGet (operand *left,
     aopOp(result,ic,TRUE);
 
     DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
     /* get the string representation of the name */
     l = aopGet(AOP(left),0,FALSE,TRUE);
     size = AOP_SIZE(result);
+    // tsd, was l+1 - the underline `_' prefix was being stripped
     while (size--) {
        if (offset)
-           sprintf(buffer,"(%s + %d)",l+1,offset);
+           sprintf(buffer,"(%s + %d)",l,offset);
        else
-           sprintf(buffer,"%s",l+1);
+           sprintf(buffer,"%s",l);
        aopPut(AOP(result),buffer,offset++);
     }
 
@@ -6819,6 +7030,10 @@ static void genGenPointerGet (operand *left,
            emitcode("mov","b,#%d",pointerCode(retype));
        }
         else { /* we need to get it byte by byte */
+         
+         emitcode("movf","%s,w",aopGet(AOP(left),0,FALSE,FALSE));
+         emitcode("movwf","FSR");
+         /*
             emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
             emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
             if (options.model == MODEL_FLAT24)
@@ -6830,6 +7045,7 @@ static void genGenPointerGet (operand *left,
             {
                emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE));
             }
+         */
         }
     }
     /* so dptr know contains the address */
@@ -6844,10 +7060,13 @@ static void genGenPointerGet (operand *left,
         offset = 0 ;
 
         while (size--) {
-            emitcode("lcall","__gptrget");
-            aopPut(AOP(result),"a",offset++);
+         //emitcode("lcall","__gptrget");
+            emitcode("movf","indf,w");
+            //aopPut(AOP(result),"a",offset++);
+           emitcode("movwf","%s",
+                    aopGet(AOP(result),offset++,FALSE,FALSE));
             if (size)
-                emitcode("inc","dptr");
+                emitcode("incf","fsr,f");
         }
     }
 
@@ -6992,7 +7211,7 @@ static void genPackBits (sym_link    *etype ,
             break;
 
         case GPOINTER:
-            emitcode("lcall","__gptrput");
+            DEBUGemitcode(";lcall","__gptrput");
             break;
     }
 
@@ -7028,7 +7247,7 @@ static void genPackBits (sym_link    *etype ,
 
             case GPOINTER:
                 MOVA(l);
-                emitcode("lcall","__gptrput");
+                DEBUGemitcode(";lcall","__gptrput");
                 break;  
         }   
         emitcode ("inc","%s",rname);
@@ -7076,7 +7295,7 @@ static void genPackBits (sym_link    *etype ,
        break;
        
     case GPOINTER:
-       emitcode("lcall","__gptrput");
+       DEBUGemitcode(";lcall","__gptrput");
        break;                  
     }
 }
@@ -7095,13 +7314,27 @@ static void genDataPointerSet(operand *right,
     
     l = aopGet(AOP(result),0,FALSE,TRUE);
     size = AOP_SIZE(right);
+    // tsd, was l+1 - the underline `_' prefix was being stripped
     while (size--) {
        if (offset)
-           sprintf(buffer,"(%s + %d)",l+1,offset);
+           sprintf(buffer,"(%s + %d)",l,offset);
        else
-           sprintf(buffer,"%s",l+1);
-       emitcode("mov","%s,%s",buffer,
-                aopGet(AOP(right),offset++,FALSE,FALSE));
+           sprintf(buffer,"%s",l);
+
+       if (AOP_TYPE(right) == AOP_LIT) {
+         unsigned int lit = floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
+         lit = lit >> (8*offset);
+         if(lit) {
+           emitcode("movlw","%s",lit);
+           emitcode("movwf","%s",buffer);
+         } else 
+           emitcode("clrf","%s",buffer);
+       }else {
+         emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
+         emitcode("movwf","%s",buffer);
+       }
+
+       offset++;
     }
 
     freeAsmop(right,NULL,ic,TRUE);
@@ -7116,10 +7349,10 @@ static void genNearPointerSet (operand *right,
                                iCode *ic)
 {
     asmop *aop = NULL;
-    regs *preg = NULL ;
-    char *rname , *l;
+    char *l;
     sym_link *retype;
     sym_link *ptype = operandType(result);
+
     
     DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     retype= getSpec(operandType(right));
@@ -7135,43 +7368,69 @@ static void genNearPointerSet (operand *right,
        return;
     }
 
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
     /* if the value is already in a pointer register
     then don't need anything more */
     if (!AOP_INPREG(AOP(result))) {
         /* otherwise get a free pointer register */
-        aop = newAsmop(0);
-        preg = getFreePtr(ic,&aop,FALSE);
-        emitcode("mov","%s,%s",
-                 preg->name,
-                 aopGet(AOP(result),0,FALSE,TRUE));
-        rname = preg->name ;
-    } else
-        rname = aopGet(AOP(result),0,FALSE,FALSE);
+        //aop = newAsmop(0);
+        //preg = getFreePtr(ic,&aop,FALSE);
+       DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+       //emitcode("mov","%s,%s",
+        //         preg->name,
+        //         aopGet(AOP(result),0,FALSE,TRUE));
+        //rname = preg->name ;
+       emitcode("movwf","fsr");
+    }// else
+    //   rname = aopGet(AOP(result),0,FALSE,FALSE);
 
     freeAsmop(result,NULL,ic,TRUE);
     aopOp (right,ic,FALSE);
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
     /* if bitfield then unpack the bits */
-    if (IS_BITVAR(retype)) 
-        genPackBits (retype,right,rname,POINTER);
+    if (IS_BITVAR(retype)) {
+      werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
+            "The programmer is obviously confused");
+      //genPackBits (retype,right,rname,POINTER);
+      exit(1);
+    }
     else {
         /* we have can just get the values */
         int size = AOP_SIZE(right);
         int offset = 0 ;    
 
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
         while (size--) {
             l = aopGet(AOP(right),offset,FALSE,TRUE);
             if (*l == '@' ) {
-                MOVA(l);
-                emitcode("mov","@%s,a",rname);
-            } else
-                emitcode("mov","@%s,%s",rname,l);
+             //MOVA(l);
+             //emitcode("mov","@%s,a",rname);
+             emitcode("movf","indf,w ;1");
+            } else {
+
+             if (AOP_TYPE(right) == AOP_LIT) {
+               unsigned int lit = floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit);
+               if(lit) {
+                 emitcode("movlw","%s",l);
+                 emitcode("movwf","indf ;2");
+               } else 
+                 emitcode("clrf","indf");
+             }else {
+               emitcode("movf","%s,w",l);
+               emitcode("movwf","indf ;2");
+             }
+           //emitcode("mov","@%s,%s",rname,l);
+           }
             if (size)
-                emitcode("inc","%s",rname);
+             emitcode("incf","fsr,f ;3");
+           //emitcode("inc","%s",rname);
             offset++;
         }
     }
 
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* now some housekeeping stuff */
     if (aop) {
         /* we had to allocate for this iCode */
@@ -7182,16 +7441,19 @@ static void genNearPointerSet (operand *right,
         if size > 0 && this could be used again
         we have to point it back to where it 
         belongs */
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
         if (AOP_SIZE(right) > 1 &&
             !OP_SYMBOL(result)->remat &&
             ( OP_SYMBOL(result)->liveTo > ic->seq ||
               ic->depth )) {
             int size = AOP_SIZE(right) - 1;
             while (size--)
-                emitcode("dec","%s",rname);
+             emitcode("decf","fsr,f");
+             //emitcode("dec","%s",rname);
         }
     }
 
+    DEBUGemitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     /* done */
     freeAsmop(right,NULL,ic,TRUE);
 
@@ -7351,17 +7613,20 @@ static void genGenPointerSet (operand *right,
             emitcode("mov","b,%s + 1",aopGet(AOP(result),0,TRUE,FALSE));
         }
         else { /* we need to get it byte by byte */
-            emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
-            emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
-            if (options.model == MODEL_FLAT24)
-            {
-               emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
-               emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE));
-            }
-            else
-            {
-               emitcode("mov","b,%s",aopGet(AOP(result),2,FALSE,FALSE));
-            }
+            emitcode("movlw","%s",aopGet(AOP(result),0,FALSE,FALSE));
+           emitcode("movwf","fsr");
+
+            //emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
+            //emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
+            //if (options.model == MODEL_FLAT24)
+            //{
+            //   emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
+            //   emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE));
+            //}
+            //else
+            //{
+            // emitcode("mov","b,%s",aopGet(AOP(result),2,FALSE,FALSE));
+            //}
         }
     }
     /* so dptr know contains the address */
@@ -7377,10 +7642,14 @@ static void genGenPointerSet (operand *right,
 
         while (size--) {
             char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
-            MOVA(l);
-            emitcode("lcall","__gptrput");
-            if (size)
-                emitcode("inc","dptr");
+           //emitcode("movf","%s,w",aopGet(AOP(right),offset++,FALSE,FALSE));
+           emitcode("movwf","indf");
+           if(size)
+             emitcode("incf","fsr,f");
+            //MOVA(l);
+            //DEBUGemitcode(";lcall","__gptrput");
+            //if (size)
+            //    emitcode("inc","dptr");
         }
     }
 
@@ -7478,14 +7747,23 @@ static void genIfx (iCode *ic, iCode *popIc)
 
     /* if the condition is  a bit variable */
     if (isbit && IS_ITEMP(cond) && 
-       SPIL_LOC(cond))
-       genIfxJump(ic,SPIL_LOC(cond)->rname);
-    else
+       SPIL_LOC(cond)) {
+      genIfxJump(ic,SPIL_LOC(cond)->rname);
+      DEBUGemitcode ("; isbit  SPIL_LOC","%s",SPIL_LOC(cond)->rname);
+    }
+    else {
+      /*
+       if (isbit && !IS_ITEMP(cond))
+         DEBUGemitcode ("; isbit OP_SYM","%s",OP_SYMBOL(cond)->rname);
+       else
+         DEBUGemitcode ("; isbit","a");
+      */
+
        if (isbit && !IS_ITEMP(cond))
            genIfxJump(ic,OP_SYMBOL(cond)->rname);
        else
            genIfxJump(ic,"a");
-
+    }
     ic->generated = 1;
 }
 
@@ -7562,6 +7840,7 @@ release:
 
 }
 
+#if 0
 /*-----------------------------------------------------------------*/
 /* genFarFarAssign - assignment when both are in far space         */
 /*-----------------------------------------------------------------*/
@@ -7588,6 +7867,7 @@ static void genFarFarAssign (operand *result, operand *right, iCode *ic)
     freeAsmop(result,NULL,ic,FALSE);
        
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* genAssign - generate code for assignment                        */
@@ -7807,7 +8087,7 @@ static int genMixedOperation (iCode *ic)
          }
 
          emitcode("movf","%s,w", aopGet(AOP(IC_LEFT(nextic)),offset,FALSE,FALSE));
-         emitcode("skpnc","");
+         emitSKPNC;
          emitcode("btfsc","(%s >> 3), (%s & 7)",
                   AOP(IC_RIGHT(nextic))->aopu.aop_dir,
                   AOP(IC_RIGHT(nextic))->aopu.aop_dir);
@@ -8042,10 +8322,10 @@ static void genCast (iCode *ic)
         while (size--)
          emitcode("clrf","%s",aopGet(AOP(result),offset++,FALSE,FALSE));
     } else {
-        /* we need to extend the sign :{ */
-        char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,
-                         FALSE,FALSE);
-        //MOVA(l);
+      /* we need to extend the sign :{ */
+      //char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,FALSE,FALSE);
+      //MOVA(l);
+
         emitcode("clrw","");
        emitcode("btfsc","(%s >> 3), (%s & 7)",
                 AOP(right)->aopu.aop_dir,
@@ -8108,13 +8388,15 @@ static int genDjnz (iCode *ic, iCode *ifx)
        emitcode("mov","a,%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
        emitcode("jnz","%05d_DS_",lbl->key+100);
     } else {   
-       emitcode ("djnz","%s,%05d_DS_",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
-                 lbl->key+100);
+      emitcode("decfsz","%s,f",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+      emitcode ("goto","_%05d_DS_",IC_TRUE(ifx)->key+100 + labelOffset);
+
     }
-    emitcode ("sjmp","%05d_DS_",lbl1->key+100);
-    emitcode ("","%05d_DS_:",lbl->key+100);
-    emitcode ("ljmp","%05d_DS_",IC_TRUE(ifx)->key+100);
-    emitcode ("","%05d_DS_:",lbl1->key+100);
+/*     emitcode ("sjmp","%05d_DS_",lbl1->key+100); */
+/*     emitcode ("","%05d_DS_:",lbl->key+100); */
+/*     emitcode ("ljmp","%05d_DS_",IC_TRUE(ifx)->key+100); */
+/*     emitcode ("","%05d_DS_:",lbl1->key+100); */
+
     
     freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
     ifx->generated = 1;
index c3227de1a4f84754991d2bd29b8545d4566a2a44..40eaa4750f77a83c49d443dda9f8c969c8cda1f2 100644 (file)
@@ -110,7 +110,7 @@ char *pic14aopLiteral (value *val, int offset)
 static void pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 {
     symbol *sym;
-    int i,size;
+    int i,size,bitvars=0;;
 
     if (addPublics)
       fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
@@ -173,13 +173,30 @@ static void pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
        }
        else {
            /* allocate space */
-         //if (options.debug || sym->level == 0)
-         //fprintf(map->oFile,"==.\n");
+
+         /* If this is a bit variable, then allocate storage after 8 bits have been declared */
+         /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
+         /* by grouping the bits together into groups of 8 and storing them in the normal ram.*/
+         if(IS_BITVAR(sym->etype)) {
+           if((bitvars % 8) == 0) {
+             fprintf (map->oFile, "  cblock\n");
+             fprintf (map->oFile, "\tbitfield%d\n", bitvars);
+             fprintf (map->oFile, "  endc\n");
+           }
+
+           fprintf (map->oFile, "%s\tEQU\t( (bitfield%d<<3)+%d)\n",
+                    sym->rname,
+                    bitvars & 0xfff8,
+                    bitvars & 0x0007);
+             
+           bitvars++;
+         } else {
            fprintf (map->oFile, "\t%s\n", sym->rname);
            if( (size = (unsigned int)getSize (sym->type) & 0xffff)>1) {
              for(i=1; i<size; i++)
-               fprintf (map->oFile, "\t%s_%d\n", sym->rname,size);
+               fprintf (map->oFile, "\t%s_%d\n", sym->rname,i);
            }
+         }
              //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
        }
        
@@ -957,6 +974,16 @@ void pic14glue ()
     /* Put all variables into a cblock */
     fprintf (asmFile, "\n\n\tcblock  0x13\n\n");
 
+    /* For now, create a "dpl" and a "dph" in the register space */
+    /* of the pic so that we can use the same calling mechanism */
+    /* as the 8051 port */
+    fprintf (asmFile, "%s", iComments2);
+    fprintf (asmFile, "; dpl and dph to emulate the 8051 calling mechanism \n");
+    fprintf (asmFile, "%s", iComments2);
+
+    fprintf (asmFile, "\tdph\n");
+
+
 
     /* copy the sbit segment */
     fprintf (asmFile, "%s", iComments2);
@@ -977,12 +1004,6 @@ void pic14glue ()
     fprintf (asmFile, "%s", iComments2);    
     copyFile (asmFile, ovrFile);
 
-    /* copy the bit segment */
-    fprintf (asmFile, "%s", iComments2);
-    fprintf (asmFile, "; bit data\n");
-    fprintf (asmFile, "%s", iComments2);
-    copyFile (asmFile, bit->oFile);
-
     /* create the stack segment MOF */
     if (mainf && mainf->fbody) {
        fprintf (asmFile, "%s", iComments2);
@@ -1016,6 +1037,15 @@ void pic14glue ()
     
 
     fprintf (asmFile, "\tendc\n");
+
+
+    /* copy the bit segment */
+    fprintf (asmFile, "%s", iComments2);
+    fprintf (asmFile, "; bit data\n");
+    fprintf (asmFile, "%s", iComments2);
+    copyFile (asmFile, bit->oFile);
+
+
     fprintf (asmFile, "\tORG 0\n");
 
     /* copy the interrupt vector table */
index eb997bbf0720831fc049e133363cc3468d3cd287..c785693d4bb799706a7b9eea0b2cac34dfbc6cc8 100644 (file)
@@ -218,7 +218,11 @@ PORT pic14_port = {
     },
     {
        /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
-       1, 1, 2, 4, 1, 2, 3, 1, 4, 4
+       1, 1, 2, 4, 1, 2, 1, 1, 4, 4
+       /* TSD - I changed the size of gptr from 3 to 1. However, it should be
+          2 so that we can accomodate the PIC's with 4 register banks (like the
+          16f877)
+       */
     },
     {
        "XSEG    (XDATA)",
index f86f8323191a80fafec5133aba26b41f8eaeb7d3..e80f73d0b74a9d41a82cdddd73bda58027acc531 100644 (file)
@@ -1,99 +1,98 @@
-//        ; Peephole 2     removed pop %1 push %1 (not push pop)
-//        mov  %2,%3 
-//}
-
 // peep 1
 replace restart {
-        skpz
-        goto   %1
-       incf   %2,f
-%1:
+       __movf  %1,w
+       movwf   %2
+       movf    %2,w
 } by {
-       ;peep 1
-       skpnz
-       incf   %2,f
-%1:
+       ; peep 1 - Removed redundant move
+       movf    %1,w
+       movwf   %2
 }
 
-// like peep1
+// peep 2
 replace restart {
-        skpz
-        goto   %1
-%2:
-       incf   %3,f
-%1:
+       decf    %1,f
+       movf    %1,w
+       btfss   status,z
+       goto    %2
 } by {
-       ;peep 2
-       skpnz
-%2:
-       incf   %3,f
-%1:
+       ; peep 2 - decf/mov/skpz to decfsz
+       decfsz  %1,f
+        goto   %2
 }
 
+// peep 3
 replace restart {
-        skpnz
-        goto   %1
-       incf   %2,f
-%1:
+       movwf   %1
+       movf    %1,w
+       xorlw   %2
 } by {
-       ;peep 3
-       skpz
-       incf   %2,f
-%1:
+       ; peep 3 - redundant move
+       movwf   %1
+       xorlw   %2
 }
 
+// peep 4
 replace restart {
-        skpnz
-        goto   %1
-%2:
-       incf   %3,f
-%1:
+        btfsc  %1,%2
+        goto   %3
+       incf    %4,f
+%3:
 } by {
-       ;peep 4
-       skpz
-%2:
-       incf   %3,f
-%1:
+       ;peep 4 - test/jump to test/skip
+       btfss   %1,%2
+       incf   %4,f
+%3:
 }
 
+
 // peep 5
 replace restart {
-        skpc
-        goto   %1
-       incf   %2,f
-%1:
+        btfss  %1,%2
+        goto   %3
+       incf    %4,f
+%3:
 } by {
-       ;peep 5
-       skpnc
-       incf   %2,f
-%1:
+       ;peep 5 - test/jump to test/skip
+       btfsc   %1,%2
+       incf   %4,f
+%3:
 }
 
-// like peep5
+// peep 6
 replace restart {
-        skpc
-        goto   %1
-%2:
-       incf   %3,f
-%1:
+        btfss  %1,%2
+        goto   %3
+%4:
+       incf    %5,f
+%3:
 } by {
-       ;peep 5a
-       skpnc
-%2:
-       incf   %3,f
-%1:
+       ;peep 6 - test/jump to test/skip
+       btfsc   %1,%2
+%4:
+       incf   %5,f
+%3:
 }
 
-// peep 6
+// peep 7
 replace restart {
-        skpnc
-        goto   %1
-       incf   %2,f
-%1:
+        btfsc  %1,%2
+        goto   %3
+%4:
+       incf    %5,f
+%3:
 } by {
-       ;peep 6
-       skpc
-       incf   %2,f
-%1:
+       ;peep 6 - test/jump to test/skip
+       btfss   %1,%2
+%4:
+       incf   %5,f
+%3:
 }
 
+replace restart {
+       movf    %1,w
+       movf    %1,w
+} by {
+       ; peep 8 - Removed redundant move
+       movf    %1,w
+}
index 13df6fa2929dde97d8c86328014c86cd7d243d9f..ffa3ff60905a761775a42dbb6e0cf5b28fffa301 100644 (file)
@@ -125,10 +125,14 @@ regs *pic14_regWithIdx (int idx)
 {
     int i ;
     
+    printf("%s - idx=%d\n",__FUNCTION__,idx);
+
     for (i=0;i < pic14_nRegs;i++)
        if (regspic14[i].rIdx == idx)
            return &regspic14[i];
 
+    return &regspic14[0];
+
     werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
           "regWithIdx not found");
     exit(1);
@@ -1271,7 +1275,9 @@ static char *rematStr (symbol *sym)
 
     while (1) {
 
+       printf("%s\n",s);
         /* if plus or minus print the right hand side */
+/*
         if (ic->op == '+' || ic->op == '-') {
             sprintf(s,"0x%04x %c ",(int) operandLitValue(IC_RIGHT(ic)),
                     ic->op );
@@ -1279,12 +1285,26 @@ static char *rematStr (symbol *sym)
             ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
             continue ;
         }
+*/
+        if (ic->op == '+' || ic->op == '-') {
+            iCode *ric = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+            sprintf(s,"(%s %c 0x%04x)",
+                   OP_SYMBOL(IC_LEFT(ric))->rname,
+                    ic->op,
+                   (int) operandLitValue(IC_RIGHT(ic)));
+
+           //s += strlen(s);
+           //ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
+            //continue ;
+           return buffer;
+        }
 
         /* we reached the end */
         sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
         break;
     }
 
+       printf("%s\n",buffer);
     return buffer ;
 }
 
@@ -2273,6 +2293,8 @@ void pic14_assignRegisters (eBBlock **ebbs, int count)
     iCode *ic;
     int i ;
 
+    fprintf(stderr,"%s:%s",__FILE__,__FUNCTION__);
+
     setToNull((void *)&_G.funcrUsed);
     pic14_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
 
index 073129faf76859c896ee61d365f8ee16c0f66782..31b090bfb291cc20c9db8b5dd8374f0c5928aee2 100644 (file)
@@ -55,7 +55,13 @@ SIMULATE = simulate
 
 # List the C files to be test here:
 SRC = b.c \
-       compare.c
+       add.c \
+       bool1.c \
+       call1.c \
+       compare.c \
+       compare2.c \
+       for.c \
+       while.c
 
 COD := $(patsubst %.c, %.cod, $(SRC))
 ASM := $(patsubst %.c, %.asm, $(SRC))
diff --git a/src/regression/add.c b/src/regression/add.c
new file mode 100644 (file)
index 0000000..15ac6c1
--- /dev/null
@@ -0,0 +1,196 @@
+//#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 add_lit2uchar(void)
+{
+
+  achar0 = achar0 + 5;
+
+  if(achar0 != 5)
+    failures++;
+
+  achar0 += 10;
+
+  if(achar0 != 15)
+    failures++;
+
+  achar0 = achar0 +1;  // Should be an increment
+  if(achar0 != 16)
+    failures++;
+
+  for(achar1 = 0; achar1 < 100; achar1++)
+    achar0 += 2;
+
+  if(achar0 != 216)
+    failures++;
+
+}
+
+void add_uchar2uchar(void)
+{
+
+  achar1 = achar1 + achar0;
+
+  if(achar1 != 16)
+    failures++;
+
+  for(achar2 = 0; achar2<7; achar2++)
+    achar1 += achar0;
+
+  if(achar1 != 128)
+    failures++;
+
+}
+
+// assumes
+//  achar0 = 0
+//  achar1 = 32
+//  achar2, achar3 can be anything.
+
+void add_uchar2uchar2(void)
+{
+
+
+  achar0++;
+  achar0 = achar0 + 1;
+  achar0 = achar0 + 2;
+  achar0 = achar0 + 3;
+  if(achar0 != 7)
+    failures++;
+
+  achar1 += achar0;
+  if(achar1 != 39)
+    failures++;
+
+  achar2 = achar1 + achar0;
+  if(achar2 != 46)
+    failures++;
+
+  achar3 = achar2 + achar1 + achar0;
+  if(achar3 != 92)
+    failures++;
+
+}
+
+#if SUPPORT_BIT_TYPES
+void add_bits(void)
+{
+
+  bit1 = bit0;
+
+  bit0 = 1;
+
+  if(bit1 != 0)
+    failures++;
+
+  bit1 = bit1+bit0;
+  if(bit1 != 1)
+    failures++;
+
+#if SUPPORT_BIT_ARITHMETIC
+  bit2 = bit1+bit3;
+  if(bit2)
+    failures++;
+
+  bit3 = bit4+bit5+bit6+bit7+bit0;
+  if(!bit3)
+    failures++;
+#endif
+}
+#endif
+
+/* add_bit2uchar(void) - assumes bit0 = 1, achar0 = 7  */
+
+void add_bit2uchar(void)
+{
+
+  achar0 += bit0;
+
+  if(achar0 != 8)
+    failures++;
+
+  if(achar0 == bit0)
+    failures++;
+
+}
+
+void add_bit2uint(void)
+{
+
+  if(aint0 != bit11)
+    failures++;
+
+  aint0 += bit0;
+  if(aint0!=1)
+    failures++;
+
+}
+void main(void)
+{
+
+  add_lit2uchar();
+
+  achar0=16;
+  achar1=0;
+  add_uchar2uchar();
+
+
+  achar0 = 0;
+  achar1 = 32;
+  add_uchar2uchar2();
+
+#if SUPPORT_BIT_TYPES
+  add_bits();
+
+  add_bit2uchar();
+  add_bit2uint();
+#endif
+
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/arrays.c b/src/regression/arrays.c
new file mode 100644 (file)
index 0000000..dc0a7f3
--- /dev/null
@@ -0,0 +1,137 @@
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void bool_or1(void)
+{
+
+  if( (achar0 >0) || (achar1 >0 ))
+    failures++;
+}
+
+void bool_or2(void)
+{
+
+  if( achar0 || achar1)
+    failures++;
+}
+
+void bool_test1(void)
+{
+
+  if( (achar0==0) || achar1)
+    failures++;
+}
+
+
+void bool_test2(void)
+{
+
+  if( (achar0==0) || aint0)
+    failures++;
+}
+
+void bool_and1(void)
+{
+
+  if( achar0 && achar1)
+    failures++;
+}
+
+void bin_or1(void)
+{
+
+  char t;
+
+  t = achar0 | achar1;
+  if(t)
+    failures++;
+}
+
+void bin_xor1(void)
+{
+
+  if(achar0 ^ achar1)
+    failures++;
+}
+
+
+void bool_test3(void)
+{
+
+  if((achar0 == 0x42) || (achar1 == 42))
+    failures++;
+}
+
+
+void bool_or_lit1(void)
+{
+
+  achar0 |= 0x0f;
+
+  if(achar0 > 0x10)
+    failures++;
+
+  if( (achar0 | 0x10) > 0xf0)
+    failures++;
+
+}
+
+void bool_and_lit1(void)
+{
+
+  achar0 &= 0xf0;
+
+  if(achar0 > 0x10)
+    failures++;
+
+  if( (achar0 & 0x10) > 0xf0)
+    failures++;
+
+  achar0 &= 0xef;
+
+}
+
+void main(void)
+{
+
+  bool_or1();
+  bool_or2();
+  bool_and1();
+  bin_or1();
+  bin_xor1();
+
+  achar0++;
+  bool_and1();
+  bool_test1();
+  bool_test2();
+  bool_test3();
+
+
+  achar0--; achar1++;
+  bool_and1();
+
+  achar0=0;
+  achar1=0;
+
+  bool_or_lit1();
+  bool_and_lit1();
+
+  success = failures;
+  done();
+}
index dc0a7f3cec6aba6cdc6afac0669aef700211ab3d..2810d832c4a99e88446423b5ef4a69ad8f61cdf9 100644 (file)
-//#include "p16c84.h"
 
-unsigned char success=0;
-unsigned char failures=0;
-unsigned char dummy=0;
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
 
-bit bit0 = 0;
-unsigned int aint0 = 0;
-unsigned int aint1 = 0;
-unsigned char achar0 = 0;
-unsigned char achar1 = 0;
-
-void done()
+unsigned char uchar0=0;
+void done(void)
 {
-
   dummy++;
-
-}
-
-void bool_or1(void)
-{
-
-  if( (achar0 >0) || (achar1 >0 ))
-    failures++;
-}
-
-void bool_or2(void)
-{
-
-  if( achar0 || achar1)
-    failures++;
-}
-
-void bool_test1(void)
-{
-
-  if( (achar0==0) || achar1)
-    failures++;
-}
-
-
-void bool_test2(void)
-{
-
-  if( (achar0==0) || aint0)
-    failures++;
-}
-
-void bool_and1(void)
-{
-
-  if( achar0 && achar1)
-    failures++;
-}
-
-void bin_or1(void)
-{
-
-  char t;
-
-  t = achar0 | achar1;
-  if(t)
-    failures++;
-}
-
-void bin_xor1(void)
-{
-
-  if(achar0 ^ achar1)
-    failures++;
-}
-
-
-void bool_test3(void)
-{
-
-  if((achar0 == 0x42) || (achar1 == 42))
-    failures++;
-}
-
-
-void bool_or_lit1(void)
-{
-
-  achar0 |= 0x0f;
-
-  if(achar0 > 0x10)
-    failures++;
-
-  if( (achar0 | 0x10) > 0xf0)
-    failures++;
-
-}
-
-void bool_and_lit1(void)
-{
-
-  achar0 &= 0xf0;
-
-  if(achar0 > 0x10)
-    failures++;
-
-  if( (achar0 & 0x10) > 0xf0)
-    failures++;
-
-  achar0 &= 0xef;
-
 }
 
 void main(void)
 {
 
-  bool_or1();
-  bool_or2();
-  bool_and1();
-  bin_or1();
-  bin_xor1();
-
-  achar0++;
-  bool_and1();
-  bool_test1();
-  bool_test2();
-  bool_test3();
-
-
-  achar0--; achar1++;
-  bool_and1();
-
-  achar0=0;
-  achar1=0;
-
-  bool_or_lit1();
-  bool_and_lit1();
+  uchar0=1;
 
   success = failures;
   done();
+
 }
diff --git a/src/regression/bool1.c b/src/regression/bool1.c
new file mode 100644 (file)
index 0000000..dc0a7f3
--- /dev/null
@@ -0,0 +1,137 @@
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void bool_or1(void)
+{
+
+  if( (achar0 >0) || (achar1 >0 ))
+    failures++;
+}
+
+void bool_or2(void)
+{
+
+  if( achar0 || achar1)
+    failures++;
+}
+
+void bool_test1(void)
+{
+
+  if( (achar0==0) || achar1)
+    failures++;
+}
+
+
+void bool_test2(void)
+{
+
+  if( (achar0==0) || aint0)
+    failures++;
+}
+
+void bool_and1(void)
+{
+
+  if( achar0 && achar1)
+    failures++;
+}
+
+void bin_or1(void)
+{
+
+  char t;
+
+  t = achar0 | achar1;
+  if(t)
+    failures++;
+}
+
+void bin_xor1(void)
+{
+
+  if(achar0 ^ achar1)
+    failures++;
+}
+
+
+void bool_test3(void)
+{
+
+  if((achar0 == 0x42) || (achar1 == 42))
+    failures++;
+}
+
+
+void bool_or_lit1(void)
+{
+
+  achar0 |= 0x0f;
+
+  if(achar0 > 0x10)
+    failures++;
+
+  if( (achar0 | 0x10) > 0xf0)
+    failures++;
+
+}
+
+void bool_and_lit1(void)
+{
+
+  achar0 &= 0xf0;
+
+  if(achar0 > 0x10)
+    failures++;
+
+  if( (achar0 & 0x10) > 0xf0)
+    failures++;
+
+  achar0 &= 0xef;
+
+}
+
+void main(void)
+{
+
+  bool_or1();
+  bool_or2();
+  bool_and1();
+  bin_or1();
+  bin_xor1();
+
+  achar0++;
+  bool_and1();
+  bool_test1();
+  bool_test2();
+  bool_test3();
+
+
+  achar0--; achar1++;
+  bool_and1();
+
+  achar0=0;
+  achar1=0;
+
+  bool_or_lit1();
+  bool_and_lit1();
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/call1.c b/src/regression/call1.c
new file mode 100644 (file)
index 0000000..35878f1
--- /dev/null
@@ -0,0 +1,81 @@
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+unsigned char call3(void);
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void call1(unsigned char uc0)
+{
+  if(uc0)
+    failures++;
+}
+
+void call2(unsigned int ui0)
+{
+  if(ui0)
+    failures++;
+
+}
+
+unsigned char call3(void)
+{
+  if(achar0)
+    failures++;
+
+  return(failures);
+
+}
+
+unsigned int call4(void)
+{
+  unsigned int i=0;
+
+  if(aint0)
+    i++;
+
+  return(i);
+
+}
+
+unsigned int call5(unsigned int k)
+{
+
+  if(k)
+    failures++;
+
+  return(k);
+
+}
+
+void main(void)
+{
+
+  call1(achar0);
+  call2(aint0);
+  achar1 = call3();
+  aint1 = call4();
+  if(aint1)
+    failures++;
+
+  aint1 = call5(aint0);
+  if(aint1)
+    failures++;
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/compare2.c b/src/regression/compare2.c
new file mode 100644 (file)
index 0000000..d082a4e
--- /dev/null
@@ -0,0 +1,162 @@
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+
+
+void char_lt_char(void)
+{
+  if(achar0 < achar1)
+    failures++;
+}
+
+void char_gt_char(void)
+{
+  if(achar1 > achar0)
+    failures++;
+}
+
+void char_lte_char(void)
+{
+  if(achar0 <= achar1)
+    failures++;
+}
+
+void char_gte_char(void)
+{
+  if(achar1 >= achar0)
+    failures++;
+}
+
+void char_lt_lit(void)
+{
+  if(achar1 < 0x10)
+    failures++;
+}
+
+void char_gt_lit(void)
+{
+  if(achar1 > 0x10)
+    failures++;
+}
+
+void char_lte_lit(void)
+{
+  if(achar1 <= 0x0f)
+    failures++;
+}
+
+void char_gte_lit(void)
+{
+  if(achar1 >= 0x11)
+    failures++;
+}
+
+
+/* ints */
+
+void int_lt_int(void)
+{
+  if(aint0 < aint1)
+    failures++;
+}
+
+void int_gt_int(void)
+{
+  if(aint1 > aint0)
+    failures++;
+}
+
+void int_lte_int(void)
+{
+  if(aint0 <= aint1)
+    failures++;
+}
+
+void int_gte_int(void)
+{
+  if(aint1 >= aint0)
+    failures++;
+}
+
+void int_lt_lit(void)
+{
+  if(aint1 < 0x10)
+    failures++;
+}
+
+void int_gt_lit(void)
+{
+  if(aint1 > 0x10)
+    failures++;
+}
+
+void int_lte_lit(void)
+{
+  if(aint1 <= 0x0f)
+    failures++;
+}
+
+void int_gte_lit(void)
+{
+  if(aint1 >= 0x11)
+    failures++;
+}
+
+
+
+
+
+
+
+void main(void)
+{
+
+  char_lt_char();
+  char_gt_char();
+
+  achar0++;
+  char_lt_char();
+  char_gt_char();
+  char_gte_char();
+  char_lte_char();
+
+  achar1 = 0x10;
+  char_lt_lit();
+  char_gt_lit();
+  char_lte_lit();
+  char_gte_lit();
+
+
+
+  int_lt_int();
+  int_gt_int();
+
+  aint0++;
+  int_lt_int();
+  int_gt_int();
+  int_gte_int();
+  int_lte_int();
+
+  aint1 = 0x10;
+  int_lt_lit();
+  int_gt_lit();
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/for.c b/src/regression/for.c
new file mode 100644 (file)
index 0000000..aed33a8
--- /dev/null
@@ -0,0 +1,53 @@
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+unsigned char call3(void);
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void for1(void)
+{
+  unsigned char i=0;
+
+  for(i=0; i<10; i++)
+    achar0++;
+
+  if(achar0 != 10)
+    failures++;
+
+}
+
+void for2(void)
+{
+  unsigned char i=0;
+
+  for(i=0; i<10; i++)
+    achar0++;
+
+  if(i < 10)
+    failures++;
+
+}
+
+void main(void)
+{
+  for1();
+  for2();
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/pointer1.c b/src/regression/pointer1.c
new file mode 100644 (file)
index 0000000..7b0cbc2
--- /dev/null
@@ -0,0 +1,64 @@
+//#include "p16c84.h"
+// Pointer tests
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+unsigned char *acharP = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void f1(unsigned char *ucP)
+{
+
+  if(ucP==0) {
+    failures++;
+    return;
+  }
+
+   if(*ucP)
+      failures++;
+}
+
+void f2(unsigned int *uiP)
+{
+
+  if(uiP==0) {
+    failures++;
+    return;
+  }
+
+  if(*uiP)
+    failures++;
+
+}
+
+unsigned char *f3(void)
+{
+
+  return &achar0;
+}
+
+void main(void)
+{
+  f1(&achar0);
+  f2(&aint0);
+
+  acharP = f3();
+  if( (acharP == 0) || (*acharP))
+      failures++;
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/struct1.c b/src/regression/struct1.c
new file mode 100644 (file)
index 0000000..fd3e860
--- /dev/null
@@ -0,0 +1,90 @@
+//#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 *acharP = 0;
+
+struct chars {
+  unsigned char c0,c1;
+};
+
+
+struct chars char_struct;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void struct_test(void)
+{
+
+  if(char_struct.c0 || char_struct.c1)
+    failures++;
+
+  char_struct.c0++;
+
+  if(char_struct.c0 != 1)
+    failures++;
+}
+
+void ptr_to_struct(struct chars *p)
+{
+
+  if(p->c1)
+    failures++;
+
+
+  p->c1++;
+
+  if(p->c1 != 1)
+    failures++;
+}
+
+
+void main(void)
+{
+
+
+  char_struct.c0 = 0;
+  char_struct.c1 = 0;
+  struct_test();
+  ptr_to_struct(&char_struct);
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/while.c b/src/regression/while.c
new file mode 100644 (file)
index 0000000..74e9942
--- /dev/null
@@ -0,0 +1,42 @@
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void while1(void)
+{
+  unsigned char i=10;
+
+  do {
+    achar0++;
+  } while(--i);
+
+  if(achar0 != 10)
+    failures++;
+
+}
+
+
+void main(void)
+{
+  while1();
+
+
+  success = failures;
+  done();
+}