gpt4 book ai didi

c - 如何使用 NDK 在 ARM 内联汇编中执行简单循环?

转载 作者:行者123 更新时间:2023-11-30 15:40:15 25 4
gpt4 key购买 nike

我正在尝试在 ARM Assembly 中执行一个简单的循环,但每次运行时都会崩溃这是日志:

01-13 15:34:21.277: A/libc(27296): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 27312 (Thread-2932)

这是我的代码我做错了什么?

 void foo(int *pIn, int *pOut) {
//pIn contains the number of iterations the loop will have
asm volatile(
"ldr r3, %[in];"
"ldr r4, %[out];"
"ldr r5, [r3];"

"loop:; "
//here would go the code inside the loop perhaps put something in output, in this case just do nothing
"subs r5, r5, #1;"
"bne loop"

:[out] "=m" (pOut)
:[in] "m" (pIn)
:"r3","r4","r5","memory"
);
}

在 Android.mk 文件中我放置了 32 位指令

LOCAL_ARM_MODE := arm

有什么想法为什么会崩溃吗?仅当我放置循环时才会发生崩溃,在此之前我尝试移动东西并且它工作得非常好,给出了我预期的输出值。

最佳答案

问题已解决,将“r5”和“cc”添加到我的破坏列表中即可使其工作。这是工作代码:

void foo(int *pIn, int *pOut) {
//pIn contains the number of iterations the loop will have
asm volatile(
"ldr r3, %[in];"
"ldr r4, %[out];"
"ldr r5, [r3];"

"loop:; "
//here would go the code inside the loop perhaps put something in output, in this case just do nothing
"subs r5, r5, #1;"
"bne loop"

:[out] "=m" (pOut)
:[in] "m" (pIn)
:"r3","r4","r5","cc","memory"
);
}

关于c - 如何使用 NDK 在 ARM 内联汇编中执行简单循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21099160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com