当前位置:文档之家› arm通用寄存器及其别名

arm通用寄存器及其别名

AMR寄存器的别名+ APCS
默认情况下,arm处理器中的通用寄存器被称为:r0、r1...r14等,在APCS中为arm通用寄存器定义了别名。

在某些情况下(比如多人协作编辑汇编代码,或需要修改其它人所写的汇编代码时),使用APCS所定义的别名有助于提高代码的可读性和兼容性。

arm通用寄存器及其别名对照表:
The following register names are predeclared:
r0-r15 and R0-R15
a1-a4 (argument, result, or scratch registers, synonyms for r0 to r3)
v1-v8 (variable registers, r4 to r11)
sb and SB (static base, r9)
ip and IP (intra-procedure-call scratch register, r12)
sp and SP (stack pointer, r13)
lr and LR (link register, r14)
pc and PC (program counter, r15).
arm中r12的用途
原文作者在维护1个以前的程序,该程序包括应用、库文件以及linux device driver。

该程序原来使用arm-linux-gcc 3.4.3编译,现在改用arm-linux-gcc 4.1.1进行编译时发现程序无法运行。

经原文作者测试,发现当使用shared library形式编译程序后无法运行,而使用static linking形式编译程序后可正常运行。

这是由于在arm-linux-gcc 4.1.1所使用的新的规范中,r12不仅作为通用寄存器,还被称为Intra-Procedure-call scratch register。

Register r12 (IP) may be used by a linker as a scratch register between a routine and any subroutine it calls (for details, see §5.3.1.1, Use of IP by the linker). It can also be used within a routine to hold intermediate values between subroutine calls
Both the ARM- and Thumb-state BL instructions are unable to address the full 32-bit address space, so it may be necessary for the linker to insert a veneer between the calling routine and the called subroutine. Veneers may also be needed to support ARM-Thumb inter-working or dynamic linking. Any veneer inserted must preserve the contents of all registers except IP (r12) and the condition code flags; a conforming program must assume that a veneer that alters IP may be inserted at any branch instruction that is exposed to a relocation that supports inter-working or long branches.
——引用自:"Procedure Call Standard for the ARM Architecture"
19th January, 2007, Richard Earnshaw.
由上述说明可知,若在汇编代码中使用了bl命令,而r12又被作为通用寄存器使用时,则r12的值可能会被链接器插入的veneer代码所修改,若是单纯的c源码则不会出现此问题。

arm中R0-R15寄存器的作用
r0-r3:被用来传递函数参数和函数返回值(可使用其别名A1~A3),在子程序调用之间,可使用r0~r3
作为任何用途。

若在被调用程序中需要使用r0~r3,则应在使用前保存这些寄存器的内容。

r4-r11:被用来存放函数局部变量(可使用其别名V1~V8)。

若在被调用程序中需要使用r4~r11,则应在使用前保存这些寄存器的内容。

r12:可作为内部调用过程寄存器ip,链接器可能会在过程链接胶合代码(比如,交互操作胶合代码)中使用ip寄存器。

在过程调用之间,可将r12用于任何用途,被调用函数在返回之前无需恢复r12。

r13:栈指针sp,通常不会将sp作为其它用途使用,在退出被调用函数时,需将sp恢复到进入时的状态。

r14:链接寄存器lr,用来保存函数返回地址,若在被调用程序中需要使用r14,则应在使用前保存r14寄存器的内容。

r15:程序计数器PC,不可将PC作为其它用途使用。

注意:在中断ISR中需要保护所有寄存器,编译器会自动保护R4~R11。

相关主题