2009-12-27 10:46 AM
RRX in C
2011-05-17 04:35 AM
I'm coding a program in which I want to load a register with a binary value and then drive a MOSFET with the binary value. I want to Rotate Right by one bit and then carry the dropped off bit to the MSB. Through some research found that the Cortex M3 instruction set supports the operation using the RRX assembler instruction but doesn't appear to carry.
I would like to use the function of RRX with carry in C and can't seem to find any equivelant C function. I have fiddled a bit with the REGISTER>>1 to shift the bit one position but looking for an easy way to carry the bit to the MSB.2011-05-17 04:35 AM
This really sounds like something that need to be done in assmebler.
In 'C', you would have to save the LSB, do the shift, then put the saved LSB into the MSB...2011-05-17 04:35 AM
Add to your project an assembly file with such function exported, see the cortex_m3.s or similar files, exporting some useful assembly functions, or use inline assembler, if allowed by compiler.
Instead of RRX, what about BFI? I guess that this instruction can spare you one additional, that needs to shift the Carry back to some register. Try this (assuming std. ASM function called from C): EXPORT __BFI __BFI: BFI r0, r0, #7, #1 BX lr In C code do something like this: u32 __BFI(u32 param); u32 variable = __BFI(register); assuming you added the assembly file to your project.