This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

>> convert to RR not RRC

Hi,

I need to put a statement in a interrupt routine to shift a variable right one-bit. Like this:

dat >>=1;

It generated assembly code like this:

MOV A,dat
CLR C
RRC A
MOV dat,A

What statement in C language sould be written to complete the shift operation but not effect the "C,carry" bit?

This is to save the "PUSH PSW", "POP PSW" instruction in my ISR. The inline assembly statement is not good to me, since I am not familar with it.

Thanks, John

Parents Reply Children
  • cror_(dat, 1);
    dat &= 0x7F;
    

    Above program is not correct, it won't process the rotation, and it can corrected to follow one.

    dat = cror_(dat, 1);
    dat &= 0x7F;
    

    But the _cror_ is not a good choice, it cost more time than ">>". The assembly code after complied is listed as below.

    Dear Christoph, still very thanks for your suggestion.

    0053 AF00        R     MOV     R7,dat
    0055 7801              MOV     R0,#01H
    0057 EF                MOV     A,R7
    0058 08                INC     R0
    0059 8001              SJMP    ?C0016
    005B         ?C0015:
    005B 03                RR      A
    005C         ?C0016:
    005C D8FD              DJNZ    R0,?C0015
    005E F500        R     MOV     dat ,A
    0060 53007F      R     ANL     ps2dev_kb_rxdata,#07FH