+ if(ifx) ifx->generated = 1;
+ return;
+
+
+ }
+#endif // _swapp
+
+ if(AOP_TYPE(left) == AOP_LIT) {
+ //symbol *lbl = newiTempLabel(NULL);
+
+ //EXPERIMENTAL lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit));
+
+
+ DEBUGpic16_emitcode(";left lit","lit = 0x%x,sign=%d",lit,sign);
+
+ /* Special cases */
+ if((lit == 0) && (sign == 0)){
+
+ size--;
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ while(size)
+ pic16_emitpcode(POC_IORFW, pic16_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)
+ pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rFalseIfx.lbl->key));
+
+ if(ifx) ifx->generated = 1;
+ return;
+ }
+
+ if(sign) {
+ /* signed comparisons to a literal byte */
+
+ int lp1 = (lit+1) & 0xff;
+
+ DEBUGpic16_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:
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
+ pic16_emitpcode(POC_XORLW, pic16_popGetLit(0x7f));
+ genSkipz2(&rFalseIfx,1);
+ break;
+ default:
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(((-(lit+1)) & 0xff) ^ 0x80));
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
+ break;
+ }
+ } else {
+ /* unsigned comparisons to a literal byte */
+
+ switch(lit & 0xff ) {
+ case 0:
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
+ genSkipz2(&rFalseIfx,0);
+ break;
+ case 0x7f:
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,0,7);
+ break;
+
+ default:
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit+1) & 0xff));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),0));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ rFalseIfx.condition ^= 1;
+ if (AOP_TYPE(result) == AOP_CRY)
+ genSkipc(&rFalseIfx);
+ else {
+ pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),0));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),0));
+ }
+ break;
+ }
+ }
+
+ if(ifx) ifx->generated = 1;
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ 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 */
+
+
+ DEBUGpic16_emitcode(";left lit = -1","line = %d ",__LINE__);
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,size,7);
+ if(ifx) ifx->generated = 1;
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ }
+
+ if(lit == 0) {
+ int s = size;
+
+ if(rFalseIfx.condition) {
+ pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
+ }
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ while(size--)
+ pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
+
+
+ emitSKPZ;
+ if(rFalseIfx.condition) {
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
+ pic16_emitpLabel(truelbl->key);
+ }else {
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,s,7);
+ }
+
+ if(ifx) ifx->generated = 1;
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ }
+
+ if((size == 1) && (0 == (lp1&0xff))) {
+ /* lower byte of signed word is zero */
+ DEBUGpic16_emitcode(";left lit","line = %d 0x%x+1 low byte is zero",__LINE__,lit);
+ i = ((lp1 >> 8) & 0xff) ^0x80;
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit( 0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x100-i));
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
+
+
+ if(ifx) ifx->generated = 1;
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ }
+
+ if(lit & (0x80 << (size*8))) {
+ /* Lit is less than zero */
+ DEBUGpic16_emitcode(";left lit","line = %d 0x%x is less than 0",__LINE__,lit);
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,left,size,7);
+ //rFalseIfx.condition ^= 1;
+ pic16_emitpcode(POC_BTFSS, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
+ //pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
+
+ if(rFalseIfx.condition)
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
+ else
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
+
+
+ } else {
+ /* Lit is greater than or equal to zero */
+ DEBUGpic16_emitcode(";left lit","line = %d 0x%x is greater than 0",__LINE__,lit);
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,right,size,7);
+ //rFalseIfx.condition ^= 1;
+
+ //pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ //pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
+
+ pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
+ if(rFalseIfx.condition)
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
+ else
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
+
+ }
+
+
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lp1 >> (size*8)) & 0xff));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
+
+ while(size--) {
+
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lp1 >> (size*8)) & 0xff));
+ emitSKPNZ;
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
+ }
+ rFalseIfx.condition ^= 1;
+ //rFalseIfx.condition = 1;
+ genSkipc(&rFalseIfx);
+
+ pic16_emitpLabel(truelbl->key);
+
+ if(ifx) ifx->generated = 1;
+
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ // end of if (sign)
+ } else {
+
+ /* compare word or long to an unsigned literal on the right.*/
+
+
+ size--;
+ if(lit < 0xff) {
+ DEBUGpic16_emitcode ("; ***","%s %d lit =0x%x < 0xff",__FUNCTION__,__LINE__,lit);
+ switch (lit) {
+ case 0:
+ break; /* handled above */
+/*
+ case 0xff:
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ while(size--)
+ pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
+ genSkipz2(&rFalseIfx,0);
+ break;
+*/
+ default:
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ while(--size)
+ pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
+
+ emitSKPZ;
+ if(rFalseIfx.condition)
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
+ else
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
+
+
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit+1));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),0));
+
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
+ }
+
+ pic16_emitpLabel(truelbl->key);
+
+ if(ifx) ifx->generated = 1;
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ }
+
+
+ lit++;
+ DEBUGpic16_emitcode ("; ***","%s %d lit =0x%x",__FUNCTION__,__LINE__,lit);
+ i = (lit >> (size*8)) & 0xff;
+
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(i));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
+
+ while(size--) {
+ i = (lit >> (size*8)) & 0xff;
+
+ if(i) {
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(i));
+ emitSKPNZ;
+ pic16_emitpcode(POC_SUBFW, pic16_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)
+ pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
+ }
+ }
+
+
+ pic16_emitpLabel(lbl->key);
+
+ rFalseIfx.condition ^= 1;
+
+ genSkipc(&rFalseIfx);
+ }
+
+ if(sign)
+ pic16_emitpLabel(truelbl->key);
+ if(ifx) ifx->generated = 1;
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ }
+ }
+ /* Compare two variables */
+
+ DEBUGpic16_emitcode(";sign","%d",sign);
+
+ size--;
+ if(sign) {
+ /* Sigh. thus sucks... */
+ if(size) {
+ pCodeOp *pctemp;
+
+ pctemp = pic16_popGetTempReg(1);
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
+ pic16_emitpcode(POC_MOVWF, pctemp); //pic16_pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_XORWF, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),size));
+ pic16_emitpcode(POC_SUBFW, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_popReleaseTempReg(pctemp, 1);
+ } else {
+ /* Signed char comparison */
+ /* Special thanks to Nikolai Golovchenko for this snippet */
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),0));
+ pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),0)); /* could be any register */
+ pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(left),0));
+ pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),0));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ genSkipc(&rFalseIfx);
+
+ if(ifx) ifx->generated = 1;
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+ }
+
+ } else {
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
+ }
+
+
+ /* The rest of the bytes of a multi-byte compare */
+ while (size) {
+
+ emitSKPZ;
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(lbl->key));
+ size--;
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
+ pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
+
+
+ }
+
+ pic16_emitpLabel(lbl->key);
+
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ if ((AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) ||
+ (AOP_TYPE(result) == AOP_REG)) {
+ pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),0));
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),0));
+ } else {
+ genSkipc(&rFalseIfx);
+ }
+ //genSkipc(&rFalseIfx);
+ if(ifx) ifx->generated = 1;
+
+
+ if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
+ goto check_carry;
+
+ return;
+
+ }
+
+check_carry:
+ if ((AOP_TYPE(result) != AOP_CRY)
+ && AOP_SIZE(result)) {
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ if(!ifx)pic16_emitpLabel( rFalseIfx.lbl->key );
+
+ pic16_outBitC(result);
+ } else {
+ DEBUGpic16_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
+ pic16_outBitC(result);
+ /* leave the result in acc */
+ }
+
+}
+
+#else /* old version of genCmp() */
+
+/* new version of genCmp -- VR 20041012 */
+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;
+ int willCheckCarry=0;
+ // resolvedIfx rTrueIfx;
+ symbol *truelbl;
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+
+ /* General concept:
+ * subtract right from left if at the end the carry flag is set then we
+ * know that left is greater than right */
+
+ resolveIfx(&rFalseIfx,ifx);
+ truelbl = newiTempLabel(NULL);
+ size = max(AOP_SIZE(left),AOP_SIZE(right));
+
+ DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
+
+ /* POC_CPFSGT compare f, wreg, skip if f greater than wreg
+ * POC_CPFSLT compare f, wreg, skip if f less then wreg */
+
+
+ /* 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 = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);