-
- }
-#endif // _swapp
-
- if(AOP_TYPE(left) == AOP_LIT) {
- //symbol *lbl = newiTempLabel(NULL);
-
- //EXPERIMENTAL lit = (unsigned long)(floatFromVal(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(((-(lit+1)) & 0xff) ^ 0x80));
- rFalseIfx.condition ^= 1;
- genSkipc(&rFalseIfx);
- 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:
- rFalseIfx.condition ^= 1;
- 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);
- 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);
-
-
- 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);
-
- 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);
- }
-
- 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);
- }
-
- 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);
-
- 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);
- }
- //genSkipc(&rFalseIfx);
- 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 */
- }
-
-}
-
-/*-----------------------------------------------------------------*/
-/* genCmpGt :- greater than comparison */
-/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
-
- 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 ;
-
- 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);
-}
-
-/*-----------------------------------------------------------------*/
-/* genc16bit2lit - compare a 16 bit value to a literal */
-/*-----------------------------------------------------------------*/
-static void genc16bit2lit(operand *op, int lit, int offset)
-{
- int i;
-
- 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));
-
- }
-
-}
-
-/*-----------------------------------------------------------------*/
-/* gencjneshort - compare and jump if not equal */
-/*-----------------------------------------------------------------*/
-static void gencjne(operand *left, operand *right, operand *result, iCode *ifx)
-{
- int size = max(AOP_SIZE(left),AOP_SIZE(right));
- int offset = 0;
- int res_offset = 0; /* the result may be a different size then left or right */
- int res_size = AOP_SIZE(result);
- resolvedIfx rIfx;
- symbol *lbl;
-
- unsigned long lit = 0L;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- DEBUGpic14_AopType(__LINE__,left,right,result);
- if(result)
- DEBUGpic14_emitcode ("; ***","%s %d result is not null",__FUNCTION__,__LINE__);
- resolveIfx(&rIfx,ifx);
- lbl = newiTempLabel(NULL);
-
-
- /* 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 = (unsigned long)floatFromVal(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:
- 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++;
- if(res_offset < res_size-1)
- res_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) {
- emitpcode(POC_CLRF,popGet(AOP(result),res_offset));
- //emitpcode(POC_INCF,popGet(AOP(result),res_offset));
- }else {
- 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: */
- 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));
- //emitpcode(POC_INCF,popGet(AOP(result),res_offset));
- }
- if(ifx)
- ifx->generated=1;
- }
- emit_skip++;
- offset++;
- if(res_offset < res_size-1)
- res_offset++;
- }
-/* break; */
-/* } */
- } else if(AOP_TYPE(right) == AOP_REG &&
- AOP_TYPE(left) != AOP_DIR){
-
- 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++;
- if(res_offset < res_size-1)
- res_offset++;
- }
-
- }else{
- /* right is a pointer reg need both a & b */
- 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),res_offset));
- if(!rIfx.condition)
- emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
-
- emitpLabel(lbl->key);
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- if(ifx)
- ifx->generated = 1;
-}
-
-#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;
- unsigned long lit = 0L;
- int size,offset=0;
-
- 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);
-
- size = max(AOP_SIZE(left),AOP_SIZE(right));
-
- DEBUGpic14_AopType(__LINE__,left,right,result);
-
- /* if literal, literal on the right or
- if the right is in a pointer register and left
- is not */
- if ((AOP_TYPE(IC_LEFT(ic)) == AOP_LIT) ||
- (IS_AOP_PREG(right) && !IS_AOP_PREG(left))) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
-
-
- if(ifx && !AOP_SIZE(result)){
- symbol *tlbl;
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if(lit == 0L){
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("cpl","c");
- } else if(lit == 1L) {
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- pic14_emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("jb","%s,%05d_DS_",AOP(right)->aopu.aop_dir,(lbl->key+100));
- pic14_emitcode("cpl","c");
- pic14_emitcode("","%05d_DS_:",(lbl->key+100));
- }
- /* if true label then we jump if condition
- supplied is true */
- tlbl = newiTempLabel(NULL);
- if ( IC_TRUE(ifx) ) {
- pic14_emitcode("jnc","%05d_DS_",tlbl->key+100);
- pic14_emitcode("ljmp","%05d_DS_",IC_TRUE(ifx)->key+100);
- } else {
- pic14_emitcode("jc","%05d_DS_",tlbl->key+100);
- pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ifx)->key+100);
- }
- pic14_emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
-
- {
- /* left and right are both bit variables, result is carry */
- resolvedIfx rIfx;
-
- resolveIfx(&rIfx,ifx);
-
- emitpcode(POC_MOVLW,popGet(AOP(left),0));
- emitpcode(POC_ANDFW,popGet(AOP(left),0));
- emitpcode(POC_BTFSC,popGet(AOP(right),0));
- emitpcode(POC_ANDLW,popGet(AOP(left),0));
- genSkipz2(&rIfx,0);
- }
- } else {
-
- /* They're not both bit variables. Is the right a literal? */
- if(AOP_TYPE(right) == AOP_LIT) {
- lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- switch(size) {
-
- case 1:
- switch(lit & 0xff) {
- case 1:
- if ( IC_TRUE(ifx) ) {
- emitpcode(POC_DECFW,popGet(AOP(left),offset));
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- } else {
- emitpcode(POC_DECFSZW,popGet(AOP(left),offset));
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- }
- break;
- case 0xff:
- if ( IC_TRUE(ifx) ) {
- emitpcode(POC_INCFW,popGet(AOP(left),offset));
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- } else {
- emitpcode(POC_INCFSZW,popGet(AOP(left),offset));
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- }
- break;
- default:
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- if(lit)
- emitpcode(POC_XORLW,popGetLit(lit & 0xff));
- genSkip(ifx,'z');
- }
-
-
- /* end of size == 1 */
- break;
-
- case 2:
- genc16bit2lit(left,lit,offset);
- genSkip(ifx,'z');
- break;
- /* end of size == 2 */
-
- default:
- /* size is 4 */
- if(lit==0) {
- emitpcode(POC_MOVFW,popGet(AOP(left),0));
- emitpcode(POC_IORFW,popGet(AOP(left),1));
- emitpcode(POC_IORFW,popGet(AOP(left),2));
- emitpcode(POC_IORFW,popGet(AOP(left),3));
-
- } else {
-
- /* search for patterns that can be optimized */
-
- genc16bit2lit(left,lit,0);
- lit >>= 16;
- if(lit) {
- genSkipz(ifx,IC_TRUE(ifx) == NULL);
- //genSkip(ifx,'z');
- genc16bit2lit(left,lit,2);
- } else {
- emitpcode(POC_IORFW,popGet(AOP(left),2));
- emitpcode(POC_IORFW,popGet(AOP(left),3));
-
- }
-
- }
-
- genSkip(ifx,'z');
- }
-
- ifx->generated = 1;
- goto release ;
-
-
- } else if(AOP_TYPE(right) == AOP_CRY ) {
- /* we know the left is not a bit, but that the right is */
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode( ( (IC_TRUE(ifx)) ? POC_BTFSC : POC_BTFSS),
- popGet(AOP(right),offset));
- emitpcode(POC_XORLW,popGetLit(1));
-
- /* if the two are equal, then W will be 0 and the Z bit is set
- * we could test Z now, or go ahead and check the high order bytes if
- * the variable we're comparing is larger than a byte. */
-
- while(--size)
- emitpcode(POC_IORFW,popGet(AOP(left),offset));
-
- if ( IC_TRUE(ifx) ) {
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- } else {
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
-
- } else {
- /* They're both variables that are larger than bits */
- int s = size;
-
- tlbl = newiTempLabel(NULL);
-
- while(size--) {
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_XORFW,popGet(AOP(right),offset));
-
- if ( IC_TRUE(ifx) ) {
- if(size) {
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(tlbl->key));
- pic14_emitcode(" goto","_%05d_DS_",tlbl->key+100+labelOffset);
- } else {
- emitSKPNZ;
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_TRUE(ifx)->key+100+labelOffset);
- }
- } else {
- emitSKPZ;
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
- pic14_emitcode(" goto","_%05d_DS_",IC_FALSE(ifx)->key+100+labelOffset);
- }
- offset++;
- }
- if(s>1 && IC_TRUE(ifx)) {
- emitpLabel(tlbl->key);
- pic14_emitcode("","_%05d_DS_:",tlbl->key+100+labelOffset);
- }
- }
- }
- /* mark the icode as generated */
- ifx->generated = 1;
- goto release ;
- }
-
- /* if they are both bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- ((AOP_TYPE(right) == AOP_CRY) || (AOP_TYPE(right) == AOP_LIT))) {
- if(AOP_TYPE(right) == AOP_LIT){
- unsigned long lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
- if(lit == 0L){
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("cpl","c");
- } else if(lit == 1L) {
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- pic14_emitcode("clr","c");
- }
- /* AOP_TYPE(right) == AOP_CRY */
- } else {
- symbol *lbl = newiTempLabel(NULL);
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- pic14_emitcode("jb","%s,%05d_DS_",AOP(right)->aopu.aop_dir,(lbl->key+100));
- pic14_emitcode("cpl","c");
- pic14_emitcode("","%05d_DS_:",(lbl->key+100));
- }
- /* c = 1 if egal */
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)){
- pic14_outBitC(result);
- goto release ;
- }
- if (ifx) {
- genIfxJump (ifx,"c");
- goto release ;
- }
- /* if the result is used in an arithmetic operation
- then put the result in place */
- pic14_outBitC(result);
- } else {
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- gencjne(left,right,result,ifx);
-/*
- if(ifx)
- gencjne(left,right,newiTempLabel(NULL));
- else {
- if(IC_TRUE(ifx)->key)
- gencjne(left,right,IC_TRUE(ifx)->key);
- else
- gencjne(left,right,IC_FALSE(ifx)->key);
- ifx->generated = 1;
- goto release ;
- }
- if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) {
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- if (ifx) {
- genIfxJump (ifx,"a");
- goto release ;
- }
-*/
- /* if the result is used in an arithmetic operation
- then put the result in place */
-/*
- if (AOP_TYPE(result) != AOP_CRY)
- pic14_outAcc(result);
-*/
- /* leave the result in acc */
- }
-
-release:
- 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 )
-{
- /* 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; */
-
- 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;
-
- /* note here that || operations that are in an
- if statement are taken away by backPatchLabels
- only those used in arthmetic operations remain */
- 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);
-
- /* if both are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- pic14_emitcode("clrc","");
- pic14_emitcode("btfss","(%s >> 3), (%s & 7)",
- AOP(left)->aopu.aop_dir,
- AOP(left)->aopu.aop_dir);
- pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
- AOP(right)->aopu.aop_dir,
- AOP(right)->aopu.aop_dir);
- pic14_emitcode("setc","");
-
- } else {
- tlbl = newiTempLabel(NULL);
- pic14_toBoolean(left);
- emitSKPZ;
- pic14_emitcode("goto","%05d_DS_",tlbl->key+100+labelOffset);
- pic14_toBoolean(right);
- pic14_emitcode("","%05d_DS_:",tlbl->key+100+labelOffset);
-
- pic14_outBitAcc(result);
- }
-
- 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;
-
- 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)
-{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(IC_TRUE(ic))
- pic14_emitcode("ljmp","%05d_DS_",IC_TRUE(ic)->key+100);
- ic->generated = 1;
-}
-
-/*-----------------------------------------------------------------*/
-/* jmpIfTrue - */
-/*-----------------------------------------------------------------*/
-static void jumpIfTrue (iCode *ic)
-{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!IC_TRUE(ic))
- pic14_emitcode("ljmp","%05d_DS_",IC_FALSE(ic)->key+100);
- ic->generated = 1;
-}
-
-/*-----------------------------------------------------------------*/
-/* jmpTrueOrFalse - */
-/*-----------------------------------------------------------------*/
-static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
-{
- // 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;
-
-
- 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 = (unsigned long)floatFromVal (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){
-/*
- if(IC_TRUE(ifx)) {
- emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ic)->key));
- } else {
- emitpcode(POC_BTFSS,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ic)->key));
- }
-*/
- emitpcode(((rIfx.condition) ? POC_BTFSC : POC_BTFSS),
- newpCodeOpBit(aopGet(AOP(left),0,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){
- MOVA( aopGet(AOP(left),offset,FALSE,FALSE));
- // byte == 2^n ?
- if((posbit = isLiteralBit(bytelit)) != 0)
- pic14_emitcode("jb","acc.%d,%05d_DS_",(posbit-1)&0x07,tlbl->key+100);
- else{
- if(bytelit != 0x0FFL)
- pic14_emitcode("anl","a,%s",
- aopGet(AOP(right),offset,FALSE,TRUE));
- pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
- }
- }
- 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 */
- pic14_emitcode("clrf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- 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 */
- pic14_emitcode("bcf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
- emitpcode(POC_BCF,newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
-
- } else {
- pic14_emitcode("movlw","0x%x", (lit & 0xff));
- pic14_emitcode("andwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE));
- if(know_W != (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:
- pic14_emitcode("clrf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- emitpcode(POC_CLRF,popGet(AOP(result),offset));
- break;
- case 0xff:
- if(AOP_TYPE(left) != AOP_ACC) {
- pic14_emitcode("movf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- 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 {
- pic14_emitcode("movlw","0x%x",t);
- pic14_emitcode("andwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
-
- 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) {
- pic14_emitcode("andwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitpcode(POC_ANDFW,popGet(AOP(right),offset));
- } else {
- pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- pic14_emitcode("andwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitpcode(POC_MOVFW,popGet(AOP(right),offset));
- emitpcode(POC_ANDFW,popGet(AOP(left),offset));
- }
- pic14_emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- 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;
-
- 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 = (unsigned long)floatFromVal (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 != (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_IORWF, 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_IORFW, popGet(AOP(left),offset));
-
- pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- pic14_emitcode("iorwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- }
- emitpcode(POC_MOVWF, popGet(AOP(result),offset));
- pic14_emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- }
- }
-
-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;
-
- 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 = (unsigned long)floatFromVal (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 {
- 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));
- pic14_emitcode("xorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- } else {
- emitpcode(POC_MOVFW,popGet(AOP(right),offset));
- emitpcode(POC_XORFW,popGet(AOP(left),offset));
- pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- pic14_emitcode("xorwf","%s,w",aopGet(AOP(left),offset,FALSE,FALSE));
- }
- if ( AOP_TYPE(result) != AOP_ACC){
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- pic14_emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- }
- }
- }
-
- 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;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- _G.inLine += (!options.asmpeep);
-
- buffer = bp = bp1 = Safe_calloc(1, strlen(IC_INLINE(ic))+1);
- strcpy(buffer,IC_INLINE(ic));
-
- /* emit each line as a code */
- while (*bp) {
- if (*bp == '\n') {
- *bp++ = '\0';
-
- if(*bp1)
- addpCode2pBlock(pb,AssembleLine(bp1));
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- pic14_emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
- }
- }
- if ((bp1 != bp) && *bp1)
- addpCode2pBlock(pb,AssembleLine(bp1));
-
- 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;
-
- /* 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;
-
- 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);
-
- 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);
-}
-
-/*-----------------------------------------------------------------*/
-/* AccRol - rotate left accumulator by known count */
-/*-----------------------------------------------------------------*/
-static void AccRol (int shCount)
-{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- shCount &= 0x0007; // shCount : 0..7
- switch(shCount){
- case 0 :
- break;
- case 1 :
- pic14_emitcode("rl","a");
- break;
- case 2 :
- pic14_emitcode("rl","a");
- pic14_emitcode("rl","a");
- break;
- case 3 :
- pic14_emitcode("swap","a");
- pic14_emitcode("rr","a");
- break;
- case 4 :
- pic14_emitcode("swap","a");
- break;
- case 5 :
- pic14_emitcode("swap","a");
- pic14_emitcode("rl","a");
- break;
- case 6 :
- pic14_emitcode("rr","a");
- pic14_emitcode("rr","a");
- break;
- case 7 :
- pic14_emitcode("rr","a");
- break;
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* AccLsh - left shift accumulator by known count */
-/*-----------------------------------------------------------------*/
-static void AccLsh (int shCount)
-{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1)
- pic14_emitcode("add","a,acc");
- else
- if(shCount == 2) {
- pic14_emitcode("add","a,acc");
- pic14_emitcode("add","a,acc");
- } else {
- /* rotate left accumulator */
- AccRol(shCount);
- /* and kill the lower order bits */
- pic14_emitcode("anl","a,#0x%02x", SLMask[shCount]);
- }
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* AccRsh - right shift accumulator by known count */
-/*-----------------------------------------------------------------*/
-static void AccRsh (int shCount)
-{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1){
- CLRC;
- pic14_emitcode("rrc","a");
- } else {
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- pic14_emitcode("anl","a,#0x%02x", SRMask[shCount]);
- }
- }
-}
-
-#if 0
-/*-----------------------------------------------------------------*/
-/* AccSRsh - signed right shift accumulator by known count */
-/*-----------------------------------------------------------------*/
-static void AccSRsh (int shCount)
-{
- symbol *tlbl ;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(shCount != 0){
- if(shCount == 1){
- pic14_emitcode("mov","c,acc.7");
- pic14_emitcode("rrc","a");
- } else if(shCount == 2){
- pic14_emitcode("mov","c,acc.7");
- pic14_emitcode("rrc","a");
- pic14_emitcode("mov","c,acc.7");
- pic14_emitcode("rrc","a");
- } else {
- tlbl = newiTempLabel(NULL);
- /* rotate right accumulator */
- AccRol(8 - shCount);
- /* and kill the higher order bits */
- pic14_emitcode("anl","a,#0x%02x", SRMask[shCount]);
- pic14_emitcode("jnb","acc.%d,%05d_DS_",7-shCount,tlbl->key+100);
- pic14_emitcode("orl","a,#0x%02x",
- (unsigned char)~SRMask[shCount]);
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- }
- }
-}
-#endif
-/*-----------------------------------------------------------------*/
-/* shiftR1Left2Result - shift right one byte from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftR1Left2ResultSigned (operand *left, int offl,
- operand *result, int offr,
- int shCount)
-{
- int same;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
-
- switch(shCount) {
- case 1:
- emitpcode(POC_RLFW, popGet(AOP(left),offl));
- if(same)
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- else {
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
-
- break;
- case 2:
-
- emitpcode(POC_RLFW, popGet(AOP(left),offl));
- if(same)
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- else {
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
- emitpcode(POC_RLFW, popGet(AOP(result),offr));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
-
- break;
-
- case 3:
- if(same)
- emitpcode(POC_SWAPF, popGet(AOP(result),offr));
- else {
- emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
-
- emitpcode(POC_RLFW, popGet(AOP(result),offr));
- emitpcode(POC_RLFW, popGet(AOP(result),offr));
- emitpcode(POC_ANDLW, popGetLit(0x1f));
-
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
- emitpcode(POC_IORLW, popGetLit(0xe0));
-
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- break;
-
- case 4:
- emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0x0f));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
- emitpcode(POC_IORLW, popGetLit(0xf0));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- break;
- case 5:
- if(same) {
- emitpcode(POC_SWAPF, popGet(AOP(result),offr));
- } else {
- emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
- emitpcode(POC_RRFW, popGet(AOP(result),offr));
- emitpcode(POC_ANDLW, popGetLit(0x07));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
- emitpcode(POC_IORLW, popGetLit(0xf8));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- break;
-
- case 6:
- if(same) {
- emitpcode(POC_MOVLW, popGetLit(0x00));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
- emitpcode(POC_MOVLW, popGetLit(0xfe));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),6,0));
- emitpcode(POC_IORLW, popGetLit(0x01));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- } else {
- emitpcode(POC_CLRF, popGet(AOP(result),offr));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
- emitpcode(POC_DECF, popGet(AOP(result),offr));
- emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),6,0));
- emitpcode(POC_BCF, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),0,0));
- }
- break;
-
- case 7:
- if(same) {
- emitpcode(POC_MOVLW, popGetLit(0x00));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
- emitpcode(POC_MOVLW, popGetLit(0xff));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- } else {
- emitpcode(POC_CLRF, popGet(AOP(result),offr));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
- emitpcode(POC_DECF, popGet(AOP(result),offr));
- }
-
- default:
- break;
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* shiftR1Left2Result - shift right one byte from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftR1Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
-{
- int same;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
-
- /* Copy the msb into the carry if signed. */
- if(sign) {
- shiftR1Left2ResultSigned(left,offl,result,offr,shCount);
- return;
- }
-
-
-
- switch(shCount) {
- case 1:
- emitCLRC;
- if(same)
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- else {
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
- break;
- case 2:
- emitCLRC;
- if(same) {
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- } else {
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));