- 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));
-
- pic14_emitcode("movf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- default:
- emitpcode(POC_MOVLW, popGetLit(t));
- emitpcode(POC_IORFW, popGet(AOP(left),offset));
- emitpcode(POC_MOVWF, popGet(AOP(result),offset));
-
- pic14_emitcode("movlw","0x%x",t);
- pic14_emitcode("iorwf","%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_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:
- 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:
- emitpcode(POC_COMFW,popGet(AOP(left),offset));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset));
- pic14_emitcode("comf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- break;
- default:
- 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';
- pic14_emitcode(bp1,"");
- addpCode2pBlock(pb,newpCodeInlineP(bp1));
- bp1 = bp;
- } else {
- if (*bp == ':') {
- bp++;
- *bp = '\0';
- bp++;
- pic14_emitcode(bp1,"");
- bp1 = bp;
- } else
- bp++;
- }
- }
- if (bp1 != bp) {
- pic14_emitcode(bp1,"");
- addpCode2pBlock(pb,newpCodeInlineP(bp1));
- }
- /* pic14_emitcode("",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));
- }
- emitCLRC;
- 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_MOVWF, popGet(AOP(result),offr));
- break;
-
- case 4:
- emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0x0f));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- break;
-
- case 5:
- emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0x0f));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- emitCLRC;
- emitpcode(POC_RRF, popGet(AOP(result),offr));
-
- break;
- case 6:
-
- emitpcode(POC_RLFW, popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0x80));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- break;
-
- case 7:
-
- emitpcode(POC_RLFW, popGet(AOP(left),offl));
- emitpcode(POC_CLRF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr));
-
- break;
-
- default:
- break;
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* shiftL1Left2Result - shift left one byte from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftL1Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
-{
- int same;
-
- // char *l;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- same = ((left == result) || (AOP(left) == AOP(result))) && (offl==offr);
- DEBUGpic14_emitcode ("; ***","same = %d",same);
- // l = aopGet(AOP(left),offl,FALSE,FALSE);
- // MOVA(l);
- /* shift left accumulator */
- //AccLsh(shCount); // don't comment out just yet...
- // aopPut(AOP(result),"a",offr);
-
- switch(shCount) {
- case 1:
- /* Shift left 1 bit position */
- emitpcode(POC_MOVFW, popGet(AOP(left),offl));
- if(same) {
- emitpcode(POC_ADDWF, popGet(AOP(left),offl));
- } else {
- emitpcode(POC_ADDFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
- break;
- case 2:
- emitpcode(POC_RLFW, popGet(AOP(left),offl));
- emitpcode(POC_ANDLW,popGetLit(0x7e));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr));
- emitpcode(POC_ADDWF,popGet(AOP(result),offr));
- break;
- case 3:
- emitpcode(POC_RLFW, popGet(AOP(left),offl));
- emitpcode(POC_ANDLW,popGetLit(0x3e));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr));
- emitpcode(POC_ADDWF,popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- break;
- case 4:
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0xf0));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr));
- break;
- case 5:
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0xf0));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr));
- emitpcode(POC_ADDWF,popGet(AOP(result),offr));
- break;
- case 6:
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0x30));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr));
- emitpcode(POC_ADDWF,popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- break;
- case 7:
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_CLRF, popGet(AOP(result),offr));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- break;
-
- default:
- DEBUGpic14_emitcode ("; ***","%s %d, shift count is %d",__FUNCTION__,__LINE__,shCount);
- }
-
-}
-
-/*-----------------------------------------------------------------*/
-/* movLeft2Result - move byte from left to result */
-/*-----------------------------------------------------------------*/
-static void movLeft2Result (operand *left, int offl,
- operand *result, int offr)
-{
- char *l;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!pic14_sameRegs(AOP(left),AOP(result)) || (offl != offr)){
- l = aopGet(AOP(left),offl,FALSE,FALSE);
-
- if (*l == '@' && (IS_AOP_PREG(result))) {
- pic14_emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offr);
- } else {
- emitpcode(POC_MOVFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- }
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* shiftL2Left2Result - shift left two bytes from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftL2Left2Result (operand *left, int offl,
- operand *result, int offr, int shCount)
-{
-
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- if(pic14_sameRegs(AOP(result), AOP(left))) {
- switch(shCount) {
- case 0:
- break;
- case 1:
- case 2:
- case 3:
-
- emitpcode(POC_MOVFW,popGet(AOP(result),offr));
- emitpcode(POC_ADDWF,popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16));
-
- while(--shCount) {
- emitCLRC;
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16));
- }
-
- break;
- case 4:
- case 5:
- emitpcode(POC_MOVLW, popGetLit(0x0f));
- emitpcode(POC_ANDWF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_SWAPF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_SWAPF, popGet(AOP(result),offr));
- emitpcode(POC_ANDFW, popGet(AOP(result),offr));
- emitpcode(POC_XORWF, popGet(AOP(result),offr));
- emitpcode(POC_ADDWF, popGet(AOP(result),offr+MSB16));
- if(shCount >=5) {
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16));
- }
- break;
- case 6:
- emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- emitpcode(POC_RRFW, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_ANDLW,popGetLit(0xc0));
- emitpcode(POC_XORFW,popGet(AOP(result),offr));
- emitpcode(POC_XORWF,popGet(AOP(result),offr));
- emitpcode(POC_XORFW,popGet(AOP(result),offr));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
- break;
- case 7:
- emitpcode(POC_RRFW, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRFW, popGet(AOP(result),offr));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
- emitpcode(POC_CLRF, popGet(AOP(result),offr));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- }
-
- } else {
- switch(shCount) {
- case 0:
- break;
- case 1:
- case 2:
- case 3:
- /* note, use a mov/add for the shift since the mov has a
- chance of getting optimized out */
- emitpcode(POC_MOVFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- emitpcode(POC_ADDWF, popGet(AOP(result),offr));
- emitpcode(POC_RLFW, popGet(AOP(left),offl+MSB16));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
-
- while(--shCount) {
- emitCLRC;
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16));
- }
- break;
-
- case 4:
- case 5:
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl+MSB16));
- emitpcode(POC_ANDLW, popGetLit(0xF0));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
- emitpcode(POC_ANDLW, popGetLit(0xF0));
- emitpcode(POC_XORWF, popGet(AOP(result),offr));
- emitpcode(POC_ADDWF, popGet(AOP(result),offr+MSB16));
-
-
- if(shCount == 5) {
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16));
- }
- break;
- case 6:
- emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRFW, popGet(AOP(result),offl));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
-
- emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- emitpcode(POC_RRFW, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_ANDLW,popGetLit(0xc0));
- emitpcode(POC_XORFW,popGet(AOP(result),offr));
- emitpcode(POC_XORWF,popGet(AOP(result),offr));
- emitpcode(POC_XORFW,popGet(AOP(result),offr));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
- break;
- case 7:
- emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16));
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
- emitpcode(POC_CLRF, popGet(AOP(result),offr));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- }
- }
-
-}
-/*-----------------------------------------------------------------*/
-/* shiftR2Left2Result - shift right two bytes from left to result */
-/*-----------------------------------------------------------------*/
-static void shiftR2Left2Result (operand *left, int offl,
- operand *result, int offr,
- int shCount, int sign)
-{
- int same=0;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- same = pic14_sameRegs(AOP(result), AOP(left));
-
- if(same && ((offl + MSB16) == offr)){
- same=1;
- /* don't crash result[offr] */
- MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
- pic14_emitcode("xch","a,%s", aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- } else {
- movLeft2Result(left,offl, result, offr);
- MOVA(aopGet(AOP(left),offl+MSB16,FALSE,FALSE));
- }
- /* a:x >> shCount (x = lsb(result))*/
-/*
- if(sign)
- AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
- else {
- AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount);
-*/
- switch(shCount) {
- case 0:
- break;
- case 1:
- case 2:
- case 3:
- if(sign)
- emitpcode(POC_RLFW,popGet(AOP(result),offr+MSB16));
- else
- emitCLRC;
-
- if(same) {
- emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRF,popGet(AOP(result),offr));
- } else {
- emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRFW, popGet(AOP(left),offl));
- emitpcode(POC_MOVWF,popGet(AOP(result),offr));
- }
-
- while(--shCount) {
- if(sign)
- emitpcode(POC_RLFW,popGet(AOP(result),offr+MSB16));
- else
- emitCLRC;
- emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRF,popGet(AOP(result),offr));
- }
- break;
- case 4:
- case 5:
- if(same) {
-
- emitpcode(POC_MOVLW, popGetLit(0xf0));
- emitpcode(POC_ANDWF, popGet(AOP(result),offr));
- emitpcode(POC_SWAPF, popGet(AOP(result),offr));
-
- emitpcode(POC_SWAPF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_ANDFW, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_ADDWF, popGet(AOP(result),offr));
- } else {
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
- emitpcode(POC_ANDLW, popGetLit(0x0f));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr));
-
- emitpcode(POC_SWAPFW,popGet(AOP(left),offl+MSB16));
- emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_ANDLW, popGetLit(0xf0));
- emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_ADDWF, popGet(AOP(result),offr));
- }
-
- if(shCount >=5) {
- emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16));
- emitpcode(POC_RRF, popGet(AOP(result),offr));
- }
-
- if(sign) {
- emitpcode(POC_MOVLW, popGetLit(0xf0 + (shCount-4)*8 ));
- emitpcode(POC_BTFSC,
- newpCodeOpBit(aopGet(AOP(result),offr+MSB16,FALSE,FALSE),7-shCount,0));
- emitpcode(POC_ADDWF, popGet(AOP(result),offr+MSB16));
- }
-
- break;
-
- case 6:
- if(same) {
-
- emitpcode(POC_RLF, popGet(AOP(result),offr));
- emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16));