- /* 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);
-}
-
-/*-----------------------------------------------------------------*/
-/* 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 {
- 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:
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- break;
- default:
- emitpcode(POC_MOVLW, popGetLit(t));
- emitpcode(POC_ANDFW,popGet(AOP(left),offset));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- }
- continue;
- }
-
- 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 {
- 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));
- }
- } 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(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 {
- emitpcode(POC_MOVFW, popGet(AOP(right),offset));
- emitpcode(POC_IORWF, 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 = 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:
- emitpcode(POC_MOVFW, popGet(AOP(left),offset));
- emitpcode(POC_MOVWF, popGet(AOP(result),offset));
-
- break;
- default:
- 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
- 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 {
- emitpcode(POC_MOVLW, popGetLit(t));
- emitpcode(POC_XORWF,popGet(AOP(left),offset));
- }
- } else {
- emitpcode(POC_MOVFW,popGet(AOP(right),offset));
- emitpcode(POC_XORWF,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 = 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:
- emitpcode(POC_MOVFW,popGet(AOP(left),offset));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- break;
- case 0xff:
- emitpcode(POC_COMFW,popGet(AOP(left),offset));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- break;
- default:
- emitpcode(POC_MOVLW, popGetLit(t));
- emitpcode(POC_XORFW,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
- emitpcode(POC_MOVFW,popGet(AOP(right),offset));
- emitpcode(POC_XORFW,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);
-}
-
-/*-----------------------------------------------------------------*/
-/* 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);
- }
-}
-
-#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);
- }
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* shiftR1Left2Result - shift right one byte from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftR1Left2ResultSigned (operand *left, int offl,
- operand *result, int offr,
- int shCount)
-{
- int same;
-
- FENTRY;
- 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;
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);