cancel
Showing results for 
Search instead for 
Did you mean: 

How to rotate lower and upper half-word of a 32-bit variable

matic
Associate III
Posted on December 28, 2015 at 10:23

Hi.

I would like to rotate lower and upper half-word of a 32-bit variable as in next example:

var = 0x12345678;  --> I would like to get 0x56781234;

How could I do this as fast as possible (time is critical)? I saw that there are some ASM instructions for that, but I don't know how to implement this in Keil in a .c file somewhere in between of a normal C code. Any suggestions?

Have a nice holidays.

2 REPLIES 2
gregstm
Senior III
Posted on December 30, 2015 at 12:38

Search for ''__ror intrinsic'' on the arm.com site. I haven't tried using intrinsics myself, (normally I write an assembly routine if things are critical). I'm sure there is some C statement that will optimise to a ROR instruction - you could try various C statements and check the listing.

matic
Associate III
Posted on December 30, 2015 at 13:19

Thanks. I already figured out that. In CMSIS libs I found a  __ROR() function. And if I look at assembly code in debugger, there is a ''ror'' instruction, which works exactly how I want.