From: tecodev Date: Sat, 29 Apr 2006 08:53:05 +0000 (+0000) Subject: * src/pic16/pcode.c (pic16_newpCodeOpLit12), X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=758812d261c4dab1f506a0d797ffcbab2ccb4754;p=fw%2Fsdcc * 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() git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4139 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 557be875..cd0ac7de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-04-28 Raphael Neider + + * 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 * device/lib/pic/libdev/Makefile.in, diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 71f6aa2a..55810a46 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -1869,6 +1869,12 @@ pCodeOp *pic16_popGetLit(int lit) return pic16_newpCodeOpLit(lit); } +/* Allow for 12 bit literals (LFSR x, ). */ +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 diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index 49ab5b15..52c8e8ef 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -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) diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index f4c4789b..597abf53 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -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);