+ size = AOP_SIZE(right) - 1;
+ mask = (0x100UL << (size*8)) - 1;
+ // in the end CARRY holds "left < right" (performedLt == 1) or "left >= right" (performedLt == 0)
+ performedLt = 1;
+ templbl = NULL;
+ lit = 0;
+
+ resolveIfx (&rIfx, ifx);
+
+ /**********************************************************************
+ * handle bits - bit compares are promoted to int compares seemingly! *
+ **********************************************************************/
+#if 0
+ // THIS IS COMPLETELY UNTESTED!
+ if (AOP_TYPE(left) == AOP_CRY && AOP_TYPE(right) == AOP_CRY) {
+ pCodeOp *pcleft = pic16_popGet(AOP(left), 0);
+ pCodeOp *pcright = pic16_popGet(AOP(right), 0);
+ assert (pcleft->type == PO_GPR_BIT && pcright->type == PO_GPR_BIT);
+
+ emitSETC;
+ // 1 < {0,1} is false --> clear C by skipping the next instruction
+ //pic16_emitpcode (POC_BTFSS, pic16_popCopyGPR2Bit (AOP(left),0), PCORB(pcleft)->bit);
+ pic16_emitpcode (POC_BTFSS, pic16_popGet (AOP(left), 0));
+ // {0,1} < 0 is false --> clear C by NOT skipping the next instruction
+ pic16_emitpcode (POC_BTFSS, pic16_popCopyGPR2Bit (pic16_popGet(AOP(right),0), PCORB(pcright)->bit));
+ emitCLRC; // only skipped for left=0 && right=1
+
+ goto correct_result_in_carry;
+ } // if
+#endif
+
+ /*************************************************
+ * make sure that left is register (or the like) *
+ *************************************************/
+ if (!isAOP_REGlike(left)) {
+ DEBUGpc ("swapping arguments (AOP_TYPEs %d/%d)", AOP_TYPE(left), AOP_TYPE(right));
+ assert (isAOP_LIT(left));
+ assert (isAOP_REGlike(right));
+ // swap left and right
+ // left < right <==> right > left <==> (right >= left + 1)
+ lit = ulFromVal(AOP(left)->aopu.aop_lit);
+
+ if ( (!sign && (lit & mask) == mask) || (sign && (lit & mask) == (mask >> 1)) ) {
+ // MAXVALUE < right? always false
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ } // if
+
+ // This fails for lit = 0xFF (unsigned) AND lit = 0x7F (signed),
+ // that's why we handled it above.
+ lit++;
+
+ dummy = left;
+ left = right;
+ right = dummy;
+
+ performedLt ^= 1; // instead of "left < right" we check for "right >= left+1, i.e. "right < left+1"
+ } else if (isAOP_LIT(right)) {
+ lit = ulFromVal(AOP(right)->aopu.aop_lit);
+ } // if
+
+ assert (isAOP_REGlike(left)); // left must be register or the like
+ assert (isAOP_REGlike(right) || isAOP_LIT(right)); // right may be register-like or a literal
+
+ /*************************************************
+ * special cases go here *
+ *************************************************/
+
+ if (isAOP_LIT(right)) {
+ if (!sign) {
+ // unsigned comparison to a literal
+ DEBUGpc ("unsigned compare: left %s lit(0x%X=%lu), size=%d", performedLt ? "<" : ">=", lit, lit, size+1);
+ if (lit == 0) {
+ // unsigned left < 0? always false
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ }
+ } else {
+ // signed comparison to a literal
+ DEBUGpc ("signed compare: left %s lit(0x%X=%ld), size=%d, mask=%x", performedLt ? "<" : ">=", lit, lit, size+1, mask);
+ if ((lit & mask) == ((0x80 << (size*8)) & mask)) {
+ // signed left < 0x80000000? always false
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ } else if (lit == 0) {
+ // compare left < 0; set CARRY if SIGNBIT(left) is set
+ if (performedLt) emitSETC; else emitCLRC;
+ emitpcode (POC_BTFSS, newpCodeOpBit (aopGet (AOP(left), size, FALSE, FALSE), 7, 0));
+ if (performedLt) emitCLRC; else emitSETC;
+ goto correct_result_in_carry;
+ }
+ } // if (!sign)
+ } // right is literal
+
+ /*************************************************
+ * perform a general case comparison *
+ * make sure we get CARRY==1 <==> left >= right *
+ *************************************************/
+ // compare most significant bytes
+ //DEBUGpc ("comparing bytes at offset %d", size);
+ if (!sign) {
+ // unsigned comparison
+ pic14_mov2w_regOrLit (AOP(right), lit, size);
+ emitpcode (POC_SUBFW, popGet (AOP(left), size));
+ } else {
+ // signed comparison
+ // (add 2^n to both operands then perform an unsigned comparison)
+ if (isAOP_LIT(right)) {
+ // left >= LIT <-> LIT-left <= 0 <-> LIT-left == 0 OR !(LIT-left >= 0)
+ unsigned char litbyte = (lit >> (8*size)) & 0xFF;
+
+ if (litbyte == 0x80) {
+ // left >= 0x80 -- always true, but more bytes to come
+ mov2w (AOP(left), size);
+ emitpcode (POC_XORLW, popGetLit (0x80)); // set ZERO flag
+ emitSETC;
+ } else {
+ // left >= LIT <-> left + (-LIT) >= 0 <-> left + (0x100-LIT) >= 0x100
+ mov2w (AOP(left), size);
+ emitpcode (POC_ADDLW, popGetLit (0x80));
+ emitpcode (POC_ADDLW, popGetLit ((0x100 - (litbyte + 0x80)) & 0x00FF));
+ } // if
+ } else {
+ pCodeOp *pctemp = popGetTempReg();
+ mov2w (AOP(left), size);
+ emitpcode (POC_ADDLW, popGetLit (0x80));
+ emitpcode (POC_MOVWF, pctemp);
+ mov2w (AOP(right), size);
+ emitpcode (POC_ADDLW, popGetLit (0x80));
+ emitpcode (POC_SUBFW, pctemp);
+ popReleaseTempReg(pctemp);
+ }
+ } // if (!sign)
+
+ // compare remaining bytes (treat as unsigned case from above)
+ templbl = newiTempLabel ( NULL );
+ offs = size;
+ while (offs--) {
+ //DEBUGpc ("comparing bytes at offset %d", offs);
+ emitSKPZ;
+ emitpcode (POC_GOTO, popGetLabel (templbl->key));
+ pic14_mov2w_regOrLit (AOP(right), lit, offs);
+ emitpcode (POC_SUBFW, popGet (AOP(left), offs));
+ } // while (offs)
+ emitpLabel (templbl->key);
+ goto result_in_carry;
+
+result_in_carry:
+
+ /****************************************************
+ * now CARRY contains the result of the comparison: *
+ * SUBWF sets CARRY iff *
+ * F-W >= 0 <==> F >= W <==> !(F < W) *
+ * (F=left, W=right) *
+ ****************************************************/
+
+ if (performedLt) {
+ invert_result = 1;
+ // value will be used in the following genSkipc()
+ rIfx.condition ^= 1;
+ } // if
+
+correct_result_in_carry:
+
+ // assign result to variable (if neccessary)
+ if (result && AOP_TYPE(result) != AOP_CRY) {
+ //DEBUGpc ("assign result");
+ size = AOP_SIZE(result);
+ while (size--) {
+ emitpcode (POC_CLRF, popGet (AOP(result), size));
+ } // while
+ if (invert_result) {
+ emitSKPC;
+ emitpcode (POC_BSF, newpCodeOpBit (aopGet (AOP(result), 0, FALSE, FALSE), 0, 0));
+ } else {
+ emitpcode (POC_RLF, popGet (AOP(result), 0));
+ }
+ } // if (result)
+
+ // perform conditional jump
+ if (ifx) {
+ //DEBUGpc ("generate control flow");
+ genSkipc (&rIfx);
+ ifx->generated = 1;
+ } // if
+}
+
+
+#if 0
+/* OLD VERSION -- BUGGY, DO NOT USE */
+
+/*-----------------------------------------------------------------*/
+/* genCmp :- greater or less than comparison */
+/*-----------------------------------------------------------------*/
+static void genCmp (operand *left,operand *right,
+ operand *result, iCode *ifx, int sign)
+{
+ int size; //, offset = 0 ;
+ unsigned long lit = 0L,i = 0;
+ resolvedIfx rFalseIfx;
+ // resolvedIfx rTrueIfx;
+ symbol *truelbl;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /*
+ if(ifx) {
+ DEBUGpic14_emitcode ("; ***","true ifx is %s",((IC_TRUE(ifx) == NULL) ? "false" : "true"));
+ DEBUGpic14_emitcode ("; ***","false ifx is %s",((IC_FALSE(ifx) == NULL) ? "false" : "true"));
+ }
+ */
+
+ resolveIfx(&rFalseIfx,ifx);
+ truelbl = newiTempLabel(NULL);
+ size = max(AOP_SIZE(left),AOP_SIZE(right));
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+#define _swapp
+
+ /* if literal is on the right then swap with left */
+ if ((AOP_TYPE(right) == AOP_LIT)) {
+ operand *tmp = right ;
+ unsigned long mask = (0x100 << (8*(size-1))) - 1;
+ lit = ulFromVal(AOP(right)->aopu.aop_lit);
+#ifdef _swapp
+
+ lit = (lit - 1) & mask;
+ right = left;
+ left = tmp;
+ rFalseIfx.condition ^= 1;
+#endif
+
+ } else if ((AOP_TYPE(left) == AOP_LIT)) {
+ lit = ulFromVal(AOP(left)->aopu.aop_lit);
+ }
+
+
+ //if(IC_TRUE(ifx) == NULL)
+ /* if left & right are bit variables */
+ if (AOP_TYPE(left) == AOP_CRY &&
+ AOP_TYPE(right) == AOP_CRY ) {
+ pic14_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
+ pic14_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
+ } else {
+ /* subtract right from left if at the
+ end the carry flag is set then we know that
+ left is greater than right */
+
+ symbol *lbl = newiTempLabel(NULL);
+
+#ifndef _swapp
+ if(AOP_TYPE(right) == AOP_LIT) {
+
+ //lit = ulFromVal(AOP(right)->aopu.aop_lit);
+
+ DEBUGpic14_emitcode(";right lit","lit = 0x%x,sign=%d",lit,sign);
+
+ /* special cases */
+
+ if(lit == 0) {
+
+ if(sign != 0)
+ genSkipCond(&rFalseIfx,left,size-1,7);
+ else
+ /* no need to compare to 0...*/
+ /* NOTE: this is a de-generate compare that most certainly
+ * creates some dead code. */
+ emitpcode(POC_GOTO,popGetLabel(rFalseIfx.lbl->key));
+
+ if(ifx) ifx->generated = 1;
+ return;
+
+ }
+ size--;
+
+ if(size == 0) {
+ //i = (lit >> (size*8)) & 0xff;
+ DEBUGpic14_emitcode(";right lit","line = %d",__LINE__);
+
+ emitpcode(POC_MOVFW, popGet(AOP(left),size));
+
+ i = ((0-lit) & 0xff);
+ if(sign) {
+ if( i == 0x81) {
+ /* lit is 0x7f, all signed chars are less than
+ * this except for 0x7f itself */
+ emitpcode(POC_XORLW, popGetLit(0x7f));
+ genSkipz2(&rFalseIfx,0);
+ } else {
+ emitpcode(POC_ADDLW, popGetLit(0x80));
+ emitpcode(POC_ADDLW, popGetLit(i^0x80));
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ }
+
+ } else {
+ if(lit == 1) {
+ genSkipz2(&rFalseIfx,1);
+ } else {
+ emitpcode(POC_ADDLW, popGetLit(i));
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ }
+ }
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ /* chars are out of the way. now do ints and longs */
+
+
+ DEBUGpic14_emitcode(";right lit","line = %d",__LINE__);
+
+ /* special cases */
+
+ if(sign) {
+
+ if(lit == 0) {
+ genSkipCond(&rFalseIfx,left,size,7);
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if(lit <0x100) {
+ DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
+
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,left,size,7);
+ //rFalseIfx.condition ^= 1;
+
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+ emitpcode(POC_MOVLW, popGetLit(0x100-lit));
+ emitpcode(POC_ADDFW, popGet(AOP(left),0));
+ emitpcode(POC_MOVFW, popGet(AOP(left),1));
+
+ while(size > 1)
+ emitpcode(POC_IORFW, popGet(AOP(left),size--));
+
+ if(rFalseIfx.condition) {
+ emitSKPZ;
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+ } else {
+ emitSKPNZ;
+ }
+
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ emitpLabel(truelbl->key);
+ if(ifx) ifx->generated = 1;
+ return;
+
+ }
+
+ if(size == 1) {
+
+ if( (lit & 0xff) == 0) {
+ /* lower byte is zero */
+ DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
+ i = ((lit >> 8) & 0xff) ^0x80;
+ emitpcode(POC_MOVFW, popGet(AOP(left),size));
+ emitpcode(POC_ADDLW, popGetLit( 0x80));
+ emitpcode(POC_ADDLW, popGetLit(0x100-i));
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+
+
+ if(ifx) ifx->generated = 1;
+ return;
+
+ }
+ } else {
+ /* Special cases for signed longs */
+ if( (lit & 0xffffff) == 0) {
+ /* lower byte is zero */
+ DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
+ i = ((lit >> 8*3) & 0xff) ^0x80;
+ emitpcode(POC_MOVFW, popGet(AOP(left),size));
+ emitpcode(POC_ADDLW, popGetLit( 0x80));
+ emitpcode(POC_ADDLW, popGetLit(0x100-i));
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+
+
+ if(ifx) ifx->generated = 1;
+ return;
+
+ }
+
+ }
+
+
+ if(lit & (0x80 << (size*8))) {
+ /* lit is negative */
+ DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
+
+ //genSkipCond(&rFalseIfx,left,size,7);
+
+ emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+
+
+ } else {
+ /* lit is positive */
+ DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+ }
+
+ /* There are no more special cases, so perform a general compare */
+
+ emitpcode(POC_MOVLW, popGetLit((lit >> (size*8)) & 0xff));
+ emitpcode(POC_SUBFW, popGet(AOP(left),size));
+
+ while(size--) {
+
+ emitpcode(POC_MOVLW, popGetLit((lit >> (size*8)) & 0xff));
+ emitSKPNZ;
+ emitpcode(POC_SUBFW, popGet(AOP(left),size));
+ }
+ //rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+
+ emitpLabel(truelbl->key);
+
+ if(ifx) ifx->generated = 1;
+ return;
+
+
+ }
+
+
+ /* sign is out of the way. So now do an unsigned compare */
+ DEBUGpic14_emitcode(";right lit","line = %d unsigned compare to 0x%x",__LINE__,lit);
+
+
+ /* General case - compare to an unsigned literal on the right.*/
+
+ i = (lit >> (size*8)) & 0xff;
+ emitpcode(POC_MOVLW, popGetLit(i));
+ emitpcode(POC_SUBFW, popGet(AOP(left),size));
+ while(size--) {
+ i = (lit >> (size*8)) & 0xff;
+
+ if(i) {
+ emitpcode(POC_MOVLW, popGetLit(i));
+ emitSKPNZ;
+ emitpcode(POC_SUBFW, popGet(AOP(left),size));
+ } else {
+ /* this byte of the lit is zero,
+ *if it's not the last then OR in the variable */
+ if(size)
+ emitpcode(POC_IORFW, popGet(AOP(left),size));
+ }
+ }
+
+
+ emitpLabel(lbl->key);
+ //if(emitFinalCheck)
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ if(sign)
+ emitpLabel(truelbl->key);
+
+ if(ifx) ifx->generated = 1;
+ return;
+
+
+ }
+#endif // _swapp
+
+ if(AOP_TYPE(left) == AOP_LIT) {
+ //symbol *lbl = newiTempLabel(NULL);
+
+ //EXPERIMENTAL lit = ulFromVal(AOP(left)->aopu.aop_lit);
+
+
+ DEBUGpic14_emitcode(";left lit","lit = 0x%x,sign=%d",lit,sign);
+
+ /* Special cases */
+ if((lit == 0) && (sign == 0)){
+
+ size--;
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ while(size)
+ emitpcode(POC_IORFW, popGet(AOP(right),--size));
+
+ genSkipz2(&rFalseIfx,0);
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if(size==1) {
+ /* Special cases */
+ lit &= 0xff;
+ if(((lit == 0xff) && !sign) || ((lit==0x7f) && sign)) {
+ /* degenerate compare can never be true */
+ if(rFalseIfx.condition == 0)
+ emitpcode(POC_GOTO,popGetLabel(rFalseIfx.lbl->key));
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if(sign) {
+ /* signed comparisons to a literal byte */
+
+ int lp1 = (lit+1) & 0xff;
+
+ DEBUGpic14_emitcode(";left lit","line = %d lit = 0x%x",__LINE__,lit);
+ switch (lp1) {
+ case 0:
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,0,7);
+ break;
+ case 0x7f:
+ emitpcode(POC_MOVFW, popGet(AOP(right),0));
+ emitpcode(POC_XORLW, popGetLit(0x7f));
+ genSkipz2(&rFalseIfx,1);
+ break;
+ default:
+ emitpcode(POC_MOVFW, popGet(AOP(right),0));
+ emitpcode(POC_ADDLW, popGetLit(0x80));
+ emitpcode(POC_ADDLW, popGetLit(((0-(lit+1)) & 0xff) ^ 0x80));
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ break;
+ }
+ if(ifx) ifx->generated = 1;
+ } else {
+ /* unsigned comparisons to a literal byte */
+
+ switch(lit & 0xff ) {
+ case 0:
+ emitpcode(POC_MOVFW, popGet(AOP(right),0));
+ genSkipz2(&rFalseIfx,0);
+ if(ifx) ifx->generated = 1;
+ break;
+ case 0x7f:
+ genSkipCond(&rFalseIfx,right,0,7);
+ if(ifx) ifx->generated = 1;
+ break;
+
+ default:
+ emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
+ emitpcode(POC_SUBFW, popGet(AOP(right),0));
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ rFalseIfx.condition ^= 1;
+ if (AOP_TYPE(result) == AOP_CRY) {
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ if(ifx) ifx->generated = 1;
+ } else {
+ DEBUGpic14_emitcode ("; ***","%s %d RFIfx.cond=%d",__FUNCTION__,__LINE__, rFalseIfx.condition);
+ emitpcode(POC_CLRF, popGet(AOP(result),0));
+ emitpcode(POC_RLF, popGet(AOP(result),0));
+ emitpcode(POC_MOVLW, popGetLit(0x01));
+ emitpcode(POC_XORWF, popGet(AOP(result),0));
+ }
+ break;
+ }
+ }
+
+ //goto check_carry;
+ return;
+
+ } else {
+
+ /* Size is greater than 1 */
+
+ if(sign) {
+ int lp1 = lit+1;
+
+ size--;
+
+ if(lp1 == 0) {
+ /* this means lit = 0xffffffff, or -1 */
+
+
+ DEBUGpic14_emitcode(";left lit = -1","line = %d ",__LINE__);
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,size,7);
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if(lit == 0) {
+ int s = size;
+
+ if(rFalseIfx.condition) {
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ }
+
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ while(size--)
+ emitpcode(POC_IORFW, popGet(AOP(right),size));
+
+
+ emitSKPZ;
+ if(rFalseIfx.condition) {
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ emitpLabel(truelbl->key);
+ }else {
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,s,7);
+ }
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if((size == 1) && (0 == (lp1&0xff))) {
+ /* lower byte of signed word is zero */
+ DEBUGpic14_emitcode(";left lit","line = %d 0x%x+1 low byte is zero",__LINE__,lit);
+ i = ((lp1 >> 8) & 0xff) ^0x80;
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ emitpcode(POC_ADDLW, popGetLit( 0x80));
+ emitpcode(POC_ADDLW, popGetLit(0x100-i));
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if(lit & (0x80 << (size*8))) {
+ /* Lit is less than zero */
+ DEBUGpic14_emitcode(";left lit","line = %d 0x%x is less than 0",__LINE__,lit);
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,left,size,7);
+ //rFalseIfx.condition ^= 1;
+ emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ //emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+
+ } else {
+ /* Lit is greater than or equal to zero */
+ DEBUGpic14_emitcode(";left lit","line = %d 0x%x is greater than 0",__LINE__,lit);
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,right,size,7);
+ //rFalseIfx.condition ^= 1;
+
+ //emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ //emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+
+ }
+
+
+ emitpcode(POC_MOVLW, popGetLit((lp1 >> (size*8)) & 0xff));
+ emitpcode(POC_SUBFW, popGet(AOP(right),size));
+
+ while(size--) {
+
+ emitpcode(POC_MOVLW, popGetLit((lp1 >> (size*8)) & 0xff));
+ emitSKPNZ;
+ emitpcode(POC_SUBFW, popGet(AOP(right),size));
+ }
+ rFalseIfx.condition ^= 1;
+ //rFalseIfx.condition = 1;
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+
+ emitpLabel(truelbl->key);
+
+ if(ifx) ifx->generated = 1;
+ return;
+ // end of if (sign)
+ } else {
+
+ /* compare word or long to an unsigned literal on the right.*/
+
+
+ size--;
+ if(lit < 0xff) {
+ DEBUGpic14_emitcode ("; ***","%s %d lit =0x%x < 0xff",__FUNCTION__,__LINE__,lit);
+ switch (lit) {
+ case 0:
+ break; /* handled above */
+ /*
+ case 0xff:
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ while(size--)
+ emitpcode(POC_IORFW, popGet(AOP(right),size));
+ genSkipz2(&rFalseIfx,0);
+ break;
+ */
+ default:
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ while(--size)
+ emitpcode(POC_IORFW, popGet(AOP(right),size));
+
+ emitSKPZ;
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+
+ emitpcode(POC_MOVLW, popGetLit(lit+1));
+ emitpcode(POC_SUBFW, popGet(AOP(right),0));
+
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ }
+
+ emitpLabel(truelbl->key);
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+
+ lit++;
+ DEBUGpic14_emitcode ("; ***","%s %d lit =0x%x",__FUNCTION__,__LINE__,lit);
+ i = (lit >> (size*8)) & 0xff;
+
+ emitpcode(POC_MOVLW, popGetLit(i));
+ emitpcode(POC_SUBFW, popGet(AOP(right),size));
+
+ while(size--) {
+ i = (lit >> (size*8)) & 0xff;
+
+ if(i) {
+ emitpcode(POC_MOVLW, popGetLit(i));
+ emitSKPNZ;
+ emitpcode(POC_SUBFW, popGet(AOP(right),size));
+ } else {
+ /* this byte of the lit is zero,
+ *if it's not the last then OR in the variable */
+ if(size)
+ emitpcode(POC_IORFW, popGet(AOP(right),size));
+ }
+ }
+
+
+ emitpLabel(lbl->key);
+
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ }
+
+ if(sign)
+ emitpLabel(truelbl->key);
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+ }
+ /* Compare two variables */
+
+ DEBUGpic14_emitcode(";sign","%d",sign);
+
+ size--;
+ if(sign) {
+ /* Sigh. thus sucks... */
+ if(size) {
+ emitpcode(POC_MOVFW, popGet(AOP(left),size));
+ emitpcode(POC_MOVWF, popRegFromIdx(Gstack_base_addr));
+ emitpcode(POC_MOVLW, popGetLit(0x80));
+ emitpcode(POC_XORWF, popRegFromIdx(Gstack_base_addr));
+ emitpcode(POC_XORFW, popGet(AOP(right),size));
+ emitpcode(POC_SUBFW, popRegFromIdx(Gstack_base_addr));
+ } else {
+ /* Signed char comparison */
+ /* Special thanks to Nikolai Golovchenko for this snippet */
+ emitpcode(POC_MOVFW, popGet(AOP(right),0));
+ emitpcode(POC_SUBFW, popGet(AOP(left),0));
+ emitpcode(POC_RRFW, popGet(AOP(left),0)); /* could be any register */
+ emitpcode(POC_XORFW, popGet(AOP(left),0));
+ emitpcode(POC_XORFW, popGet(AOP(right),0));
+ emitpcode(POC_ADDLW, popGetLit(0x80));
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ } else {
+
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ emitpcode(POC_SUBFW, popGet(AOP(left),size));
+ }
+
+
+ /* The rest of the bytes of a multi-byte compare */
+ while (size) {
+
+ emitSKPZ;
+ emitpcode(POC_GOTO, popGetLabel(lbl->key));
+ size--;
+
+ emitpcode(POC_MOVFW, popGet(AOP(right),size));
+ emitpcode(POC_SUBFW, popGet(AOP(left),size));
+
+
+ }
+
+ emitpLabel(lbl->key);
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if ((AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) ||
+ (AOP_TYPE(result) == AOP_REG)) {
+ emitpcode(POC_CLRF, popGet(AOP(result),0));
+ emitpcode(POC_RLF, popGet(AOP(result),0));
+ } else {
+ genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ }
+ //genSkipc(&rFalseIfx); assert ( !"genSkipc should have inverse logic" );
+ if(ifx) ifx->generated = 1;
+
+ return;
+
+ }
+
+ // check_carry:
+ if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ pic14_outBitC(result);
+ } else {
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* if the result is used in the next
+ ifx conditional branch then generate
+ code a little differently */
+ if (ifx )
+ genIfxJump (ifx,"c");
+ else
+ pic14_outBitC(result);
+ /* leave the result in acc */
+ }
+
+}
+#endif
+
+/*-----------------------------------------------------------------*/
+/* genCmpGt :- greater than comparison */
+/*-----------------------------------------------------------------*/
+static void genCmpGt (iCode *ic, iCode *ifx)
+{
+ operand *left, *right, *result;
+ sym_link *letype , *retype;
+ int sign ;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ left = IC_LEFT(ic);
+ right= IC_RIGHT(ic);
+ result = IC_RESULT(ic);
+
+ letype = getSpec(operandType(left));
+ retype =getSpec(operandType(right));
+ sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+ /* assign the amsops */
+ aopOp (left,ic,FALSE);
+ aopOp (right,ic,FALSE);
+ aopOp (result,ic,TRUE);
+
+ genCmp(right, left, result, ifx, sign);
+
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genCmpLt - less than comparisons */
+/*-----------------------------------------------------------------*/
+static void genCmpLt (iCode *ic, iCode *ifx)
+{
+ operand *left, *right, *result;
+ sym_link *letype , *retype;
+ int sign ;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ left = IC_LEFT(ic);
+ right= IC_RIGHT(ic);
+ result = IC_RESULT(ic);
+
+ letype = getSpec(operandType(left));
+ retype =getSpec(operandType(right));
+ sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
+
+ /* assign the amsops */
+ aopOp (left,ic,FALSE);
+ aopOp (right,ic,FALSE);
+ aopOp (result,ic,TRUE);
+
+ genCmp(left, right, result, ifx, sign);
+
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+#if 0
+/*-----------------------------------------------------------------*/
+/* genc16bit2lit - compare a 16 bit value to a literal */
+/*-----------------------------------------------------------------*/
+static void genc16bit2lit(operand *op, int lit, int offset)
+{
+ int i;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d, lit = %d",__FUNCTION__,__LINE__,lit);
+ if( (lit&0xff) == 0)
+ i=1;
+ else
+ i=0;
+
+ switch( BYTEofLONG(lit,i)) {
+ case 0:
+ emitpcode(POC_MOVFW,popGet(AOP(op),offset+i));
+ break;
+ case 1:
+ emitpcode(POC_DECFW,popGet(AOP(op),offset+i));
+ break;
+ case 0xff:
+ emitpcode(POC_INCFW,popGet(AOP(op),offset+i));
+ break;
+ default:
+ emitpcode(POC_MOVFW,popGet(AOP(op),offset+i));
+ emitpcode(POC_XORLW,popGetLit(BYTEofLONG(lit,i)));
+ }
+
+ i ^= 1;
+
+ switch( BYTEofLONG(lit,i)) {
+ case 0:
+ emitpcode(POC_IORFW,popGet(AOP(op),offset+i));
+ break;
+ case 1:
+ emitSKPNZ;
+ emitpcode(POC_DECFW,popGet(AOP(op),offset+i));
+ break;
+ case 0xff:
+ emitSKPNZ;
+ emitpcode(POC_INCFW,popGet(AOP(op),offset+i));
+ break;
+ default:
+ emitpcode(POC_MOVLW,popGetLit(BYTEofLONG(lit,i)));
+ emitSKPNZ;
+ emitpcode(POC_XORFW,popGet(AOP(op),offset+i));
+
+ }
+
+}
+#endif
+
+#if 0
+/*-----------------------------------------------------------------*/
+/* gencjneshort - compare and jump if not equal */
+/*-----------------------------------------------------------------*/
+static void gencjne(operand *left, operand *right, operand *result, iCode *ifx)
+{
+ int size = min(AOP_SIZE(left),AOP_SIZE(right));
+ int offset = 0;
+ //resolvedIfx rIfx;
+ symbol *lbl;
+
+ //unsigned long lit = 0L;
+ FENTRY;
+ if (!ifx && (!result || AOP_TYPE(result) == AOP_CRY)) {
+ emitpComment ("gencjne: no ifx, no (real) result -- comparison ignored");
+ return;
+ }
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ assert (!pic14_sameRegs (AOP(left), AOP(result)));
+ assert (!pic14_sameRegs (AOP(right), AOP(result)));
+ if (AOP_SIZE(result)) {
+ for (offset = 0; offset < AOP_SIZE(result); offset++)
+ emitpcode (POC_CLRF, popGet (AOP(result), offset));
+ }
+
+ assert (AOP_SIZE(left) == AOP_SIZE(right));
+ //resolveIfx(&rIfx,ifx);
+ lbl = newiTempLabel (NULL);
+ while (size--)
+ {
+ mov2w (AOP(right),size);
+ emitpcode (POC_XORFW, popGet (AOP(left), size));
+ if (size)
+ {
+ emitSKPZ;
+ emitpcode (POC_GOTO, popGetLabel (lbl->key));
+ }
+ } // while
+ emitpLabel (lbl->key);
+ if (AOP_SIZE(result)) {
+ emitSKPNZ;
+ emitpcode (POC_INCF, popGet (AOP(result), 0));
+ } else {
+ assert (ifx);
+ genSkipz (ifx, NULL != IC_TRUE(ifx));
+ ifx->generated = 1;
+ }
+ return;
+#if 0
+ if(result)
+ {
+ DEBUGpic14_emitcode ("; ***","%s %d result is not null",__FUNCTION__,__LINE__);
+ assert (!pic14_sameRegs (AOP(result), AOP(left)));
+ assert (!pic14_sameRegs (AOP(result), AOP(right)));
+ for (offset=0; offset < AOP_SIZE(result); offset++)
+ {
+ emitpcode (POC_CLRF, popGet (AOP(result), offset));
+ } // for offset
+ }
+
+
+ /* if the left side is a literal or
+ if the right is in a pointer register and left
+ is not */
+ if ((AOP_TYPE(left) == AOP_LIT) ||
+ (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
+ operand *t = right;
+ right = left;
+ left = t;
+ }
+ if(AOP_TYPE(right) == AOP_LIT)
+ lit = ulFromVal(AOP(right)->aopu.aop_lit);
+
+ /* if the right side is a literal then anything goes */
+ if (AOP_TYPE(right) == AOP_LIT &&
+ AOP_TYPE(left) != AOP_DIR ) {
+ switch(size) {
+ case 2:
+ genc16bit2lit(left, lit, 0);
+ emitSKPNZ;
+ emitpcode(POC_GOTO,popGetLabel(lbl->key));
+ break;
+ default:
+ offset = 0;
+ while (size--) {
+ if(lit & 0xff) {
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ emitpcode(POC_XORLW,popGetLit(lit & 0xff));
+ } else {
+ emitpcode(POC_MOVF,popGet(AOP(left),offset));
+ }
+
+ emitSKPNZ;
+ emitpcode(POC_GOTO,popGetLabel(lbl->key));
+ offset++;
+ lit >>= 8;
+ }
+ break;
+ }
+ }
+
+ /* if the right side is in a register or in direct space or
+ if the left is a pointer register & right is not */
+ else if (AOP_TYPE(right) == AOP_REG ||
+ AOP_TYPE(right) == AOP_DIR ||
+ (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) ||
+ (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) {
+ //int lbl_key = (rIfx.condition) ? rIfx.lbl->key : lbl->key;
+ int lbl_key = lbl->key;
+
+ if(!result) {
+ DEBUGpic14_emitcode ("; ***","%s %d -- ERROR",__FUNCTION__,__LINE__);
+ fprintf(stderr, "%s %d error - expecting result to be non_null\n",
+ __FUNCTION__,__LINE__);
+ return;
+ }
+
+ /* switch(size) { */
+ /* case 2: */
+ /* genc16bit2lit(left, lit, 0); */
+ /* emitSKPNZ; */
+ /* emitpcode(POC_GOTO,popGetLabel(lbl->key)); */
+ /* break; */
+ /* default: */
+ offset = 0;
+ while (size--) {
+ int emit_skip=1;
+ if((AOP_TYPE(left) == AOP_DIR) &&
+ ((AOP_TYPE(right) == AOP_REG) || (AOP_TYPE(right) == AOP_DIR))) {
+
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ emitpcode(POC_XORFW,popGet(AOP(right),offset));
+
+ } else if((AOP_TYPE(left) == AOP_DIR) && (AOP_TYPE(right) == AOP_LIT)){
+
+ switch (lit & 0xff) {
+ case 0:
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ break;
+ case 1:
+ emitpcode(POC_DECFSZW,popGet(AOP(left),offset));
+ //emitpcode(POC_INCF,popGet(AOP(result),res_offset));
+ emitpcode(POC_GOTO,popGetLabel(lbl->key));
+ emit_skip=0;
+ break;
+ case 0xff:
+ emitpcode(POC_INCFSZW,popGet(AOP(left),offset));
+ //emitpcode(POC_INCF,popGet(AOP(result),res_offset));
+ //emitpcode(POC_INCFSZW,popGet(AOP(left),offset));
+ emitpcode(POC_GOTO,popGetLabel(lbl_key));
+ emit_skip=0;
+ break;
+ default:
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ emitpcode(POC_XORLW,popGetLit(lit & 0xff));
+ }
+ lit >>= 8;
+
+ } else {
+ emitpcode(POC_MOVF,popGet(AOP(left),offset));
+ }
+ if(emit_skip) {
+ if(AOP_TYPE(result) == AOP_CRY) {
+ pic14_emitcode(";***","%s %d",__FUNCTION__,__LINE__);
+ if(rIfx.condition)
+ emitSKPNZ;
+ else
+ emitSKPZ;
+ emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+ } else {
+ /* fix me. probably need to check result size too */
+ //emitpcode(POC_CLRF,popGet(AOP(result),0));
+ if(rIfx.condition)
+ emitSKPZ;
+ else
+ emitSKPNZ;
+ emitpcode(POC_GOTO,popGetLabel(lbl_key));
+ }
+ if(ifx)
+ ifx->generated=1;
+ }
+ emit_skip++;
+ offset++;
+ }
+ /* break; */
+ /* } */
+ } else if(AOP_TYPE(right) == AOP_REG &&
+ AOP_TYPE(left) != AOP_DIR){
+
+ offset = 0;
+ while(size--) {
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ emitpcode(POC_XORFW,popGet(AOP(right),offset));
+ pic14_emitcode(";***","%s %d",__FUNCTION__,__LINE__);
+ if(rIfx.condition)
+ emitSKPNZ;
+ else
+ emitSKPZ;
+ emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+ offset++;
+ }
+
+ }else{
+ /* right is a pointer reg need both a & b */
+ offset = 0;
+ while(size--) {
+ char *l = aopGet(AOP(left),offset,FALSE,FALSE);
+ if(strcmp(l,"b"))
+ pic14_emitcode("mov","b,%s",l);
+ MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("cjne","a,b,%05d_DS_",lbl->key+100);
+ offset++;
+ }
+ }
+
+ emitpcode(POC_INCF,popGet(AOP(result),0));
+ if(!rIfx.condition)
+ emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+
+ emitpLabel(lbl->key);
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ if(ifx)
+ ifx->generated = 1;
+#endif
+}
+#endif
+
+#if 0
+/*-----------------------------------------------------------------*/
+/* gencjne - compare and jump if not equal */
+/*-----------------------------------------------------------------*/
+static void gencjne(operand *left, operand *right, iCode *ifx)
+{
+ symbol *tlbl = newiTempLabel(NULL);
+
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ gencjneshort(left, right, lbl);
+
+ pic14_emitcode("mov","a,%s",one);
+ pic14_emitcode("sjmp","%05d_DS_",tlbl->key+100);
+ pic14_emitcode("","%05d_DS_:",lbl->key+100);
+ pic14_emitcode("clr","a");
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+
+ emitpLabel(lbl->key);
+ emitpLabel(tlbl->key);
+
+}
+#endif
+
+/*-----------------------------------------------------------------*/
+/* genCmpEq - generates code for equal to */
+/*-----------------------------------------------------------------*/
+static void genCmpEq (iCode *ic, iCode *ifx)
+{
+ operand *left, *right, *result;
+ int size;
+ symbol *false_label;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ if(ifx)
+ DEBUGpic14_emitcode ("; ifx is non-null","");
+ else
+ DEBUGpic14_emitcode ("; ifx is null","");
+
+ aopOp((left=IC_LEFT(ic)),ic,FALSE);
+ aopOp((right=IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,TRUE);
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ /* if literal, move literal to right */
+ if (op_isLitLike (IC_LEFT(ic))) {
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ false_label = NULL;
+ if (ifx && !IC_TRUE(ifx))
+ {
+ assert (IC_FALSE(ifx));
+ false_label = IC_FALSE(ifx);
+ }
+
+ size = min(AOP_SIZE(left),AOP_SIZE(right));
+ assert(!pic14_sameRegs(AOP(result),AOP(left)));
+ assert(!pic14_sameRegs(AOP(result),AOP(right)));
+
+ /* assume left != right */
+ {
+ int i;
+ for (i=0; i < AOP_SIZE(result); i++)
+ {
+ emitpcode(POC_CLRF, popGet(AOP(result),i));
+ }
+ }
+
+ if (AOP_TYPE(right) == AOP_LIT)
+ {
+ unsigned long lit = ulFromVal (AOP(right)->aopu.aop_lit);
+ int i;
+ size = AOP_SIZE(left);
+ assert(!op_isLitLike(left));
+
+ switch (lit)
+ {
+ case 0:
+ mov2w(AOP(left), 0);
+ for (i=1; i < size; i++)
+ emitpcode(POC_IORFW,popGet(AOP(left),i));
+ /* now Z is set iff `left == right' */
+ emitSKPZ;
+ if (!false_label) false_label = newiTempLabel(NULL);
+ emitpcode(POC_GOTO, popGetLabel(false_label->key));
+ break;
+
+ default:
+ for (i=0; i < size; i++)
+ {
+ mov2w(AOP(left),i);
+ emitpcode(POC_XORLW, popGetLit(lit >> (8*i)));
+ /* now Z is cleared if `left != right' */
+ emitSKPZ;
+ if (!false_label) false_label = newiTempLabel(NULL);
+ emitpcode(POC_GOTO, popGetLabel(false_label->key));
+ } // for i
+ break;
+ } // switch (lit)
+ }
+ else
+ {
+ /* right is no literal */
+ int i;
+
+ for (i=0; i < size; i++)
+ {
+ mov2w(AOP(right),i);
+ emitpcode(POC_XORFW,popGet(AOP(left),i));
+ /* now Z is cleared if `left != right' */
+ emitSKPZ;
+ if (!false_label) false_label = newiTempLabel(NULL);
+ emitpcode(POC_GOTO, popGetLabel(false_label->key));
+ } // for i
+ }
+
+ /* if we reach here, left == right */
+
+ if (AOP_SIZE(result) > 0)
+ {
+ emitpcode(POC_INCF, popGet(AOP(result),0));
+ }
+
+ if (ifx && IC_TRUE(ifx))
+ {
+ emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
+ }
+
+ if (false_label && (!ifx || IC_TRUE(ifx)))
+ emitpLabel(false_label->key);
+
+ if (ifx) ifx->generated = 1;
+
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* ifxForOp - returns the icode containing the ifx for operand */
+/*-----------------------------------------------------------------*/
+static iCode *ifxForOp ( operand *op, iCode *ic )
+{
+ FENTRY;
+ /* if true symbol then needs to be assigned */
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if (IS_TRUE_SYMOP(op))
+ return NULL ;
+
+ /* if this has register type condition and
+ the next instruction is ifx with the same operand
+ and live to of the operand is upto the ifx only then */
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND(ic->next)->key == op->key &&
+ OP_SYMBOL(op)->liveTo <= ic->next->seq )
+ return ic->next;
+
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND(ic->next)->key == op->key) {
+ DEBUGpic14_emitcode ("; WARNING ","%d IGNORING liveTo range in %s",__LINE__,__FUNCTION__);
+ return ic->next;
+ }
+
+ DEBUGpic14_emitcode ("; NULL :(","%d",__LINE__);
+ if (ic->next &&
+ ic->next->op == IFX)
+ DEBUGpic14_emitcode ("; ic-next"," is an IFX");
+
+ if (ic->next &&
+ ic->next->op == IFX &&
+ IC_COND(ic->next)->key == op->key) {
+ DEBUGpic14_emitcode ("; "," key is okay");
+ DEBUGpic14_emitcode ("; "," key liveTo %d, next->seq = %d",
+ OP_SYMBOL(op)->liveTo,
+ ic->next->seq);
+ }
+
+
+ return NULL;
+}
+/*-----------------------------------------------------------------*/
+/* genAndOp - for && operation */
+/*-----------------------------------------------------------------*/
+static void genAndOp (iCode *ic)
+{
+ operand *left,*right, *result;
+ /* symbol *tlbl; */
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* note here that && operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ aopOp((left=IC_LEFT(ic)),ic,FALSE);
+ aopOp((right=IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,FALSE);
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ emitpcode(POC_MOVFW,popGet(AOP(left),0));
+ emitpcode(POC_ANDFW,popGet(AOP(right),0));
+ emitpcode(POC_MOVWF,popGet(AOP(result),0));
+
+ /* if both are bit variables */
+ /* if (AOP_TYPE(left) == AOP_CRY && */
+ /* AOP_TYPE(right) == AOP_CRY ) { */
+ /* pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir); */
+ /* pic14_emitcode("anl","c,%s",AOP(right)->aopu.aop_dir); */
+ /* pic14_outBitC(result); */
+ /* } else { */
+ /* tlbl = newiTempLabel(NULL); */
+ /* pic14_toBoolean(left); */
+ /* pic14_emitcode("jz","%05d_DS_",tlbl->key+100); */
+ /* pic14_toBoolean(right); */
+ /* pic14_emitcode("","%05d_DS_:",tlbl->key+100); */
+ /* pic14_outBitAcc(result); */
+ /* } */
+
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+
+/*-----------------------------------------------------------------*/
+/* genOrOp - for || operation */
+/*-----------------------------------------------------------------*/
+/*
+tsd pic port -
+modified this code, but it doesn't appear to ever get called
+*/
+
+static void genOrOp (iCode *ic)
+{
+ operand *left,*right, *result;
+ symbol *tlbl;
+ int i;
+
+ /* note here that || operations that are in an
+ if statement are taken away by backPatchLabels
+ only those used in arthmetic operations remain */
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ aopOp((left=IC_LEFT(ic)),ic,FALSE);
+ aopOp((right=IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,FALSE);
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ for (i=0; i < AOP_SIZE(result); i++)
+ {
+ emitpcode(POC_CLRF, popGet(AOP(result), i));
+ } // for i
+
+ tlbl = newiTempLabel(NULL);
+ pic14_toBoolean(left);
+ emitSKPZ;
+ emitpcode(POC_GOTO, popGetLabel(tlbl->key));
+ pic14_toBoolean(right);
+ emitpLabel(tlbl->key);
+ /* here Z is clear IFF `left || right' */
+ emitSKPZ;
+ emitpcode(POC_INCF, popGet(AOP(result), 0));
+
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* isLiteralBit - test if lit == 2^n */
+/*-----------------------------------------------------------------*/
+static int isLiteralBit(unsigned long lit)
+{
+ unsigned long pw[32] = {1L,2L,4L,8L,16L,32L,64L,128L,
+ 0x100L,0x200L,0x400L,0x800L,
+ 0x1000L,0x2000L,0x4000L,0x8000L,
+ 0x10000L,0x20000L,0x40000L,0x80000L,
+ 0x100000L,0x200000L,0x400000L,0x800000L,
+ 0x1000000L,0x2000000L,0x4000000L,0x8000000L,
+ 0x10000000L,0x20000000L,0x40000000L,0x80000000L};
+ int idx;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ for(idx = 0; idx < 32; idx++)
+ if(lit == pw[idx])
+ return idx+1;
+ return 0;
+}
+
+/*-----------------------------------------------------------------*/
+/* continueIfTrue - */
+/*-----------------------------------------------------------------*/
+static void continueIfTrue (iCode *ic)
+{
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if(IC_TRUE(ic))
+ {
+ // Why +100?!?
+ emitpcode(POC_GOTO, popGetLabel(IC_TRUE(ic)->key+100));
+ pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
+ }
+ ic->generated = 1;
+}
+
+/*-----------------------------------------------------------------*/
+/* jmpIfTrue - */
+/*-----------------------------------------------------------------*/
+static void jumpIfTrue (iCode *ic)
+{
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if(!IC_TRUE(ic))
+ {
+ // Why +100?!?
+ emitpcode(POC_GOTO, popGetLabel(IC_TRUE(ic)->key+100));
+ pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
+ }
+ ic->generated = 1;
+}
+
+/*-----------------------------------------------------------------*/
+/* jmpTrueOrFalse - */
+/*-----------------------------------------------------------------*/
+static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
+{
+ FENTRY;
+ // ugly but optimized by peephole
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if(IC_TRUE(ic)){
+ symbol *nlbl = newiTempLabel(NULL);
+ pic14_emitcode("sjmp","%05d_DS_",nlbl->key+100);
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ pic14_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
+ pic14_emitcode("","%05d_DS_:",nlbl->key+100);
+ }
+ else{
+ pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ }
+ ic->generated = 1;
+}
+
+/*-----------------------------------------------------------------*/
+/* genAnd - code for and */
+/*-----------------------------------------------------------------*/
+static void genAnd (iCode *ic, iCode *ifx)
+{
+ operand *left, *right, *result;
+ int size, offset=0;
+ unsigned long lit = 0L;
+ int bytelit = 0;
+ resolvedIfx rIfx;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ aopOp((left = IC_LEFT(ic)),ic,FALSE);
+ aopOp((right= IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,TRUE);
+
+ resolveIfx(&rIfx,ifx);
+
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
+ AOP_NEEDSACC(left)) {
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if(pic14_sameRegs(AOP(result),AOP(right))){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE(right) == AOP_CRY &&
+ AOP_TYPE(left) != AOP_CRY){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+ if(AOP_TYPE(right) == AOP_LIT)
+ lit = ulFromVal (AOP(right)->aopu.aop_lit);
+
+ size = AOP_SIZE(result);
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ // if(bit & yy)
+ // result = bit & yy;
+ if (AOP_TYPE(left) == AOP_CRY){
+ // c = bit & literal;
+ if(AOP_TYPE(right) == AOP_LIT){
+ if(lit & 1) {
+ if(size && pic14_sameRegs(AOP(result),AOP(left)))
+ // no change
+ goto release;
+ pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
+ } else {
+ // bit(result) = 0;
+ if(size && (AOP_TYPE(result) == AOP_CRY)){
+ pic14_emitcode("clr","%s",AOP(result)->aopu.aop_dir);
+ goto release;
+ }
+ if((AOP_TYPE(result) == AOP_CRY) && ifx){
+ jumpIfTrue(ifx);
+ goto release;
+ }
+ pic14_emitcode("clr","c");
+ }
+ } else {
+ if (AOP_TYPE(right) == AOP_CRY){
+ // c = bit & bit;
+ pic14_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
+ pic14_emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
+ } else {
+ // c = bit & val;
+ MOVA(aopGet(AOP(right),0,FALSE,FALSE));
+ // c = lsb
+ pic14_emitcode("rrc","a");
+ pic14_emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
+ }
+ }
+ // bit = c
+ // val = c
+ if(size)
+ pic14_outBitC(result);
+ // if(bit & ...)
+ else if((AOP_TYPE(result) == AOP_CRY) && ifx)
+ genIfxJump(ifx, "c");
+ goto release ;
+ }
+
+ // if(val & 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val & 0xZZ - size = 1, ifx = FALSE -
+ if((AOP_TYPE(right) == AOP_LIT) &&
+ (AOP_TYPE(result) == AOP_CRY) &&
+ (AOP_TYPE(left) != AOP_CRY)){
+ int posbit = isLiteralBit(lit);
+ /* left & 2^n */
+ if(posbit){
+ posbit--;
+ //MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE));
+ // bit = left & 2^n
+ if(size)
+ pic14_emitcode("mov","c,acc.%d",posbit&0x07);
+ // if(left & 2^n)
+ else{
+ if(ifx){
+ int offset = 0;
+ while (posbit > 7) {
+ posbit -= 8;
+ offset++;
+ }
+ emitpcode(((rIfx.condition) ? POC_BTFSC : POC_BTFSS),
+ newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),posbit,0));
+ emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+
+ ifx->generated = 1;
+ }
+ goto release;
+ }
+ } else {
+ symbol *tlbl = newiTempLabel(NULL);
+ int sizel = AOP_SIZE(left);
+ if(size)
+ pic14_emitcode("setb","c");
+ while(sizel--){
+ if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
+ mov2w( AOP(left), offset);
+ // byte == 2^n ?
+ if((posbit = isLiteralBit(bytelit)) != 0) {
+ emitpcode(rIfx.condition ? POC_BTFSC : POC_BTFSS, // XXX: or the other way round?
+ newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),posbit - 1, 0));
+ pic14_emitcode("jb","acc.%d,%05d_DS_",(posbit-1)&0x07,tlbl->key+100);
+ }
+ else{
+ emitpcode(POC_ANDLW, newpCodeOpLit(bytelit & 0x0ff));
+ if (rIfx.condition) emitSKPZ;
+ else emitSKPNZ;
+
+ if(bytelit != 0x0FFL)
+ {
+ pic14_emitcode("anl","a,%s",
+ aopGet(AOP(right),offset,FALSE,TRUE));
+ }
+ pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
+ }
+
+ emitpcode(POC_GOTO, popGetLabel(rIfx.lbl->key));
+ ifx->generated = 1;
+
+ }
+ offset++;
+ }
+ // bit = left & literal
+ if(size){
+ pic14_emitcode("clr","c");
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ }
+ // if(left & literal)
+ else{
+ if(ifx)
+ jmpTrueOrFalse(ifx, tlbl);
+ goto release ;
+ }
+ }
+ pic14_outBitC(result);
+ goto release ;
+ }
+
+ /* if left is same as result */
+ if(pic14_sameRegs(AOP(result),AOP(left))){
+ int know_W = -1;
+ for(;size--; offset++,lit>>=8) {
+ if(AOP_TYPE(right) == AOP_LIT){
+ switch(lit & 0xff) {
+ case 0x00:
+ /* and'ing with 0 has clears the result */
+ emitpcode(POC_CLRF,popGet(AOP(result),offset));
+ break;
+ case 0xff:
+ /* and'ing with 0xff is a nop when the result and left are the same */
+ break;
+
+ default:
+ {
+ int p = my_powof2( (~lit) & 0xff );
+ if(p>=0) {
+ /* only one bit is set in the literal, so use a bcf instruction */
+ emitpcode(POC_BCF,newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
+
+ } else {
+ if(know_W != (int)(lit&0xff))
+ emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+ know_W = lit &0xff;
+ emitpcode(POC_ANDWF,popGet(AOP(left),offset));
+ }
+ }
+ }
+ } else {
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_ANDFW,popGet(AOP(right),offset));
+ } else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset));
+ emitpcode(POC_ANDWF,popGet(AOP(left),offset));
+
+ }
+ }
+ }
+
+ } else {
+ // left & result in different registers
+ if(AOP_TYPE(result) == AOP_CRY){
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left & right)
+ symbol *tlbl = newiTempLabel(NULL);
+ int sizer = min(AOP_SIZE(left),AOP_SIZE(right));
+ if(size)
+ pic14_emitcode("setb","c");
+ while(sizer--){
+ MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("anl","a,%s",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
+ offset++;
+ }
+ if(size){
+ CLRC;
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ pic14_outBitC(result);
+ } else if(ifx)
+ jmpTrueOrFalse(ifx, tlbl);
+ } else {
+ for(;(size--);offset++) {
+ // normal case
+ // result = left & right
+ if(AOP_TYPE(right) == AOP_LIT){
+ int t = (lit >> (offset*8)) & 0x0FFL;
+ switch(t) {
+ case 0x00:
+ emitpcode(POC_CLRF,popGet(AOP(result),offset));
+ break;
+ case 0xff:
+ if(AOP_TYPE(left) != AOP_ACC) {
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ break;
+ default:
+ if(AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_ANDLW, popGetLit(t));
+ } else {
+ emitpcode(POC_MOVLW, popGetLit(t));
+ emitpcode(POC_ANDFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ }
+ continue;
+ }
+
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_ANDFW,popGet(AOP(right),offset));
+ } else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset));
+ emitpcode(POC_ANDFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ }
+ }
+ }
+
+release :
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genOr - code for or */
+/*-----------------------------------------------------------------*/
+static void genOr (iCode *ic, iCode *ifx)
+{
+ operand *left, *right, *result;
+ int size, offset=0;
+ unsigned long lit = 0L;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ aopOp((left = IC_LEFT(ic)),ic,FALSE);
+ aopOp((right= IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,TRUE);
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
+ AOP_NEEDSACC(left)) {
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if(pic14_sameRegs(AOP(result),AOP(right))){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE(right) == AOP_CRY &&
+ AOP_TYPE(left) != AOP_CRY){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ DEBUGpic14_AopType(__LINE__,left,right,result);
+
+ if(AOP_TYPE(right) == AOP_LIT)
+ lit = ulFromVal (AOP(right)->aopu.aop_lit);
+
+ size = AOP_SIZE(result);
+
+ // if(bit | yy)
+ // xx = bit | yy;
+ if (AOP_TYPE(left) == AOP_CRY){
+ if(AOP_TYPE(right) == AOP_LIT){
+ // c = bit & literal;
+ if(lit){
+ // lit != 0 => result = 1
+ if(AOP_TYPE(result) == AOP_CRY){
+ if(size)
+ emitpcode(POC_BSF, popGet(AOP(result),0));
+ //pic14_emitcode("bsf","(%s >> 3), (%s & 7)",
+ // AOP(result)->aopu.aop_dir,
+ // AOP(result)->aopu.aop_dir);
+ else if(ifx)
+ continueIfTrue(ifx);
+ goto release;
+ }
+ } else {
+ // lit == 0 => result = left
+ if(size && pic14_sameRegs(AOP(result),AOP(left)))
+ goto release;
+ pic14_emitcode(";XXX mov","c,%s %s,%d",AOP(left)->aopu.aop_dir,__FILE__,__LINE__);
+ }
+ } else {
+ if (AOP_TYPE(right) == AOP_CRY){
+ if(pic14_sameRegs(AOP(result),AOP(left))){
+ // c = bit | bit;
+ emitpcode(POC_BCF, popGet(AOP(result),0));
+ emitpcode(POC_BTFSC, popGet(AOP(right),0));
+ emitpcode(POC_BSF, popGet(AOP(result),0));
+
+ pic14_emitcode("bcf","(%s >> 3), (%s & 7)",
+ AOP(result)->aopu.aop_dir,
+ AOP(result)->aopu.aop_dir);
+ pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
+ AOP(right)->aopu.aop_dir,
+ AOP(right)->aopu.aop_dir);
+ pic14_emitcode("bsf","(%s >> 3), (%s & 7)",
+ AOP(result)->aopu.aop_dir,
+ AOP(result)->aopu.aop_dir);
+ } else {
+ if( AOP_TYPE(result) == AOP_ACC) {
+ emitpcode(POC_MOVLW, popGetLit(0));
+ emitpcode(POC_BTFSS, popGet(AOP(right),0));
+ emitpcode(POC_BTFSC, popGet(AOP(left),0));
+ emitpcode(POC_MOVLW, popGetLit(1));
+
+ } else {
+
+ emitpcode(POC_BCF, popGet(AOP(result),0));
+ emitpcode(POC_BTFSS, popGet(AOP(right),0));
+ emitpcode(POC_BTFSC, popGet(AOP(left),0));
+ emitpcode(POC_BSF, popGet(AOP(result),0));
+
+ pic14_emitcode("bcf","(%s >> 3), (%s & 7)",
+ AOP(result)->aopu.aop_dir,
+ AOP(result)->aopu.aop_dir);
+ pic14_emitcode("btfss","(%s >> 3), (%s & 7)",
+ AOP(right)->aopu.aop_dir,
+ AOP(right)->aopu.aop_dir);
+ pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
+ AOP(left)->aopu.aop_dir,
+ AOP(left)->aopu.aop_dir);
+ pic14_emitcode("bsf","(%s >> 3), (%s & 7)",
+ AOP(result)->aopu.aop_dir,
+ AOP(result)->aopu.aop_dir);
+ }
+ }
+ } else {
+ // c = bit | val;
+ symbol *tlbl = newiTempLabel(NULL);
+ pic14_emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
+
+
+ emitpcode(POC_BCF, popGet(AOP(result),0));
+ if( AOP_TYPE(right) == AOP_ACC) {
+ emitpcode(POC_IORLW, popGetLit(0));
+ emitSKPNZ;
+ emitpcode(POC_BTFSC, popGet(AOP(left),0));
+ emitpcode(POC_BSF, popGet(AOP(result),0));
+ }
+
+
+
+ if(!((AOP_TYPE(result) == AOP_CRY) && ifx))
+ pic14_emitcode(";XXX setb","c");
+ pic14_emitcode(";XXX jb","%s,%05d_DS_",
+ AOP(left)->aopu.aop_dir,tlbl->key+100);
+ pic14_toBoolean(right);
+ pic14_emitcode(";XXX jnz","%05d_DS_",tlbl->key+100);
+ if((AOP_TYPE(result) == AOP_CRY) && ifx){
+ jmpTrueOrFalse(ifx, tlbl);
+ goto release;
+ } else {
+ CLRC;
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ }
+ }
+ }
+ // bit = c
+ // val = c
+ if(size)
+ pic14_outBitC(result);
+ // if(bit | ...)
+ else if((AOP_TYPE(result) == AOP_CRY) && ifx)
+ genIfxJump(ifx, "c");
+ goto release ;
+ }
+
+ // if(val | 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val | 0xZZ - size = 1, ifx = FALSE -
+ if((AOP_TYPE(right) == AOP_LIT) &&
+ (AOP_TYPE(result) == AOP_CRY) &&
+ (AOP_TYPE(left) != AOP_CRY)){
+ if(lit){
+ pic14_emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
+ // result = 1
+ if(size)
+ pic14_emitcode(";XXX setb","%s",AOP(result)->aopu.aop_dir);
+ else
+ continueIfTrue(ifx);
+ goto release;
+ } else {
+ pic14_emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
+ // lit = 0, result = boolean(left)
+ if(size)
+ pic14_emitcode(";XXX setb","c");
+ pic14_toBoolean(right);
+ if(size){
+ symbol *tlbl = newiTempLabel(NULL);
+ pic14_emitcode(";XXX jnz","%05d_DS_",tlbl->key+100);
+ CLRC;
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ } else {
+ genIfxJump (ifx,"a");
+ goto release;
+ }
+ }
+ pic14_outBitC(result);
+ goto release ;
+ }
+
+ /* if left is same as result */
+ if(pic14_sameRegs(AOP(result),AOP(left))){
+ int know_W = -1;
+ for(;size--; offset++,lit>>=8) {
+ if(AOP_TYPE(right) == AOP_LIT){
+ if((lit & 0xff) == 0)
+ /* or'ing with 0 has no effect */
+ continue;
+ else {
+ int p = my_powof2(lit & 0xff);
+ if(p>=0) {
+ /* only one bit is set in the literal, so use a bsf instruction */
+ emitpcode(POC_BSF,
+ newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
+ } else {
+ if(know_W != (int)(lit & 0xff))
+ emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+ know_W = lit & 0xff;
+ emitpcode(POC_IORWF, popGet(AOP(left),offset));
+ }
+
+ }
+ } else {
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_IORFW, popGet(AOP(right),offset));
+ pic14_emitcode("iorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
+ } else {
+ emitpcode(POC_MOVFW, popGet(AOP(right),offset));
+ emitpcode(POC_IORWF, popGet(AOP(left),offset));
+
+ pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("iorwf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
+
+ }
+ }
+ }
+ } else {
+ // left & result in different registers
+ if(AOP_TYPE(result) == AOP_CRY){
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left | right)
+ symbol *tlbl = newiTempLabel(NULL);
+ int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
+ pic14_emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
+
+
+ if(size)
+ pic14_emitcode(";XXX setb","c");
+ while(sizer--){
+ MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode(";XXX orl","a,%s",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode(";XXX jnz","%05d_DS_",tlbl->key+100);
+ offset++;
+ }
+ if(size){
+ CLRC;
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ pic14_outBitC(result);
+ } else if(ifx)
+ jmpTrueOrFalse(ifx, tlbl);
+ } else for(;(size--);offset++){
+ // normal case
+ // result = left | right
+ if(AOP_TYPE(right) == AOP_LIT){
+ int t = (lit >> (offset*8)) & 0x0FFL;
+ switch(t) {
+ case 0x00:
+ if (AOP_TYPE(left) != AOP_ACC) {
+ emitpcode(POC_MOVFW, popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
+
+ break;
+ default:
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_IORLW, popGetLit(t));
+ } else {
+ emitpcode(POC_MOVLW, popGetLit(t));
+ emitpcode(POC_IORFW, popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
+ }
+ continue;
+ }
+
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_IORFW,popGet(AOP(right),offset));
+ } else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset));
+ emitpcode(POC_IORFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
+ }
+ }
+
+release :
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genXor - code for xclusive or */
+/*-----------------------------------------------------------------*/
+static void genXor (iCode *ic, iCode *ifx)
+{
+ operand *left, *right, *result;
+ int size, offset=0;
+ unsigned long lit = 0L;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ aopOp((left = IC_LEFT(ic)),ic,FALSE);
+ aopOp((right= IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,TRUE);
+
+ /* if left is a literal & right is not ||
+ if left needs acc & right does not */
+ if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
+ (AOP_NEEDSACC(left) && !AOP_NEEDSACC(right))) {
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ /* if result = right then exchange them */
+ if(pic14_sameRegs(AOP(result),AOP(right))){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+
+ /* if right is bit then exchange them */
+ if (AOP_TYPE(right) == AOP_CRY &&
+ AOP_TYPE(left) != AOP_CRY){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+ if(AOP_TYPE(right) == AOP_LIT)
+ lit = ulFromVal (AOP(right)->aopu.aop_lit);
+
+ size = AOP_SIZE(result);
+
+ // if(bit ^ yy)
+ // xx = bit ^ yy;
+ if (AOP_TYPE(left) == AOP_CRY){
+ if(AOP_TYPE(right) == AOP_LIT){
+ // c = bit & literal;
+ if(lit>>1){
+ // lit>>1 != 0 => result = 1
+ if(AOP_TYPE(result) == AOP_CRY){
+ if(size)
+ {emitpcode(POC_BSF, popGet(AOP(result),offset));
+ pic14_emitcode("setb","%s",AOP(result)->aopu.aop_dir);}
+ else if(ifx)
+ continueIfTrue(ifx);
+ goto release;
+ }
+ pic14_emitcode("setb","c");
+ } else{
+ // lit == (0 or 1)
+ if(lit == 0){
+ // lit == 0, result = left
+ if(size && pic14_sameRegs(AOP(result),AOP(left)))
+ goto release;
+ pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
+ } else{
+ // lit == 1, result = not(left)
+ if(size && pic14_sameRegs(AOP(result),AOP(left))){
+ emitpcode(POC_MOVLW, popGet(AOP(result),offset));
+ emitpcode(POC_XORWF, popGet(AOP(result),offset));
+ pic14_emitcode("cpl","%s",AOP(result)->aopu.aop_dir);
+ goto release;
+ } else {
+ assert ( !"incomplete genXor" );
+ pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
+ pic14_emitcode("cpl","c");
+ }
+ }
+ }
+
+ } else {
+ // right != literal
+ symbol *tlbl = newiTempLabel(NULL);
+ if (AOP_TYPE(right) == AOP_CRY){
+ // c = bit ^ bit;
+ pic14_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
+ }
+ else{
+ int sizer = AOP_SIZE(right);
+ // c = bit ^ val
+ // if val>>1 != 0, result = 1
+ pic14_emitcode("setb","c");
+ while(sizer){
+ MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE));
+ if(sizer == 1)
+ // test the msb of the lsb
+ pic14_emitcode("anl","a,#0xfe");
+ pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
+ sizer--;
+ }
+ // val = (0,1)
+ pic14_emitcode("rrc","a");
+ }
+ pic14_emitcode("jnb","%s,%05d_DS_",AOP(left)->aopu.aop_dir,(tlbl->key+100));
+ pic14_emitcode("cpl","c");
+ pic14_emitcode("","%05d_DS_:",(tlbl->key+100));
+ }
+ // bit = c
+ // val = c
+ if(size)
+ pic14_outBitC(result);
+ // if(bit | ...)
+ else if((AOP_TYPE(result) == AOP_CRY) && ifx)
+ genIfxJump(ifx, "c");
+ goto release ;
+ }
+
+ if(pic14_sameRegs(AOP(result),AOP(left))){
+ /* if left is same as result */
+ for(;size--; offset++) {
+ if(AOP_TYPE(right) == AOP_LIT){
+ int t = (lit >> (offset*8)) & 0x0FFL;
+ if(t == 0x00L)
+ continue;
+ else
+ if (IS_AOP_PREG(left)) {
+ MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+ aopPut(AOP(result),"a",offset);
+ } else {
+ emitpcode(POC_MOVLW, popGetLit(t));
+ emitpcode(POC_XORWF,popGet(AOP(left),offset));
+ pic14_emitcode("xrl","%s,%s",
+ aopGet(AOP(left),offset,FALSE,TRUE),
+ aopGet(AOP(right),offset,FALSE,FALSE));
+ }
+ } else {
+ if (AOP_TYPE(left) == AOP_ACC)
+ pic14_emitcode("xrl","a,%s",aopGet(AOP(right),offset,FALSE,FALSE));
+ else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset));
+ emitpcode(POC_XORWF,popGet(AOP(left),offset));
+ /*
+ if (IS_AOP_PREG(left)) {
+ pic14_emitcode("xrl","a,%s",aopGet(AOP(left),offset,FALSE,TRUE));
+ aopPut(AOP(result),"a",offset);
+ } else
+ pic14_emitcode("xrl","%s,a",
+ aopGet(AOP(left),offset,FALSE,TRUE));
+ */
+ }
+ }
+ }
+ } else {
+ // left & result in different registers
+ if(AOP_TYPE(result) == AOP_CRY){
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left ^ right)
+ symbol *tlbl = newiTempLabel(NULL);
+ int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
+ if(size)
+ pic14_emitcode("setb","c");
+ while(sizer--){
+ if((AOP_TYPE(right) == AOP_LIT) &&
+ (((lit >> (offset*8)) & 0x0FFL) == 0x00L)){
+ MOVA(aopGet(AOP(left),offset,FALSE,FALSE));
+ } else {
+ MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("xrl","a,%s",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ }
+ pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
+ offset++;
+ }
+ if(size){
+ CLRC;
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ pic14_outBitC(result);
+ } else if(ifx)
+ jmpTrueOrFalse(ifx, tlbl);
+ } else for(;(size--);offset++){
+ // normal case
+ // result = left & right
+ if(AOP_TYPE(right) == AOP_LIT){
+ int t = (lit >> (offset*8)) & 0x0FFL;
+ switch(t) {
+ case 0x00:
+ if (AOP_TYPE(left) != AOP_ACC) {
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ pic14_emitcode("movf","%s,w",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode("movwf","%s",
+ aopGet(AOP(result),offset,FALSE,FALSE));
+ break;
+ case 0xff:
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_XORLW, popGetLit(t));
+ } else {
+ emitpcode(POC_COMFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ break;
+ default:
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_XORLW, popGetLit(t));
+ } else {
+ emitpcode(POC_MOVLW, popGetLit(t));
+ emitpcode(POC_XORFW,popGet(AOP(left),offset));
+ }
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ pic14_emitcode("movlw","0x%x",t);
+ pic14_emitcode("xorwf","%s,w",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode("movwf","%s",
+ aopGet(AOP(result),offset,FALSE,FALSE));
+
+ }
+ continue;
+ }
+
+ // faster than result <- left, anl result,right
+ // and better if result is SFR
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_XORFW,popGet(AOP(right),offset));
+ } else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset));
+ emitpcode(POC_XORFW,popGet(AOP(left),offset));
+ }
+ if ( AOP_TYPE(result) != AOP_ACC){
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset));
+ }
+ }
+ }
+
+release :
+ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genInline - write the inline code out */
+/*-----------------------------------------------------------------*/
+static void genInline (iCode *ic)
+{
+ char *buffer, *bp, *bp1;
+ bool inComment = FALSE;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ _G.inLine += (!options.asmpeep);
+
+ buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic));
+
+ while (*bp)
+ {
+ switch (*bp)
+ {
+ case ';':
+ inComment = TRUE;
+ ++bp;
+ break;
+
+ case '\n':
+ inComment = FALSE;
+ *bp++ = '\0';
+ if (*bp1)
+ addpCode2pBlock(pb, newpCodeAsmDir(bp1, NULL)); // inline directly, no process
+ bp1 = bp;
+ break;
+
+ default:
+ /* Add \n for labels, not dirs such as c:\mydir */
+ if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1])))
+ {
+ ++bp;
+ *bp = '\0';
+ ++bp;
+ /* print label, use this special format with NULL directive
+ * to denote that the argument should not be indented with tab */
+ addpCode2pBlock(pb, newpCodeAsmDir(NULL, bp1)); // inline directly, no process
+ bp1 = bp;
+ }
+ else
+ ++bp;
+ break;
+ }
+ }
+ if ((bp1 != bp) && *bp1)
+ addpCode2pBlock(pb, newpCodeAsmDir(bp1, NULL)); // inline directly, no process
+
+ Safe_free (buffer);
+
+ _G.inLine -= (!options.asmpeep);
+}
+
+/*-----------------------------------------------------------------*/
+/* genRRC - rotate right with carry */
+/*-----------------------------------------------------------------*/
+static void genRRC (iCode *ic)
+{
+ operand *left , *result ;
+ int size, offset = 0, same;
+
+ FENTRY;
+ /* rotate right with carry */
+ left = IC_LEFT(ic);
+ result=IC_RESULT(ic);
+ aopOp (left,ic,FALSE);
+ aopOp (result,ic,FALSE);
+
+ DEBUGpic14_AopType(__LINE__,left,NULL,result);
+
+ same = pic14_sameRegs(AOP(result),AOP(left));
+
+ size = AOP_SIZE(result);
+
+ /* get the lsb and put it into the carry */
+ emitpcode(POC_RRFW, popGet(AOP(left),size-1));
+
+ offset = 0 ;
+
+ while(size--) {
+
+ if(same) {
+ emitpcode(POC_RRF, popGet(AOP(left),offset));
+ } else {
+ emitpcode(POC_RRFW, popGet(AOP(left),offset));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
+ }
+
+ offset++;
+ }
+
+ freeAsmop(left,NULL,ic,TRUE);
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genRLC - generate code for rotate left with carry */
+/*-----------------------------------------------------------------*/
+static void genRLC (iCode *ic)
+{
+ operand *left , *result ;
+ int size, offset = 0;
+ int same;
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* rotate right with carry */
+ left = IC_LEFT(ic);
+ result=IC_RESULT(ic);
+ aopOp (left,ic,FALSE);
+ aopOp (result,ic,FALSE);
+
+ DEBUGpic14_AopType(__LINE__,left,NULL,result);
+
+ same = pic14_sameRegs(AOP(result),AOP(left));
+
+ /* move it to the result */
+ size = AOP_SIZE(result);
+
+ /* get the msb and put it into the carry */
+ emitpcode(POC_RLFW, popGet(AOP(left),size-1));
+
+ offset = 0 ;
+
+ while(size--) {
+
+ if(same) {
+ emitpcode(POC_RLF, popGet(AOP(left),offset));
+ } else {
+ emitpcode(POC_RLFW, popGet(AOP(left),offset));
+ emitpcode(POC_MOVWF, popGet(AOP(result),offset));
+ }
+
+ offset++;
+ }
+
+
+ freeAsmop(left,NULL,ic,TRUE);
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genGetHbit - generates code get highest order bit */
+/*-----------------------------------------------------------------*/
+static void genGetHbit (iCode *ic)
+{
+ operand *left, *result;
+ left = IC_LEFT(ic);
+ result=IC_RESULT(ic);
+ aopOp (left,ic,FALSE);
+ aopOp (result,ic,FALSE);
+
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ /* get the highest order byte into a */
+ MOVA(aopGet(AOP(left),AOP_SIZE(left) - 1,FALSE,FALSE));
+ if(AOP_TYPE(result) == AOP_CRY){
+ pic14_emitcode("rlc","a");
+ pic14_outBitC(result);
+ }
+ else{
+ pic14_emitcode("rl","a");
+ pic14_emitcode("anl","a,#0x01");
+ pic14_outAcc(result);
+ }
+
+
+ freeAsmop(left,NULL,ic,TRUE);
+ freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* AccLsh - shift left accumulator by known count */
+/* MARK: pic14 always rotates through CARRY! */
+/*-----------------------------------------------------------------*/
+static void AccLsh (pCodeOp *pcop,int shCount)
+{
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ shCount &= 0x0007; // shCount : 0..7
+ switch(shCount){
+ case 0 :
+ return;
+ break;
+ case 1 :
+ emitCLRC;
+ emitpcode(POC_RLF,pcop);
+ return;
+ break;
+ case 2 :
+ emitpcode(POC_RLF,pcop);
+ emitpcode(POC_RLF,pcop);
+ break;
+ case 3 :
+ emitpcode(POC_RLF,pcop);
+ emitpcode(POC_RLF,pcop);
+ emitpcode(POC_RLF,pcop);
+ break;
+ case 4 :
+ emitpcode(POC_SWAPF,pcop);
+ break;
+ case 5 :
+ emitpcode(POC_SWAPF,pcop);
+ emitpcode(POC_RLF,pcop);
+ break;
+ case 6 :
+ emitpcode(POC_SWAPF,pcop);
+ emitpcode(POC_RLF,pcop);
+ emitpcode(POC_RLF,pcop);
+ break;
+ case 7 :
+ emitpcode(POC_RRFW,pcop);
+ emitpcode(POC_RRF,pcop);
+ break;
+ }
+ /* clear invalid bits */
+ emitpcode(POC_MOVLW, popGetLit ((unsigned char)(~((1UL << shCount) - 1))));
+ emitpcode(POC_ANDWF, pcop);
+}
+
+/*-----------------------------------------------------------------*/
+/* AccRsh - shift right accumulator by known count */
+/* MARK: pic14 always rotates through CARRY! */
+/* maskmode - 0: leave invalid bits undefined (caller should mask) */
+/* 1: mask out invalid bits (zero-extend) */
+/* 2: sign-extend result (pretty slow) */
+/*-----------------------------------------------------------------*/
+static void AccRsh (pCodeOp *pcop,int shCount, int mask_mode)
+{
+ FENTRY;
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ shCount &= 0x0007; // shCount : 0..7
+ switch(shCount){
+ case 0 :
+ return;
+ break;
+ case 1 :
+ /* load sign if needed */
+ if (mask_mode == 2) emitpcode(POC_RLFW,pcop);
+ else if (mask_mode == 1) emitCLRC;
+ emitpcode(POC_RRF,pcop);
+ return;
+ break;
+ case 2 :
+ /* load sign if needed */
+ if (mask_mode == 2) emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_RRF,pcop);
+ /* load sign if needed */
+ if (mask_mode == 2) emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_RRF,pcop);
+ if (mask_mode == 2) return;
+ break;
+ case 3 :
+ /* load sign if needed */
+ if (mask_mode == 2) emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_RRF,pcop);
+ /* load sign if needed */
+ if (mask_mode == 2) emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_RRF,pcop);
+ /* load sign if needed */
+ if (mask_mode == 2) emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_RRF,pcop);
+ if (mask_mode == 2) return;
+ break;
+ case 4 :
+ emitpcode(POC_SWAPF,pcop);
+ break;
+ case 5 :
+ emitpcode(POC_SWAPF,pcop);
+ emitpcode(POC_RRF,pcop);
+ break;
+ case 6 :
+ emitpcode(POC_SWAPF,pcop);
+ emitpcode(POC_RRF,pcop);
+ emitpcode(POC_RRF,pcop);
+ break;
+ case 7 :
+ if (mask_mode == 2)
+ {
+ /* load sign */
+ emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_CLRF,pcop);
+ emitSKPNC;
+ emitpcode(POC_COMF,pcop);
+ return;
+ } else {
+ emitpcode(POC_RLFW,pcop);
+ emitpcode(POC_RLF,pcop);
+ }
+ break;
+ }
+
+ if (mask_mode == 0)
+ {
+ /* leave invalid bits undefined */
+ return;
+ }
+
+ /* clear invalid bits -- zero-extend */
+ emitpcode(POC_MOVLW, popGetLit (0x00ff >> shCount));
+ emitpcode(POC_ANDWF, pcop);
+
+ if (mask_mode == 2) {
+ /* sign-extend */
+ emitpcode(POC_MOVLW, popGetLit (0x00ff << (8 - shCount)));
+ emitpcode(POC_BTFSC, newpCodeOpBit (get_op(pcop,NULL,0), 7 - shCount ,0));
+ emitpcode(POC_IORWF, pcop);
+ }
+}