-/* 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 */