ARM汇编-访问参数vs返回值? [英] ARM assembly - access parameter vs return value?

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

问题描述

我有一个函数原型 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的地址保留在被调用者保存的寄存器(X19-X29)中,并在每次调用回文式时将其复制到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汇编-访问参数vs返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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