ARM通用寄存器传递参数介绍

Parameters in general-purpose registers

For the purposes of function calls, the general-purpose registers are divided into four groups:
Argument registers (X0-X7)

These are used to pass parameters to a function and to return a result. They can be used as scratch registers (临时寄存器)or as caller-saved register variables(变量) that can hold intermediate(中间的) values within a function, between calls to other functions. The fact that 8 registers are available for passing parameters reduces the need to spill(溢出) parameters to the stack when compared with AArch32.

Caller-saved temporary registers (X9-X15)

If the caller requires the values in any of these registers to be preserved(保存) across a call to another function, the caller must save the affected(被影响的) registers in its own stack frame. They can be modified by the called subroutine(子程序) without the need to save and restore(恢复) them before returning to the caller.

Callee-saved registers (X19-X29)

These registers are saved in the callee frame. They can be modified by the called subroutine as long as they are saved and restored before returning.

Registers with a special purpose (X8, X16-X18, X29, X30)

• X8 is the indirect result register. This is used to pass the address location of an indirect result, for example, where a function returns a large structure.
• X16 and X17 are IP0 and IP1, intra-procedure-call temporary registers(子程序内部调用l临时寄存器).

These can be used by call veneers and similar code, or as temporary
registers for intermediate values between subroutine calls. They are
corruptible by a function. Veneers are small pieces of code which are
automatically inserted by the linker, for example when the branch target is
out of range of the branch instruction.
• X18 is the platform register and is reserved for the use of platform ABIs.

This is an additional temporary register on platforms that don’t assign a
special meaning to it.
• X29 is the frame pointer register (FP).
• X30 is the link register (LR)
在这里插入图片描述

Caller-saved register(又名易失性寄存器AKA volatile registers, or call-clobbered)用于保存不需要在各个调用之间保留的临时数量
因此,如果要在过程调用后恢复该值,则调用方有责任将这些寄存器压入堆栈或将其复制到其他位置。不过,让调用销毁这些寄存器中的临时值是正常的。从被调用方的角度来看,您的函数可以自由覆盖(也就是破坏)这些寄存器,而无需保存/恢复。

Callee-saved register(又称非易失性寄存器AKA non-volatile registers, or call-preserved)用于保存应在每次调用中保留的长寿命值。当调用者进行过程调用时,可以期望这些寄存器在被调用者返回后将保持相同的值,这使被调用者有责任在返回调用者之前保存它们并恢复它们, 还是不要碰它们

x0~x7:传递子程序的参数和返回值,使用时不需要保存,多余的参数用堆栈传递,64位的返回结果保存在x0中。
x8:保存间接结果,如返回结构体地址
x9~x15:临时寄存器,也叫可变寄存器,子程序使用时不需要保存。
x16~x17:子程序内部调用寄存器(IPx),使用时不需要保存,尽量不要用。
x18:平台寄存器,它的使用与平台相关,尽量不要使用。
x19~x28:临时寄存器,子程序使用时必须保存。
x29:帧指针寄存器(FP),用于连接栈帧,使用时必须保存。
x30:链接寄存器(LR),用于保存子程序的返回地址。
x31:堆栈指针寄存器(SP),用于指向每个函数的栈顶。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值