* src/pic16/pcode.c (pic16_newpCodeOpLit12),
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 29 Apr 2006 08:53:05 +0000 (08:53 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 29 Apr 2006 08:53:05 +0000 (08:53 +0000)
* src/pic16/gen.c (pic16_popGetLit12): NEW, create 12 bit literal,
  (pic16_loadFSR0): handle 12 bit literals correctly, fixes #1440527
* src/pic16/pcode.h: added prototype for pic16_newpCodeOpLit12()

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

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

index 557be87508a564382ef79907eaff3851982701f2..cd0ac7deece9b30ce71b5be03296c59502820dc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-04-28 Raphael Neider <rneider AT web.de>
+
+       * src/pic16/pcode.c (pic16_newpCodeOpLit12),
+       * src/pic16/gen.c (pic16_popGetLit12): NEW, create 12 bit literal,
+         (pic16_loadFSR0): handle 12 bit literals correctly, fixes #1440527
+       * src/pic16/pcode.h: added prototype for pic16_newpCodeOpLit12()
+
 2006-04-28 Bernhard Held <bernhard AT bernhardheld.de>
 
        * device/lib/pic/libdev/Makefile.in,
index 71f6aa2aa39a579acc30b4b4cc0faca165acdb39..55810a463ba86af169aa2f7efc7750cbc07c9253 100644 (file)
@@ -1869,6 +1869,12 @@ pCodeOp *pic16_popGetLit(int lit)
   return pic16_newpCodeOpLit(lit);
 }
 
+/* Allow for 12 bit literals (LFSR x, <here!>). */
+pCodeOp *pic16_popGetLit12(int lit)
+{
+  return pic16_newpCodeOpLit12(lit);
+}
+
 /*-----------------------------------------------------------------*/
 /* pic16_popGetLit2 - asm operator to pcode operator conversion    */
 /*-----------------------------------------------------------------*/
@@ -10512,7 +10518,18 @@ static void genRightShift (iCode *ic) {
 void pic16_loadFSR0(operand *op, int lit)
 {
   if((IS_SYMOP(op) && OP_SYMBOL(op)->remat) || is_LitOp( op )) {
-    pic16_emitpcode(POC_LFSR, pic16_popGetLit2(0, pic16_popGet(AOP(op), 0)));
+    if (AOP_TYPE(op) == AOP_LIT) {
+      /* handle 12 bit integers correctly */
+      unsigned int val = (unsigned int)floatFromVal(AOP(op)->aopu.aop_lit);
+      if ((val & 0x0fff) != val) {
+        fprintf (stderr, "WARNING: Accessing memory at 0x%x truncated to 0x%x.\n",
+               val, (val & 0x0fff) );
+       val &= 0x0fff;
+      }
+      pic16_emitpcode(POC_LFSR, pic16_popGetLit2(0, pic16_popGetLit12(val)));
+    } else {
+      pic16_emitpcode(POC_LFSR, pic16_popGetLit2(0, pic16_popGet(AOP(op), 0)));
+    }
   } else {
     assert (!IS_SYMOP(op) || !OP_SYMBOL(op)->remat);
     // set up FSR0 with address of result
index 49ab5b1501b0785b9a6de9d613b9a2b3e4372607..52c8e8efd61596a766ca14f43c89b441f44457eb 100644 (file)
@@ -4069,6 +4069,30 @@ pCodeOp *pic16_newpCodeOpLit(int lit)
   return pcop;
 }
 
+/* Allow for 12 bit literals, required for LFSR */
+pCodeOp *pic16_newpCodeOpLit12(int lit)
+{
+  char *s = buffer;
+  pCodeOp *pcop;
+
+
+  pcop = Safe_calloc(1,sizeof(pCodeOpLit) );
+  pcop->type = PO_LITERAL;
+
+  pcop->name = NULL;
+  //if(lit>=0)
+    sprintf(s,"0x%03x", ((unsigned int)lit) & 0x0fff);
+  //else
+  //  sprintf(s, "%i", lit);
+  
+  if(s)
+    pcop->name = Safe_strdup(s);
+
+  ((pCodeOpLit *)pcop)->lit = lit;
+
+  return pcop;
+}
+
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 pCodeOp *pic16_newpCodeOpLit2(int lit, pCodeOp *arg2)
index f4c4789be7adefd62b2e23316ac99c0a06e94997..597abf53fe20901e59999bee5fa3ee7a49c923c5 100644 (file)
@@ -1035,6 +1035,7 @@ pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...);
 pCodeOp *pic16_newpCodeOpLabel(char *name, int key);
 pCodeOp *pic16_newpCodeOpImmd(char *name, int offset, int index, int code_space);
 pCodeOp *pic16_newpCodeOpLit(int lit);
+pCodeOp *pic16_newpCodeOpLit12(int lit);
 pCodeOp *pic16_newpCodeOpLit2(int lit, pCodeOp *arg2);
 pCodeOp *pic16_newpCodeOpBit(char *name, int bit,int inBitSpace, PIC_OPTYPE subt);
 pCodeOp *pic16_newpCodeOpBit_simple (struct asmop *op, int offs, int bit);