Topic : 'RRX' command doesn't work

Forum : ARM

Original Post
Post Information Post
July 16, 2009 - 10:35am
Guest

Hi

The assembly command 'rrx' seems not to work for me as expected, when simulating the program in IDE.
On real STM32 everything works ok. Would someone else check it, please?
Here is the code:

u32 SQRT_32(u32 s)
{
asm volatile(
"mov r0, %1\n" /* (low word) w = operand */
"mov r12, #32\n" /* loop counter = 32 */
"mov r1, #0\n" /* (high word) w = 0 */
"mov r2, r1\n" /* q = 0 (calculated square root) */
"mov r3, r1\n" /* x = 0 (temporary var) */
"rbit r0, r0\n" /* need rotate left, so reverse bit order */
"sqr32_loop:\n"
"lsls r2, r2, #1\n" /* q << 1 and clear carry */
"rbit r1, r1\n" /* w << 2 (reverse order) */
"rrxs r0, r0\n" /* here is the problem: carry flag does'n change as expected */
"rrxs r1, r1\n"
"rrxs r0, r0\n"
"rrxs r1, r1\n"
"rbit r1, r1\n" /* restotre proper order */
"cmp r3, r1\n" /* Carry = ~(x < (w>>32)) */
"bcs sqr32_fwd\n" /* if (Carry == 0) do */
"add r2, #1\n" /* q += 1 */
"sbc r1, r1, r3\n" /* w -= (x + (~Carry)) << 32 */
"orr r3, r3, #2\n" /* x |= 2 */
"sqr32_fwd:"
"lsl r3, r3, #1\n" /* x << 1 */
"subs r12, #1\n" /* decrement loop counter */
"bne sqr32_loop\n"
"mov %0, r2\n" /* result 16-bit.16-bit int.frac */

: "=r" (s)
: "r" (s)
: "cc"
);
return s;
};

Best regards

Replies
Post Information Post
+1
0
-1
July 16, 2009 - 1:54pm
Guest

I don't understand why this thread was moved - the problem lays in Ride IDE, not in microcontroller...