开发者

Problem with increment in inline ARM assembly

i have the following bit of inline ARM assembly, it works in a debug build but crashes in a release build of iphone sdk 3.1. The problem is the add instructions where i am incrementing the address of the C variables output and x by 4 bytes, this is supposed to increment by the size of a float. I think when i increment at some such stage i am overwriting something, can anyone say which is the best way to handle this

Thanks

C code that the asm is replacing, sum,output and x are all floats

for(int i = 0; i< count; i++)
 sum+= output[i]* (开发者_如何学JAVA*x++)

 asm volatile(

    ".align 4 \n\t"
    "mov r4,%3    \n\t"  
    "flds s0,[%0]           \n\t"
    "0:                   \n\t"
    "flds s1,[%2]           \n\t"
    //"add %3,%3,#4         \n\t"
    "flds s2,[%1]           \n\t"
    //"add %2,%2,#4         \n\t"
    "subs r4,r4, #1         \n\t"
    "fmacs s0, s1, s2        \n\t"
    "bne 0b                 \n\t"
    "fsts s0,[%0]               \n\t"
    :
    : "r" (&sum), "r" (output), "r" (x),"r" (count)
    : "r0","r4","cc", "memory", 
        "s0","s1","s2"                         
    );


did you mean %1 to add 4 to and %3? adding to %3 could cause damage if that register is used again after your function.

asm volatile(

    ".align 4 \n\t"
    "mov r4,%3    \n\t"  
    "flds s0,[%0]           \n\t"
    "0:                   \n\t"
    "flds s1,[%2]           \n\t"
    "add %2,%2,#4         \n\t"
    "flds s2,[%1]           \n\t"
    "add %1,%1,#4         \n\t"
    "subs r4,r4, #1         \n\t"
    "fmacs s0, s1, s2        \n\t"
    "bne 0b                 \n\t"
    "fsts s0,[%0]               \n\t"
    :
    : "r" (&sum), "r" (output), "r" (x),"r" (count)
    : "r0","r4","cc", "memory", 
        "s0","s1","s2"                         
    );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜