【发布时间】:2016-06-15 13:27:36
【问题描述】:
我对 ARM 和 Thumb2 命令感兴趣:LDR 和 LDR.W、PC、=ADDR 用于绝对跳转到某个地址。
例如,当我从 ARM 代码跳转到 ARM 时,会执行命令 LDR PC, =ADDR。 但是在其他情况下会发生什么?
从 ARM 到 Thumb2
从 Thumb2 到 Thumb2
从 Thumb2 到 ARM
什么时候需要在地址中添加 +1?为什么?
【问题讨论】:
我对 ARM 和 Thumb2 命令感兴趣:LDR 和 LDR.W、PC、=ADDR 用于绝对跳转到某个地址。
例如,当我从 ARM 代码跳转到 ARM 时,会执行命令 LDR PC, =ADDR。 但是在其他情况下会发生什么?
从 ARM 到 Thumb2
从 Thumb2 到 Thumb2
从 Thumb2 到 ARM
什么时候需要在地址中添加 +1?为什么?
【问题讨论】:
规则其实很简单:
这就是 +1 的原因。
请注意,根据编译器和使用的标签,地址的位 0 可能由编译器自动设置。
【讨论】:
| 1会比+ 1更好的后缀,以防编译器已经调整了地址?
OR,在组装时间完成;或者由于执行错误类型的代码而导致可怕的崩溃。我想我知道我想要什么......
您只需阅读文档即可。
The following instructions write a value to the PC, treating that value as an interworking address to branch
to, with low-order bits that determine the new instruction set state:
— BLX (register), BX , and BXJ
— LDR instructions with <Rt> equal to the PC
— POP and all forms of LDM except LDM (exception return), when the register list includes the PC
— in ARM state only, ADC , ADD , ADR , AND , ASR (immediate), BIC , EOR , LSL (immediate), LSR (immediate), MOV ,
MVN , ORR , ROR (immediate), RRX , RSB , RSC , SBC , and SUB instructions with <Rd> equal to the PC and without
flag-setting specified.
由于您提到 thumb2 意味着 armv6 或更新版本。 (您说的是 thumb2 并且通常是指拇指吗?)我相信文档告诉我们上述适用于 armv6 和 armv7。
注意bit是被指令消耗的,pc在thumb模式下不携带set lsbit,它只是被指令用来指示模式改变。
还请注意,您应该考虑 OR 1 而不是 PLUS 1。如果您正确编写代码,工具链将为您提供具有正确 lsbit 的正确地址,如果您向该地址添加一个,您将破坏代码,如果你是偏执狂或没有做对,你可以或一个地址,如果它有它已经没有伤害,如果它没有,那么它解决了阻止它存在的问题。不过,在切换到拇指模式方面,我永远不会使用加一。
【讨论】: