We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
You may want to experiment with the intrinsic routines, though:
http://www.keil.com/support/man/docs/c51/c51__cror_.htm
Maybe a
_cror_(dat, 1); dat &= 0x7F;
has the effect you are looking for, if the compiler acutally inlines the _cror_ and doesn't use a function.
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