ARM 程序集 - 访问参数与返回值? [英] ARM assembly - access parameter vs return value?

查看:45
本文介绍了ARM 程序集 - 访问参数与返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数原型 int Palindrome(const char *c_style_string);

在ARM v8汇编中,我相信参数存储在寄存器w0中.但是,这不也是ret输出值的寄存器吗?

In ARM v8 assembly, I believe that the parameter is stored in register w0. However, isn't this also the register that ret outputs the value of?

如果是这样,我需要做什么才能使值不被覆盖?我在我的代码开头考虑了类似 mov w0, w1 的东西,这样每当我解析它时我都会将 c_style_string 称为 w1,然后编辑 w0 来存储一个 int ......这会是对吗?

If so, what do I need to do so that values do not get overwritten? I was thinking something like mov w0, w1 at the beginning of my code so that I refer to c_style_string as w1 whenever I parse through it, and then edit w0 to store an int...would this be right?

谢谢!

推荐答案

您可能希望编写符合 ARM 64 位架构的 ABI.
在上面的示例中,您可以将 c_style_string 的地址保存在Callee-saved"寄存器 (X19-X29)' 中,并在每次调用 Palindrome() 时将其复制到 x0/w0 - 我在这里假设为 Palindrome() 是一个 C 函数,因此它本身符合 ARCH 64 位 ABI.
一个理想的副作用是您的 C 代码可以始终调用您的汇编代码,反之亦然.

You may want to write your assembly code in compliance with the ABI for ARM 64-bit Architecture.
In the example above, you could keep the address for c_style_string in a 'Callee-saved' register (X19-X29)', and copy it to x0/w0 every time you are calling a Palindrome() - I am assuming here Palindrome() is a C function, and is therefore itself compliant with the ARCH 64-bit ABI.
A desirable side-effect would be that your C code could call always your assembly code, and vice-versa.

这篇关于ARM 程序集 - 访问参数与返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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