ARM中LDR指令右侧的等号=是什么意思? [英] What does an equals sign = on the right side of a LDR instruction in ARM mean?

查看:364
本文介绍了ARM中LDR指令右侧的等号=是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经使用谷歌搜索了一段时间,但是我找不到与此有关的任何文档.我一直在尝试学习ARM,并一直在寻找我编写的简单的Calculator.c程序的已编译ARM汇编代码,以便了解我是否能够理解发生了什么.我一直看到的是这样的指令:

Been googling this for a while but i can't find any documentation relating to this. I've been trying to learn ARM and have been looking at the compiled ARM assembly code for a simple calculator.c program i wrote in order to see if I could understand what was going on. The thing I keep seeing is instructions like these:

LDR     R3, =__stack_chk_guard__GLIBC_2.4

LDR     R0, =aEnterOperator ; "Enter operator: "

LDR     R0, =aSIsNotAValidOp ; "%s is not a valid operator.  Enter +, -"

注意:分号后面的内容只是IDA添加的自动注释.

Note: the stuff after the semicolons is just the auto-comments added by IDA.

我的问题是,这些LDR右侧的'='是什么意思?在第一种情况下,它似乎是一些标签,指示库的加载.在第二和第三种情况下,'= a'似乎在printf的开头.我只是不太确定要这样做,因为在文档中找不到有关LDR的这种语法的任何信息.有人可以帮我理解吗?谢谢!

My question is, what does the '=' on the right side of these LDRs mean? In the first case, it seems to be some tag indicating the loading of a library; in the second and third cases, '=a' seems to be prefacing a printf. I'm just not quite sure to make of this, since I can't find anything about this syntax for LDR in the documentation. Can someone help me understand this? Thank you!

推荐答案

在LDR指令的第二个操作数开头使用等号(=)表示使用LDR伪指令.尽管ARM指令集仅支持较小范围内的立即数,但该伪指令用于通过一条指令将任意32位常数值加载到寄存器中.

The use of an equals sign (=) at the start of the second operand of the LDR instruction indicates the use of the LDR pseudo-instruction. This pseuo-instruction is used to load an arbitrary 32-bit constant value into a register with a single instruction despite the fact that the ARM instruction set only supports immediate values in a much smaller range.

如果汇编程序知道=之后的值,并且该值适合MOV或MVN指令的立即值的允许范围,则将生成MOV或MVN指令.否则,将常量值放入文字池中,并添加相对于PC的LDR指令用于将值加载到寄存器中.

If the value after the = is known by the assembler and fits in with the allowed range of an immediate value for the MOV or MVN instruction then a MOV or MVN instruction is generated. Otherwise the constant value is put into the literal pool, and a PC-relative LDR instruction is used to load the value into the register.

如果Ida在反汇编代码时正在生成这些LDR =指令,则它必须检测到在生成您正在查看的代码时,汇编程序或编译器选择了第二个选项.实际的指令类似于LDR R0, loc_1234567(或更准确地说,类似于LDR R0, [PC, #-1234]),而Ida正在为您查找loc_1234567的文字池中的值.

If Ida is generating these LDR= instructions when dissassembling code then it must have detected that the assembler or compiler chose the second option when generating the code you're looking at. The actual instruction is something like LDR R0, loc_1234567 (or more accurately something like LDR R0, [PC, #-1234]) and Ida is looking up the value in the literal pool at loc_1234567 for you.

这篇关于ARM中LDR指令右侧的等号=是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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