通过从C ++参数大会的android参数、大会、android

2023-09-06 16:24:55 作者:像中枪一样

我想从我的C ++ code到大会通过以上四个参数。

I am trying to pass more than four parameters from my C++ code to Assembly.

C ++函数如下:

static float armFunction(float, float, float, float, float);

我可以检索从寄存器R0-R3的前四个参数没有任何问题。

I can retrieve the first four parameters from the registers r0-r3 without any problem.

我希望我的第五个浮点参数是在栈上,我应该能够使用堆栈指针SP例如进行访问我尝试加载我的R4像第五个参数:

I expect that my fifth float argument is on the stack and i should be able to access it using the stack pointer sp e.g. I try to load my fifth argument in r4 like :

ldr r4, [sp]

甚至是:

ldr r4, [sp, #-0x4]

但是,这并不工作,并装配code立即用一些堆栈损坏输出退出。

But this doesn't work and the assembly code immediately exits with some stack corruption output.

我的完整的装配code看起来像这样在这里: http://pastie.org/3933875

My complete assembly code looks like this here: http://pastie.org/3933875

推荐答案

我的ASM code毫不费力地从JNI调用读第5个参数从C到ASM。这是前两行我ASM功能:

My asm code has no trouble reading the 5th parameter from a JNI call from C to asm. Here are the first 2 lines of my asm function:

  stmfd    sp!,{r4-r12,lr}
  ldr      r12,[sp,#40]   @ first stack variable

在那里你不需要为preserve任何登记的情况下,第五个参数是堆栈的顶部:

In the case where you're not needing to preserve any registers, the 5th parameter is on the top of the stack:

  ldr r12,[sp]