为汇编中的子例程传递参数和返回值 [英] Passing parameters and return values for a subroutine in assembly

查看:60
本文介绍了为汇编中的子例程传递参数和返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与ARM汇编一起工作,在这里我必须编写一个遵循ARM调用约定的子例程(该子例程必须与其他地方的某些单独的更高级实现集成在一起)以传递参数和返回值.

I am working with ARM assembly, where I have to write one subroutine for which I am following the ARM calling convention(this will have to be integrated with some separate higher level implementation somewhere else ) for passing parameters and return values.

现在,在组装时,我总体上不确定这一点.

Now here is something I am not sure in general when working with assembly.

因此,按照惯例,如果我理解得很好,则从寄存器r0-r4开始按顺序传递参数,然后对其他参数使用堆栈.返回值传递到r0.

So from the convention if I understand well the arguments are passed in order starting from registers r0 - r4 and then for other arguments stacks are used. Return values are passed to r0.

现在这是我感到困惑的地方.如果我应该保存r0的上下文并在之后将其弹出,则没有办法返回结果,唯一的方法是破坏第一个参数.

Now here is what I am confused with. If I am supposed to save the context of r0 and pop it off after then there is no way to return the result, the only way it can be done is by corrupting the first argument.

有某种解决方法吗?

推荐答案

当您返回r0中的返回值时,调用方期望您将执行此操作.调用者并不希望r0仍包含与原始第一个参数相同的值,因为r0特别是返回值所在的位置.

When you pass back the return value in r0, the caller expects that you will do this. The caller does not expect that r0 will still contain the same value as the original first parameter, because r0 is specifically where the return value is.

通常, ARM调用约定要求子例程保留r4到r11 ,而不是r0到r3.所以反正没有矛盾.

Normally the ARM calling convention requires that the subroutine preserves r4 through r11, not r0 through r3. So there is no contradiction anyway.

这篇关于为汇编中的子例程传递参数和返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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