]> git.gag.com Git - fw/sdcc/commitdiff
* src/pic16/gen.c (aopForSym, genEndFunction): applied some fixes
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 4 Jan 2005 00:51:18 +0000 (00:51 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 4 Jan 2005 00:51:18 +0000 (00:51 +0000)
from Raphael Neider,
* src/pic16/pcode.c (pic16_newpCodeOpLit): removed casting to char
for 8-bit literals. This fixes some literal operands which are sign
extended to 16-bits ints when instruction needs only 8-bits.

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

ChangeLog
src/pic16/gen.c
src/pic16/pcode.c

index b1bfac37497e34df8273bb22f139af9a1cfb1fcc..bb24a0b85cade26530410a2e82189e53cc99156a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-01-04 Vangelis Rokas <vrokas AT otenet.gr>
+
+       * src/pic16/gen.c (aopForSym, genEndFunction): applied some fixes
+       from Raphael Neider,
+       * src/pic16/pcode.c (pic16_newpCodeOpLit): removed casting to char
+       for 8-bit literals. This fixes some literal operands which are sign
+       extended to 16-bits ints when instruction needs only 8-bits.
+
 2004-12-31 Paul Stoffregen <paul AT pjrc.com>
 
        * device/lib/logf.c: added mcs51 assembly version
index 3ce98f4676b4db01d35344331b3e2049307e9abc..b69ba63d7b2364a05f53cb4270f980607b81e226 100644 (file)
@@ -680,11 +680,20 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result)
        for(i=0;i<aop->size;i++) {
 
          /* initialise for stack access via frame pointer */
-         // operands on stack are accessible via "FSR2 - index" with index starting at 0 for the first operand
-         pic16_emitpcode(POC_MOVLW, pic16_popGetLit((sym->stack + 1 + i /*+ _G.stack_lat*/)));
-         pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
-                         pic16_popCopyReg(&pic16_pc_plusw2), pcop[i]));
-        }
+          // operands on stack are accessible via "FSR2 + index" with index
+          // starting at 2 for arguments and growing from 0 downwards for
+          // local variables (index == 0 is not assigned so we add one here)
+         {
+           int soffs = sym->stack;
+           if (soffs <= 0) {
+             assert (soffs < 0);
+             soffs++;
+           } // if
+           pic16_emitpcode(POC_MOVLW, pic16_popGetLit(soffs + i /*+ _G.stack_lat*/));
+           pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+                           pic16_popCopyReg(&pic16_pc_plusw2), pcop[i]));
+         }
+       }
        
        if(_G.accInUse) {
                pic16_poppCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
@@ -1300,14 +1309,21 @@ void pic16_freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
 
               /* we must store the result on stack */
               if((op == IC_RESULT(ic)) && RESULTONSTA(ic)) {
+                // operands on stack are accessible via "FSR2 + index" with index
+                // starting at 2 for arguments and growing from 0 downwards for
+                // local variables (index == 0 is not assigned so we add one here)
+                int soffs = OP_SYMBOL(IC_RESULT(ic))->stack;
+                if (soffs <= 0) {
+                  assert (soffs < 0);
+                  soffs++;
+                } // if
                 if(_G.accInUse)pic16_pushpCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
                 for(i=0;i<aop->size;i++) {
-                  /* initialise for stack access via frame pointer */
-                  // operands on stack are accessible via "FSR2 - index" with index starting at 0 for the first operand
-                  pic16_emitpcode(POC_MOVLW, pic16_popGetLit((OP_SYMBOL(IC_RESULT(ic))->stack + 1 + i /*+ _G.stack_lat*/)));
-                  pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+                 /* initialise for stack access via frame pointer */
+                 pic16_emitpcode(POC_MOVLW, pic16_popGetLit(soffs + i /*+ _G.stack_lat*/));
+                 pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
                         aop->aopu.stk.pop[i], pic16_popCopyReg(&pic16_pc_plusw2)));
-                }
+               }
        
                 if(_G.accInUse)pic16_poppCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
               }
@@ -1480,7 +1496,7 @@ char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname)
        return (rs);
 
     case AOP_LIT:
-       sprintf(s,"0x%02x", pic16aopLiteral (aop->aopu.aop_lit,offset));
+       sprintf(s,"0X%02x", pic16aopLiteral (aop->aopu.aop_lit,offset));
        rs = Safe_calloc(1,strlen(s)+1);
        strcpy(rs,s);   
        return rs;
@@ -3681,23 +3697,6 @@ static void genEndFunction (iCode *ic)
       /* TODO: add code here -- VR */
     }
     
-    if ((IFFUNC_ISREENT(sym->type) || options.stackAuto)
-          && sym->stack) {
-      if (sym->stack == 1) {
-        pic16_emitpcode(POC_INFSNZ, pic16_popCopyReg(&pic16_pc_fsr1l));
-        pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1h));
-      } else {
-        // we have to add more than one...
-        pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postinc1)); // this holds a return value!
-        pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack-1));
-        pic16_emitpcode(POC_ADDWF, pic16_popCopyReg(&pic16_pc_fsr1l));
-        emitSKPNC;
-        pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1h));
-        pic16_emitpcode(POC_COMF,  pic16_popCopyReg(&pic16_pc_wreg)); // WREG = -(WREG+1)!
-        pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_plusw1)); // this holds a retrun value!
-      }
-    }
-
 //    sym->regsUsed = _G.fregsUsed;
     
     /* now we need to restore the registers */
@@ -3718,6 +3717,23 @@ static void genEndFunction (iCode *ic)
 
     }
 
+    if ((IFFUNC_ISREENT(sym->type) || options.stackAuto)
+          && sym->stack) {
+      if (sym->stack == 1) {
+        pic16_emitpcode(POC_INFSNZ, pic16_popCopyReg(&pic16_pc_fsr1l));
+        pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1h));
+      } else {
+        // we have to add more than one...
+        pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postinc1)); // this holds a return value!
+        pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack-1));
+        pic16_emitpcode(POC_ADDWF, pic16_popCopyReg(&pic16_pc_fsr1l));
+        emitSKPNC;
+        pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1h));
+        pic16_emitpcode(POC_COMF,  pic16_popCopyReg(&pic16_pc_wreg)); // WREG = -(WREG+1)!
+        pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_plusw1)); // this holds a retrun value!
+      }
+    }
+
     if(strcmp(sym->name, "main")) {
       if(1/*!options.ommitFramePtr ||*/ /*sym->regsUsed*/) {
         /* restore stack frame */
@@ -12038,18 +12054,23 @@ static void genAddrOf (iCode *ic)
                   OP_SYMBOL(left)->name, OP_SYMBOL(left)->stack);
 #endif
 
-      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
-                      pic16_popCopyReg(&pic16_pc_fsr2l),
-                      pic16_popGet(AOP(result), 0)));
-      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
-                      pic16_popCopyReg(&pic16_pc_fsr2h),
-                      pic16_popGet(AOP(result), 1)));
-     
-      // operands on stack are accessible via "FSR2 - index" with index starting at 0 for the first operand
-      pic16_emitpcode(POC_MOVLW, pic16_popGetLit( - (OP_SYMBOL( IC_LEFT(ic))->stack + 1 ) /*+ _G.stack_lat*/));
-      pic16_emitpcode(POC_SUBWF, pic16_popGet(AOP(result), 0));
-      emitSKPC;
-      pic16_emitpcode(POC_DECF, pic16_popGet(AOP(result), 1));
+      // operands on stack are accessible via "FSR2 + index" with index
+      // starting at 2 for arguments and growing from 0 downwards for
+      // local variables (index == 0 is not assigned so we add one here)
+      {
+       int soffs = OP_SYMBOL( IC_LEFT(ic))->stack;
+       if (soffs <= 0) {
+         assert (soffs < 0);
+         soffs++;
+       } // if
+       DEBUGpic16_emitcode("*!*", "accessing stack symbol at offset=%d", soffs);
+       pic16_emitpcode(POC_MOVLW , pic16_popGetLit( soffs & 0x00FF ));
+       pic16_emitpcode(POC_ADDFW , pic16_popCopyReg(&pic16_pc_fsr2l));
+       pic16_emitpcode(POC_MOVWF , pic16_popGet(AOP(result), 0));
+       pic16_emitpcode(POC_MOVLW , pic16_popGetLit( (soffs >> 8) & 0x00FF ));
+       pic16_emitpcode(POC_ADDFWC, pic16_popCopyReg(&pic16_pc_fsr2h));
+       pic16_emitpcode(POC_MOVWF , pic16_popGet(AOP(result), 1));
+      }
 
       goto release;
     }
index b85f6987564ed1127861753e26c7cdea97887d80..d6b250d07997ab657abf46a78e74a7ae094321da 100644 (file)
@@ -4014,10 +4014,10 @@ pCodeOp *pic16_newpCodeOpLit(int lit)
   pcop->type = PO_LITERAL;
 
   pcop->name = NULL;
-//  if(lit>=0)
-    sprintf(s,"0x%02hhx",(char)(lit));
-//  else
-//    sprintf(s, "%i", lit);
+  if(lit>=0)
+    sprintf(s,"0x%02hhx", lit);
+  else
+    sprintf(s, "%i", lit);
   
   if(s)
     pcop->name = Safe_strdup(s);
@@ -4041,7 +4041,7 @@ pCodeOp *pic16_newpCodeOpLit2(int lit, pCodeOp *arg2)
 
   pcop->name = NULL;
   if(lit>=0) {
-    sprintf(s,"0x%02x, %s",lit, tb);
+    sprintf(s,"0x%02x, %s", lit, tb);
     if(s)
       pcop->name = Safe_strdup(s);
   }