在android中将参数从C++传递到Assembly [英] pass parameters from C++ to Assembly in android

查看:16
本文介绍了在android中将参数从C++传递到Assembly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将超过四个参数从我的 C++ 代码传递到程序集.

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

C++ 函数看起来像:

The C++ function looks like :

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]

但这不起作用,汇编代码立即退出,并带有一些堆栈损坏输出.

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

我的完整汇编代码如下所示:http://pastie.org/3933875

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

推荐答案

我的 asm 代码从 C 到 asm 的 JNI 调用中读取第 5 个参数没有问题.这是我的 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

在不需要保留任何寄存器的情况下,第 5 个参数位于堆栈顶部:

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]

这篇关于在android中将参数从C++传递到Assembly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆