- pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
-
- } else {
- symbol *lbl = newiTempLabel(NULL);
-
- if(AOP_TYPE(left) == AOP_LIT) {
- DEBUGpic16_emitcode(";left lit","lit = 0x%x, sign=%d",lit,sign);
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- willCheckCarry = 1;
- else willCheckCarry = 0;
-
- /* Special cases */
- if((lit == 0) && (sign == 0)) {
- /* unsigned compare to 0 */
- DEBUGpic16_emitcode("; unsigned compare to 0","lit = 0x%x, sign=%d",lit,sign);
-
- 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 */
- DEBUGpic16_emitcode(";signed compare to literal","%d: lit = 0x%x, sign=%d",__LINE__, lit,sign);
-
- int lp1 = (lit+1) & 0xff;
-
- DEBUGpic16_emitcode(";left lit","line = %d lit = 0x%x condition = %d lp1 = %i",__LINE__,lit, rFalseIfx.condition, lp1);
- 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_MOVLW, pic16_popGetLit( lit ));
-
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_CPFSLT, pic16_popGet(AOP(right), 0));
- else
- pic16_emitpcode(POC_CPFSGT, pic16_popGet(AOP(right), 0));
-
- if(willCheckCarry) {
- if(!rFalseIfx.condition) { emitCLRC; emitSETC; }
- else { emitSETC; emitCLRC; }
-
- } else {
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
- }
-
-/* 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 */
- DEBUGpic16_emitcode("; unsigned compare to literal","%d: lit = 0x%x, sign=%d",__LINE__, lit,sign);
-
- switch(lit & 0xff ) {
- /* special cases */
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
-
- 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 */
- }
-
-}
-#endif /* } */
-
-
-#endif /* } */
-
-
-
-/*-----------------------------------------------------------------*/
-/* genCmpGt :- greater than comparison */
-/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
-
- DEBUGpic16_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 */
- pic16_aopOp (left,ic,FALSE);
- pic16_aopOp (right,ic,FALSE);
- pic16_aopOp (result,ic,TRUE);
-
- genCmp(right, left, result, ifx, sign);
-
- pic16_freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- pic16_freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- pic16_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 ;
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);