在ARM汇编中执行
ldr r0,[r0]
是否合法?ldr r0,[r0]
是否合法?如果有疑问,始终参考ARM架构参考手册,可以在arm.com上找到。它说:
The destination register. The SP can be used. The PC can be used, provided the
instruction is either outside an IT block or the last instruction of an IT block.
If the PC is used, the instruction branches to the address (data) loaded to the PC.
In ARMv5T and above, this branch is an interworking branch, see Pseudocode details of
operations on ARM core registers on page A2-12.
它并没有说目标寄存器不能与基址寄存器相同。也就是说,答案是“是”,它们可以相同。
这种编码对于从ARMv4开始的arm和thumb指令集都是有效的。
查看你感兴趣的系列的ARM ARM(ARM架构参考手册)(http://infocenter.arm.com)。在这种情况下,ARM7是ARMv4,与ARMv5 ARM一起被分为单独的ARM ARM(曾经是原始和唯一的ARM ARM)。
你正在寻找这样的东西:
if ConditionPassed(cond) then
Rd = (Rm * Rs)[31:0]
if S == 1 then
N Flag = Rd[31]
Z Flag = if Rd == 0 then 1 else 0
C Flag = unaffected in v5 and above, UNPREDICTABLE in v4 and earlier
V Flag = unaffected
对于乘法或这个
Specifying R15 for register <Rd>, <Rm>, or <Rs> has UNPREDICTABLE results.
或者这个
Operand restriction: Specifying the same register for <Rd> and <Rm> was previously described as producing UNPREDICTABLE results. There is no restriction in ARMv6, and it is believed all relevant ARMv4 and ARMv5 implementations do not require this restriction either, because high performance multipliers read all their operands prior to writing back any results.
ldr r0,[r0,#+/-offset_12]!
就像你告诉指令将加载值和计算后的地址保存到r0一样,它是不可预测的,只有一个可以获胜,听起来就像是个抛硬币的事情。如果末尾没有!,那么只有加载的值会被写入r0。而且关于限制没有任何注释(在原始ARM ARM的rev I中,回溯到rev B和C以及E的印刷版本,它们在这方面各不相同,这就是为什么我认为arm使用了“相关”这个术语)。对于上面剪切和粘贴的mul指令。
Thumb指令对限制或不可预测的行为没有任何注释。
现在,如果你在标签中加上ARM7是指ARMv7,请查看其中一个ARMv7手册
对于ARMv7来自ARMv7-AR手册的同样问题:
LDR<c> <Rt>, [<Rn>, #+/-<imm12>]!
if wback && n == t then UNPREDICTABLE;
除此之外,使用该指令的方式没有任何限制,也可以使用r15。