从arm程序集调用c函数时如何传递长长类型参数? [英] How to pass a long long-typed parameter when calling c function from arm assembly?

查看:28
本文介绍了从arm程序集调用c函数时如何传递长长类型参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C 函数看起来像:

I have a C function witch looks like:

int foo(int a, long long b);

我试图从 arm assembly 调用它,但我不知道如何处理第二个参数(long long).

I'm trying to call it from arm assembly, but I don't know how to deal with the second parameter(long long).

推荐答案

ARM EABI/AAPCS 指定 64 位类型应该在 2 个相邻的寄存器中传递,并且第一个寄存器必须是偶数编号.在小端模式下,高位部分位于编号较高的寄存器中,而低位部分则位于编号较低的寄存器中.在大端模式下,反之亦然.

The ARM EABI/AAPCS specifies that 64bit types should be passed in 2 registers which are next to each other and the first register must be even numbered. In little endian mode the high part resides in the higher numbered register, while the low part is put in the lowered numbered one. In big endian mode it's vice versa.

这两个要求都是为了适应 strd/ldrd 指令,它可以在一条指令中保存两个寄存器.

Both requirements are there to accomodate the strd/ldrd instructions, which can save two registers in a single instructions.

因此,要在小端模式下为您的示例传递 0x0123456789abcdef,您必须按以下方式加载寄存器:

So, to pass 0x0123456789abcdef for your example in little endian mode you have to load the registers in the following way:

mov r0, a
// R1 is unused
ldr r2, =0x89abcdef
ldr r3, =0x01234567

这篇关于从arm程序集调用c函数时如何传递长长类型参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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