* 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
+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,
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 */
/*-----------------------------------------------------------------*/
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
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)
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);