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

查看:98
本文介绍了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天全站免登陆