}
+
+#if 1
+#define pic16_emitcode DEBUGpic16_emitcode
+#else
/*-----------------------------------------------------------------*/
/* pic16_emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
va_end(ap);
}
+#endif
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void genSkip(iCode *ifx,int status_bit)
{
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(!ifx)
return;
}
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ifx)->key));
- pic16_emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+ // pic16_emitcode("goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
} else {
break;
}
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ifx)->key));
- pic16_emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
+ // pic16_emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
}
rifx->generated = 1;
}
+#if 0
/*-----------------------------------------------------------------*/
/* genSkipz */
/*-----------------------------------------------------------------*/
pic16_emitcode("goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
}
+#endif
+
/*-----------------------------------------------------------------*/
/* genSkipCond */
/*-----------------------------------------------------------------*/
operand *left, *right, *result;
unsigned long lit = 0L;
int size,offset=0;
+ symbol *falselbl = newiTempLabel(NULL);
+
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(ifx && !AOP_SIZE(result)){
symbol *tlbl;
+ DEBUGpic16_emitcode ("; ***","%s %d CASE 1",__FUNCTION__,__LINE__);
/* if they are both bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
+ DEBUGpic16_emitcode ("; ***","%s %d CASE 11",__FUNCTION__,__LINE__);
if(AOP_TYPE(right) == AOP_LIT){
unsigned long lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
if(lit == 0L){
}
pic16_emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
- {
- /* left and right are both bit variables, result is carry */
- resolvedIfx rIfx;
+ {
+ /* left and right are both bit variables, result is carry */
+ resolvedIfx rIfx;
- resolveIfx(&rIfx,ifx);
-
- pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ANDFW,pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_BTFSC,pic16_popGet(AOP(right),0));
- pic16_emitpcode(POC_ANDLW,pic16_popGet(AOP(left),0));
- genSkipz2(&rIfx,0);
- }
+ resolveIfx(&rIfx,ifx);
+
+ pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),0));
+ pic16_emitpcode(POC_ANDFW,pic16_popGet(AOP(left),0));
+ pic16_emitpcode(POC_BTFSC,pic16_popGet(AOP(right),0));
+ pic16_emitpcode(POC_ANDLW,pic16_popGet(AOP(left),0));
+ genSkipz2(&rIfx,0);
+ }
} else {
- /* They're not both bit variables. Is the right a literal? */
- if(AOP_TYPE(right) == AOP_LIT) {
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- switch(size) {
-
- case 1:
- switch(lit & 0xff) {
- case 1:
- if ( IC_TRUE(ifx) ) {
- pic16_emitpcode(POC_DECFW,pic16_popGet(AOP(left),offset));
- emitSKPNZ;
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ifx)->key));
- } else {
- pic16_emitpcode(POC_DECFSZW,pic16_popGet(AOP(left),offset));
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ifx)->key));
- }
- break;
- case 0xff:
- if ( IC_TRUE(ifx) ) {
- pic16_emitpcode(POC_INCFW,pic16_popGet(AOP(left),offset));
- emitSKPNZ;
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ifx)->key));
- } else {
- pic16_emitpcode(POC_INCFSZW,pic16_popGet(AOP(left),offset));
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ifx)->key));
- }
- break;
- default:
- pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),offset));
- if(lit)
- pic16_emitpcode(POC_XORLW,pic16_popGetLit(lit & 0xff));
- genSkip(ifx,'z');
- }
-
+ DEBUGpic16_emitcode ("; ***","%s %d CASE 12",__FUNCTION__,__LINE__);
- /* end of size == 1 */
- break;
+ /* They're not both bit variables. Is the right a literal? */
+ if(AOP_TYPE(right) == AOP_LIT) {
+ lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+
+ switch(size) {
+
+ case 1:
+ switch(lit & 0xff) {
+ case 1:
+ if ( IC_TRUE(ifx) ) {
+ pic16_emitpcode(POC_DECFW,pic16_popGet(AOP(left),offset));
+ emitSKPNZ;
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ifx)->key));
+ } else {
+ pic16_emitpcode(POC_DECFSZW,pic16_popGet(AOP(left),offset));
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ifx)->key));
+ }
+ break;
+ case 0xff:
+ if ( IC_TRUE(ifx) ) {
+ pic16_emitpcode(POC_INCFW,pic16_popGet(AOP(left),offset));
+ emitSKPNZ;
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ifx)->key));
+ } else {
+ pic16_emitpcode(POC_INCFSZW,pic16_popGet(AOP(left),offset));
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ifx)->key));
+ }
+ break;
+ default:
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),offset));
+ if(lit)
+ pic16_emitpcode(POC_XORLW,pic16_popGetLit(lit & 0xff));
+ genSkip(ifx,'z');
+ } // switch lit
+
+
+ /* end of size == 1 */
+ break;
- case 2:
- genc16bit2lit(left,lit,offset);
- genSkip(ifx,'z');
- break;
- /* end of size == 2 */
-
- default:
- /* size is 4 */
- if(lit==0) {
- pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),1));
- pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),2));
- pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),3));
-
- } else {
-
- /* search for patterns that can be optimized */
-
- genc16bit2lit(left,lit,0);
- lit >>= 16;
- if(lit) {
- genSkipz(ifx,IC_TRUE(ifx) == NULL);
- //genSkip(ifx,'z');
- genc16bit2lit(left,lit,2);
- } else {
- pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),2));
- pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),3));
-
- }
-
- }
-
- genSkip(ifx,'z');
- }
+ case 2:
+ genc16bit2lit(left,lit,offset);
+ genSkip(ifx,'z');
+ break;
+ /* end of size == 2 */
+
+ default:
+ /* size is 4 */
+ if(lit==0) {
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),0));
+ pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),1));
+ pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),2));
+ pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),3));
+ genSkip(ifx,'z');
+ } else {
+ /* search for patterns that can be optimized */
+
+ genc16bit2lit(left,lit,0);
+ lit >>= 16;
+ if(lit) {
+ if(IC_TRUE(ifx))
+ emitSKPZ; // if hi word unequal
+ else
+ emitSKPNZ; // if hi word equal
+ // fail early
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(falselbl->key));
+ genc16bit2lit(left,lit,2);
+ genSkip(ifx,'z');
+ } else {
+ pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),2));
+ pic16_emitpcode(POC_IORFW,pic16_popGet(AOP(left),3));
+ genSkip(ifx,'z');
+ }
+ }
+ pic16_emitpLabel(falselbl->key);
+ break;
+
+ } // switch size
- ifx->generated = 1;
- goto release ;
+ ifx->generated = 1;
+ goto release ;
} else if(AOP_TYPE(right) == AOP_CRY ) {
if ( IC_TRUE(ifx) ) {
emitSKPNZ;
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_TRUE(ifx)->key));
- pic16_emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
+ // pic16_emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
} else {
emitSKPZ;
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(IC_FALSE(ifx)->key));
- pic16_emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
+ // pic16_emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
}
} else {
/* if they are both bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
+ DEBUGpic16_emitcode ("; ***","%s %d CASE 2",__FUNCTION__,__LINE__);
if(AOP_TYPE(right) == AOP_LIT){
unsigned long lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
if(lit == 0L){
pic16_outBitC(result);
} else {
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_emitcode ("; ***","%s %d CASE 3",__FUNCTION__,__LINE__);
gencjne(left,right,result,ifx);
/*
if(ifx)
operand *left , *result ;
int size, offset = 0, same;
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
/* rotate right with carry */
left = IC_LEFT(ic);
result=IC_RESULT(ic);
size = AOP_SIZE(result);
+ DEBUGpic16_emitcode ("; ***","%s %d size:%d same:%d",__FUNCTION__,__LINE__,size,same);
+
/* get the lsb and put it into the carry */
pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),size-1));
pic16_freeAsmop(result,NULL,ic,TRUE);
}
+#if 0
/*-----------------------------------------------------------------*/
/* AccRol - rotate left accumulator by known count */
/*-----------------------------------------------------------------*/
break;
}
}
+#endif
/*-----------------------------------------------------------------*/
/* AccLsh - left shift accumulator by known count */
static void AccLsh (int shCount)
{
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1)
- pic16_emitcode("add","a,acc");
- else
- if(shCount == 2) {
- pic16_emitcode("add","a,acc");
- pic16_emitcode("add","a,acc");
- } else {
- /* rotate left accumulator */
- AccRol(shCount);
- /* and kill the lower order bits */
- pic16_emitcode("anl","a,#0x%02x", SLMask[shCount]);
- }
+ switch(shCount){
+ case 0 :
+ return;
+ break;
+ case 1 :
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 2 :
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 3 :
+ pic16_emitpcode(POC_SWAPFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 4 :
+ pic16_emitpcode(POC_SWAPFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 5 :
+ pic16_emitpcode(POC_SWAPFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 6 :
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 7 :
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
}
+ pic16_emitpcode(POC_ANDLW,pic16_popGetLit(SLMask[shCount]));
+
}
/*-----------------------------------------------------------------*/
static void AccRsh (int shCount)
{
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1){
- CLRC;
- pic16_emitcode("rrc","a");
- } else {
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- pic16_emitcode("anl","a,#0x%02x", SRMask[shCount]);
- }
+ switch(shCount){
+ case 0 :
+ return;
+ break;
+ case 1 :
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 2 :
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 3 :
+ pic16_emitpcode(POC_SWAPFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 4 :
+ pic16_emitpcode(POC_SWAPFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 5 :
+ pic16_emitpcode(POC_SWAPFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RRNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 6 :
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
+ case 7 :
+ pic16_emitpcode(POC_RLNCFW,pic16_popCopyReg(&pic16_pc_wreg));
+ break;
}
+ pic16_emitpcode(POC_ANDLW,pic16_popGetLit(SRMask[shCount]));
}
#if 0
static void shiftL2Left2Result (operand *left, int offl,
operand *result, int offr, int shCount)
{
+ int same = pic16_sameRegs(AOP(result), AOP(left));
+ int i;
+ DEBUGpic16_emitcode ("; ***","%s %d shCount:%d same:%d offl:%d offr:%d",__FUNCTION__,__LINE__,shCount,same,offl,offr);
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if (same && (offl != offr)) { // shift bytes
+ if (offr > offl) {
+ for(i=1;i>-1;i--) {
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(result),offl+i));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),offr+i));
+ }
+ } else { // just treat as different later on
+ same = 0;
+ }
+ }
- if(pic16_sameRegs(AOP(result), AOP(left))) {
+ if(same) {
switch(shCount) {
case 0:
break;
pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
while(--shCount) {
- emitCLRC;
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
+ emitCLRC;
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
}
break;
pic16_emitpcode(POC_XORWF, pic16_popGet(AOP(result),offr));
pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offr+MSB16));
if(shCount >=5) {
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
}
break;
case 6:
pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr+MSB16));
while(--shCount) {
- emitCLRC;
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
+ emitCLRC;
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
}
break;
if(shCount == 5) {
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),offr+MSB16));
}
break;
case 6:
operand *result, int offr,
int shCount, int sign)
{
- int same=0;
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- same = pic16_sameRegs(AOP(result), AOP(left));
+ int same = pic16_sameRegs(AOP(result), AOP(left));
+ int i;
+ DEBUGpic16_emitcode ("; ***","%s %d shCount:%d same:%d sign:%d",__FUNCTION__,__LINE__,shCount,same,sign);
- if(same && ((offl + MSB16) == offr)){
- same=1;
- /* don't crash result[offr] */
- MOVA(pic16_aopGet(AOP(left),offl,FALSE,FALSE));
- pic16_emitcode("xch","a,%s", pic16_aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- }
-/* else {
- movLeft2Result(left,offl, result, offr);
- MOVA(pic16_aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
+ if (same && (offl != offr)) { // shift right bytes
+ if (offr < offl) {
+ for(i=0;i<2;i++) {
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(result),offl+i));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),offr+i));
+ }
+ } else { // just treat as different later on
+ same = 0;
+ }
}
-*/
- /* a:x >> shCount (x = lsb(result))*/
-/*
- if(sign)
- AccAXRshS( pic16_aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- else {
- AccAXRsh( pic16_aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
-*/
+
switch(shCount) {
case 0:
break;
while(--shCount) {
if(sign)
- pic16_emitpcode(POC_RLCFW,pic16_popGet(AOP(result),offr+MSB16));
+ pic16_emitpcode(POC_RLCFW,pic16_popGet(AOP(result),offr+MSB16));
else
- emitCLRC;
+ emitCLRC;
pic16_emitpcode(POC_RRCF,pic16_popGet(AOP(result),offr+MSB16));
pic16_emitpcode(POC_RRCF,pic16_popGet(AOP(result),offr));
}
operand *result, int offr, int shCount)
{
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- MOVA(pic16_aopGet(AOP(left),offl,FALSE,FALSE));
+
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),offl));
/* shift left accumulator */
AccLsh(shCount);
/* or with result */
- pic16_emitcode("orl","a,%s", pic16_aopGet(AOP(result),offr,FALSE,FALSE));
/* back to result */
- pic16_aopPut(AOP(result),"a",offr);
+ pic16_emitpcode(POC_IORWF,pic16_popGet(AOP(result),offr));
}
/*-----------------------------------------------------------------*/
operand *result, int offr, int shCount)
{
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- MOVA(pic16_aopGet(AOP(left),offl,FALSE,FALSE));
+
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),offl));
/* shift right accumulator */
AccRsh(shCount);
/* or with result */
- pic16_emitcode("orl","a,%s", pic16_aopGet(AOP(result),offr,FALSE,FALSE));
/* back to result */
- pic16_aopPut(AOP(result),"a",offr);
+ pic16_emitpcode(POC_IORWF,pic16_popGet(AOP(result),offr));
}
/*-----------------------------------------------------------------*/
{
int size;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_emitcode ("; ***","%s %d shCount:%d",__FUNCTION__,__LINE__,shCount);
size = pic16_getDataSize(result);
/* if shCount >= 8 */
/*-----------------------------------------------------------------*/
/* shiftLLong - shift left one long from left to result */
-/* offl = LSB or MSB16 */
+/* offr = LSB or MSB16 */
/*-----------------------------------------------------------------*/
static void shiftLLong (operand *left, operand *result, int offr )
{
- char *l;
int size = AOP_SIZE(result);
+ int same = pic16_sameRegs(AOP(left),AOP(result));
+ int i;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(size >= LSB+offr){
- l = pic16_aopGet(AOP(left),LSB,FALSE,FALSE);
- MOVA(l);
- pic16_emitcode("add","a,acc");
- if (pic16_sameRegs(AOP(left),AOP(result)) &&
- size >= MSB16+offr && offr != LSB )
- pic16_emitcode("xch","a,%s",
- pic16_aopGet(AOP(left),LSB+offr,FALSE,FALSE));
- else
- pic16_aopPut(AOP(result),"a",LSB+offr);
- }
+ DEBUGpic16_emitcode ("; ***","%s %d offr:%d size:%d",__FUNCTION__,__LINE__,offr,size);
- if(size >= MSB16+offr){
- if (!(pic16_sameRegs(AOP(result),AOP(left)) && size >= MSB16+offr && offr != LSB) ) {
- l = pic16_aopGet(AOP(left),MSB16,FALSE,FALSE);
- MOVA(l);
+ if (same && (offr == MSB16)) { //shift one byte
+ for(i=size-1;i>=MSB16;i--) {
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),i-1));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(left),i));
+ }
+ } else {
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),LSB+offr));
}
- pic16_emitcode("rlc","a");
- if (pic16_sameRegs(AOP(left),AOP(result)) &&
- size >= MSB24+offr && offr != LSB)
- pic16_emitcode("xch","a,%s",
- pic16_aopGet(AOP(left),MSB16+offr,FALSE,FALSE));
- else
- pic16_aopPut(AOP(result),"a",MSB16+offr);
+
+ if (size >= LSB+offr ){
+ if (same) {
+ pic16_emitpcode(POC_ADDWF,pic16_popGet(AOP(left),LSB+offr));
+ } else {
+ pic16_emitpcode(POC_ADDFW,pic16_popGet(AOP(left),LSB));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),LSB+offr));
+ }
+ }
+
+ if(size >= MSB16+offr){
+ if (same) {
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(left),MSB16+offr));
+ } else {
+ pic16_emitpcode(POC_RLCFW, pic16_popGet(AOP(left),MSB16));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),MSB16+offr));
+ }
}
if(size >= MSB24+offr){
- if (!(pic16_sameRegs(AOP(left),AOP(left)) && size >= MSB24+offr && offr != LSB)) {
- l = pic16_aopGet(AOP(left),MSB24,FALSE,FALSE);
- MOVA(l);
- }
- pic16_emitcode("rlc","a");
- if (pic16_sameRegs(AOP(left),AOP(result)) &&
- size >= MSB32+offr && offr != LSB )
- pic16_emitcode("xch","a,%s",
- pic16_aopGet(AOP(left),MSB24+offr,FALSE,FALSE));
- else
- pic16_aopPut(AOP(result),"a",MSB24+offr);
+ if (same) {
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(left),MSB24+offr));
+ } else {
+ pic16_emitpcode(POC_RLCFW, pic16_popGet(AOP(left),MSB24));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),MSB24+offr));
+ }
}
if(size > MSB32+offr){
- if (!(pic16_sameRegs(AOP(result),AOP(left)) && size >= MSB32+offr && offr != LSB)) {
- l = pic16_aopGet(AOP(left),MSB32,FALSE,FALSE);
- MOVA(l);
- }
- pic16_emitcode("rlc","a");
- pic16_aopPut(AOP(result),"a",MSB32+offr);
+ if (same) {
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(left),MSB32+offr));
+ } else {
+ pic16_emitpcode(POC_RLCFW, pic16_popGet(AOP(left),MSB32));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),MSB32+offr));
+ }
}
if(offr != LSB)
- pic16_aopPut(AOP(result),zero,LSB);
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),LSB));
+
}
/*-----------------------------------------------------------------*/
shiftL1Left2Result(left, LSB, result, MSB32, shCount);
else
movLeft2Result(left, LSB, result, MSB32);
- pic16_aopPut(AOP(result),zero,LSB);
- pic16_aopPut(AOP(result),zero,MSB16);
- pic16_aopPut(AOP(result),zero,MSB32);
+
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),LSB));
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),MSB16));
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),MSB24));
+
return;
}
movLeft2Result(left, MSB16, result, MSB32);
movLeft2Result(left, LSB, result, MSB24);
}
- pic16_aopPut(AOP(result),zero,MSB16);
- pic16_aopPut(AOP(result),zero,LSB);
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),LSB));
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),MSB16));
return;
}
movLeft2Result(left, MSB24, result, MSB32);
movLeft2Result(left, MSB16, result, MSB24);
movLeft2Result(left, LSB, result, MSB16);
- pic16_aopPut(AOP(result),zero,LSB);
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),LSB));
}
else if(shCount == 1)
shiftLLong(left, result, MSB16);
shiftL2Left2Result(left, MSB16, result, MSB24, shCount);
shiftL1Left2Result(left, LSB, result, MSB16, shCount);
shiftRLeftOrResult(left, LSB, result, MSB24, 8 - shCount);
- pic16_aopPut(AOP(result),zero,LSB);
+ pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),LSB));
}
}
}
/* 1 <= shCount <= 7 */
- else if(shCount <= 2){
+ else if(shCount <= 3)
+ {
shiftLLong(left, result, LSB);
- if(shCount == 2)
+ while(--shCount >= 1)
shiftLLong(result, result, LSB);
}
/* 3 <= shCount <= 7, optimize */
int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
int size;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_emitcode ("; ***","%s %d shCount:%d",__FUNCTION__,__LINE__,shCount);
pic16_freeAsmop(right,NULL,ic,TRUE);
pic16_aopOp(left,ic,FALSE);
tlbl = newiTempLabel(NULL);
if (!pic16_sameRegs(AOP(left),AOP(result))) {
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
}
pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(right),0));
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
/* offset should be 0, 1 or 3 */
- pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x07 + ((offset&3) << 3)));
+
+ pic16_emitpcode(POC_ANDLW, pic16_popGetLit((size<<3)-1));
emitSKPNZ;
pic16_emitpcode(POC_GOTO, pic16_popGetLabel(tlbl1->key));
static void genrshTwo (operand *result,operand *left,
int shCount, int sign)
{
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_emitcode ("; ***","%s %d shCount:%d",__FUNCTION__,__LINE__,shCount);
/* if shCount >= 8 */
if (shCount >= 8) {
shCount -= 8 ;
static void shiftRLong (operand *left, int offl,
operand *result, int sign)
{
+ int size = AOP_SIZE(result);
+ int same = pic16_sameRegs(AOP(left),AOP(result));
+ int i;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!sign)
- pic16_emitcode("clr","c");
- MOVA(pic16_aopGet(AOP(left),MSB32,FALSE,FALSE));
+
+ DEBUGpic16_emitcode ("; ***","%s %d offl:%d size:%d",__FUNCTION__,__LINE__,offl,size);
+
+ if (same && (offl == MSB16)) { //shift one byte right
+ for(i=MSB16;i<size;i++) {
+ pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),i));
+ pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(left),i-1));
+ }
+ }
+
if(sign)
- pic16_emitcode("mov","c,acc.7");
- pic16_emitcode("rrc","a");
- pic16_aopPut(AOP(result),"a",MSB32-offl);
- if(offl == MSB16)
+ pic16_emitpcode(POC_RLCFW,pic16_popGet(AOP(left),MSB32));
+ else
+ emitCLRC;
+
+ if (same) {
+ if (offl == LSB)
+ pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(left),MSB32));
+ } else {
+ pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),MSB32));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),MSB32-offl));
+ }
+
+ if(offl == MSB16) {
/* add sign of "a" */
pic16_addSign(result, MSB32, sign);
+ }
- MOVA(pic16_aopGet(AOP(left),MSB24,FALSE,FALSE));
- pic16_emitcode("rrc","a");
- pic16_aopPut(AOP(result),"a",MSB24-offl);
-
- MOVA(pic16_aopGet(AOP(left),MSB16,FALSE,FALSE));
- pic16_emitcode("rrc","a");
- pic16_aopPut(AOP(result),"a",MSB16-offl);
+ if (same) {
+ pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(left),MSB24));
+ } else {
+ pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),MSB24));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),MSB24-offl));
+ }
+
+ if (same) {
+ pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(left),MSB16));
+ } else {
+ pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),MSB16));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),MSB16-offl));
+ }
- if(offl == LSB){
- MOVA(pic16_aopGet(AOP(left),LSB,FALSE,FALSE));
- pic16_emitcode("rrc","a");
- pic16_aopPut(AOP(result),"a",LSB);
- }
+ if (same) {
+ pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(left),LSB));
+ } else {
+ if(offl == LSB){
+ pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),LSB));
+ pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),LSB));
+ }
+ }
}
/*-----------------------------------------------------------------*/
movLeft2Result(left, MSB32, result, MSB24);
pic16_addSign(result, MSB32, sign);
}
- else{
+ else{ //shcount >= 2
shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
/* the last shift is signed */
int shCount = (int) floatFromVal (AOP(right)->aopu.aop_lit);
int lsize,res_size;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
pic16_freeAsmop(right,NULL,ic,TRUE);
pic16_aopOp(left,ic,FALSE);
pic16_aopOp(result,ic,FALSE);
+ DEBUGpic16_emitcode ("; ***","%s %d shCount:%d result:%d left:%d",__FUNCTION__,__LINE__,shCount,AOP_SIZE(result),AOP_SIZE(left));
+
#if VIEW_SIZE
pic16_emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
AOP_SIZE(left));
static void genRightShift (iCode *ic)
{
operand *right, *left, *result;
- sym_link *retype ;
+ sym_link *letype ;
int size, offset;
char *l;
symbol *tlbl, *tlbl1 ;
/* if signed then we do it the hard way preserve the
sign bit moving it inwards */
- retype = getSpec(operandType(IC_RESULT(ic)));
+ letype = getSpec(operandType(IC_LEFT(ic)));
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if (!SPEC_USIGN(retype)) {
+ if (!SPEC_USIGN(letype)) {
genSignedRightShift (ic);
return ;
}
pic16_aopOp (result,ic,FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genUnpackBits (result,rname,POINTER);
else {
/* we have can just get the values */
pic16_aopOp (result,ic,FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genUnpackBits (result,rname,PPOINTER);
else {
/* we have can just get the values */
pic16_aopOp(result,ic,FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genUnpackBits(result,"dptr",FPOINTER);
else {
size = AOP_SIZE(result);
pic16_aopOp(result,ic,FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genUnpackBits(result,"dptr",CPOINTER);
else {
size = AOP_SIZE(result);
/* so dptr know contains the address */
/* if bit then unpack */
- //if (IS_BITVAR(retype))
- // genUnpackBits(result,"dptr",GPOINTER);
+ if (IS_BITFIELD(retype))
+ genUnpackBits(result,"BAD",GPOINTER);
release:
pic16_freeAsmop(left,NULL,ic,TRUE);
goto release;
}// else
- // rname = pic16_aopGet(AOP(result),0,FALSE,FALSE);
+// rname = pic16_aopGet(AOP(result),0,FALSE,FALSE);
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype)) {
+ if (IS_BITFIELD(retype)) {
werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
"The programmer is obviously confused");
- //genPackBits (retype,right,rname,POINTER);
+// genPackBits (retype,right,"BAD",POINTER);
exit(1);
}
else {
pic16_aopOp (right,ic,FALSE);
/* if bitfield then unpack the bits */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genPackBits (retype,right,rname,PPOINTER);
else {
/* we have can just get the values */
pic16_aopOp(right,ic,FALSE);
/* if bit then unpack */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genPackBits(retype,right,"dptr",FPOINTER);
else {
size = AOP_SIZE(right);
/* if bit then unpack */
- if (IS_BITVAR(retype))
+ if (IS_BITFIELD(retype))
genPackBits(retype,right,"dptr",GPOINTER);
else {
size = AOP_SIZE(right);
if(options.iCodeInAsm) {
/* insert here code to print iCode as comment */
+ pic16_emitcomment("; ic:%d: %s", ic->seq, printILine(ic));
}
/* if the result is marked as
break;
case SEND:
- DEBUGpic16_emitcode(";ic ", "\t%c 0x%x\tSEND",ic->op, ic->op);
-
addSet(&_G.sendSet,ic);
break;