什么是SP(堆栈)和LR在ARM? [英] What are SP (stack) and LR in ARM?

查看:709
本文介绍了什么是SP(堆栈)和LR在ARM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一遍又一遍地阅读的定义,我仍然没有得到什么SP和LR在ARM?我明白PC(它显示下一条指令的地址),SP和LR可能是相似的,但我只是不明白它是什么。你能帮我吗?

I am reading definitions over and over again and I still not getting what are SP and LR in ARM? I understand PC (it shows next instruction's address), SP and LR probably are similar, but I just don't get what it is. Could you please help me?

编辑:如果您能举例解释一下,这将是极好的。

edit: if you could explain it with examples, it would be superb.

编辑:终于想通了LR是什么,仍然没有得到什么是SP的

edit: finally figured out what LR is for, still not getting what SP is for.

推荐答案

LR是链接寄存器用来保存返回地址的函数调用

LR is link register used to hold the return address for a function call.

SP是堆栈指针。堆栈一般是用来保持在函数调用自动变量和上下文/参数。从概念上讲,你能想到的堆栈作为一个地方,你堆您的数据。你总是堆积海贼王数据比其他和堆栈指针告诉你数据的高的栈是如何。您可以从该堆栈的顶部删除数据,并把它缩短了。

SP is stack pointer. The stack is generally used to hold "automatic" variables and context/parameters across function calls. Conceptually you can think of the "stack" as a place where you "pile" your data. You keep "stacking" one piece of data over the other and the stack pointer tells you how "high" your "stack" of data is. You can remove data from the "top" of the "stack" and make it shorter.

从ARM架构的参考:

SP,堆栈指针

寄存器R13用作指针活性堆栈

Register R13 is used as a pointer to the active stack.

在拇指$ ​​C $ C,大多数指令不能访问SP。唯一的
  可以访问的SP的指令是那些设计成使用SP用
  堆栈指针。除作为栈以外的任何目的而使用的SP
  指针pcated德$ P $。注意使用SP的不是作为一个以外的任何目的
  堆栈指针有可能打破操作的要求
  系统,调试器和其他软件系统,导致它们
  故障。

In Thumb code, most instructions cannot access SP. The only instructions that can access SP are those designed to use SP as a stack pointer. The use of SP for any purpose other than as a stack pointer is deprecated. Note Using SP for any purpose other than as a stack pointer is likely to break the requirements of operating systems, debuggers, and other software systems, causing them to malfunction.

LR,链接寄存器

寄存器R14用来从子程序存储的返回地址。在
  其他时候,LR可以用于其它目的。

Register R14 is used to store the return address from a subroutine. At other times, LR can be used for other purposes.

当一个BL或BLX指令执行子程序调用,LR设置为
  子程序的返回地址。要执行一个子程序返回,复制LR
  回到程序计数器。这是在两个一典型的做法
  方式,用BL或BLX指令进入子程序后:

When a BL or BLX instruction performs a subroutine call, LR is set to the subroutine return address. To perform a subroutine return, copy LR back to the program counter. This is typically done in one of two ways, after entering the subroutine with a BL or BLX instruction:

•使用BX lr指令返回。

• Return with a BX LR instruction.

•在子程序入口,存储到LR
  栈中表格的指令:PUSH {,LR}和
  使用匹配指令返回:POP {,PC} ...

• On subroutine entry, store LR to the stack with an instruction of the form: PUSH {,LR} and use a matching instruction to return: POP {,PC} ...

这个链接给出了一个例子一个平凡的子程序。

下面是一个例子寄存器的保存方式之前调用堆栈上,然后赶回来恢复他们的内容。

这篇关于什么是SP(堆栈)和LR在ARM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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