Hi Guys,

I’ve been porting my reusable code to C30 from BASIC/assembler with mixed results where speed is concerned.
Bitwise operation has always been clumsy in C. Below are two examples, one in asm, and one C,
that both rotate a ten byte array bitwise one place to the right.
Does anyone have a faster (not smaller) way in C?

There could be other areas I need to check such as LCD timings, etc.
dsPic is much faster, and I thought speed difference of the code would be compensated for by that.
Cheers, Art.

Code:
RotateRight ;bitwise rotate array
rrf HMK+0 ,F ;a faster way
rrf HMK+1 ,F ;
rrf HMK+2 ,F ;
rrf HMK+3 ,F ;
rrf HMK+4 ,F ;
rrf HMK+5 ,F ;
rrf HMK+6 ,F ;
rrf HMK+7 ,F ;
rrf HMK+8 ,F ;
rrf HMK+9 ,F ;
bcf HMK+0 ,7 ;preclear MSB
btfsc status ,C ;check carry bit
bsf HMK+0 ,7 ;set MSB
return ;or return
Code:
void rotateRight() {
temp = (HMK[9] << 7); // rotate HMK right once
HMK[9] = (HMK[8] << 7) | (HMK[9] >> 1);
HMK[8] = (HMK[7] << 7) | (HMK[8] >> 1);
HMK[7] = (HMK[6] << 7) | (HMK[7] >> 1);
HMK[6] = (HMK[5] << 7) | (HMK[6] >> 1);
HMK[5] = (HMK[4] << 7) | (HMK[5] >> 1);
HMK[4] = (HMK[3] << 7) | (HMK[4] >> 1);
HMK[3] = (HMK[2] << 7) | (HMK[3] >> 1);
HMK[2] = (HMK[1] << 7) | (HMK[2] >> 1);
HMK[1] = (HMK[0] << 7) | (HMK[1] >> 1);
HMK[0] = temp | (HMK[0] >> 1);
}