内联ARM程序集增量问题

时间:2010-04-25 14:43:28

标签: iphone assembly

我有以下内联ARM程序集,它在调试版本中工作但在iphone sdk 3.1的发布版本中崩溃。问题是添加指令,其中我将C变量输出的地址和x增加4个字节,这应该增加浮点数的大小。我认为当我在某个阶段增加时,我会覆盖某些东西,任何人都可以说哪种方法可以解决这个问题

由于

asm正在替换的C代码,sum,output和x都是浮点数

for(int i = 0; i< count; i++)
 sum+= output[i]* (*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"                         
    );

1 个答案:

答案 0 :(得分:0)

你的意思是%1加4和%3?如果在您的功能之后再次使用该寄存器,则添加到%3可能会造成损害。

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"                         
    );