8.1.8 Bit-shifting Operations.

Next: 8.1.9 Bit-rotation Up: 8.1 Optimizations Previous: 8.1.7 'switch' Statements Contents Index

##
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`

In general SDCC will never 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`