8.1.8 Bit-shifting Operations.
Keywords: sdccman

##
8.1.8 Bit-shifting Operations.

Bit shifting is one of the most frequently used operation in embedded programming. SDCC tries to implement bit-shift operations in the most efficient way possible, e.g.:

> unsigned char i;
> ...
> i »= 4;
> ...

generates the following code:

> mov a,_i
> swap a
> anl a,#0x0f
> mov _i,a

Typically, SDCC will not setup a loop if the shift count is known. Another example:

> unsigned int i;
> ...
> i »= 9;
> ...

will generate:

> mov a,(_i + 1)
> mov (_i + 1),#0x00
> clr c
> rrc a
> mov _i,a