The 8051 family of microcontrollers has a very useful assembly instruction RRC. This instruction rotates carry into the MSB of the given register, shifts that register right by 1, and carry becomes equal to what used to be the LSB of the register.
bit NewCarry; unsigned char Data; NewCarry = Data & 0x01; Data = (Data >> 1); if (Carry){ Data = (Data | 0x80); } Carry = NewCarry;
It seems like a pain to write a full routine in assembly when there is only a single instruction that C cannot provide. When you choose to use a "higher level language" you sell your control to the author(s) of that language. As K&R did not see a use for "rotate" only "shift" is available in C. Keil has added some "keywords" to C which the standard defines as "language extension" but there is (AFAIK) no "allowance" for adding an "instruction". If you do not like what C does you MUST go assembler. A fact of life - it serves no purpose to complain. Erik
If you are interested in shifting and rolling by means of calls to assembly language subroutines from Keil C, you may find this interesting: http://www.programmersheaven.com/zone5/cat27/31937.htm Enjoy.