ARM汇编中带[]和不带[]的命令之间的区别
我注意到在ARM汇编中,有3种类型的加载/存储命令(据我所知,甚至可能更多).到目前为止,我已经看到:
I noticed that in ARM assembly, there are 3 types (that I known of, there are maybe even more) of load/store commands. So far I've seen:
STR R0, [R1, #4]
STR R0, [R1], #4
LDR R0, R1, #4
这些只是我所看到的命令的示例.请注意,最后一个命令是如何加载而不存储的,这是因为我还没有看到STR R0,R1,#4,所以我不知道编写该命令是否可以编译.
These are just examples of the commands I've seen. Notice how the last command is load and not store, that is because I haven't seen STR R0, R1, #4 yet, so I don't know if writing that would compile.
我知道#4表示将R1递增4(可能),但是上述命令中的[]与有什么区别?
I know that #4 means increment R1 by 4 (probably), but what are the differences with the [] in the above commands?
第一个是 preindexed
:在执行此操作之前将偏移量添加到基数:
The first one is preindexed
: the offset is added to the base before doing the operation:
STR r0, [r1, #4]
表示存储已在地址r1 + 0x4完成
Means that the store is done at address r1+0x4
请注意,存在预索引+写回.此操作将执行相同的存储操作,但是基地址将更新为该地址.因此,最后 R1 = R1 + 4
.
Note that pre-indexed + write-back exists. This operation will do the same store operation, but the base address will be updated to the address. So at the end R1 = R1 + 4
.
STR r0, [r1, #4]!
另一个是后索引的,这总是意味着回写:
The other one is post-indexed, which always means write-back:
STR r0, [r1], #4
在这种情况下,存储操作使用地址r1(无偏移),但是在存储之后基址寄存器更新为 R1 = R1 + 0x4
.
In this case, the store operation uses address r1 (Without offset), but the base register is updated to be R1 = R1 + 0x4
after the store.
对于某些说明,您可以使用一个偏移量,该偏移量是一个寄存器,有时会有一个移位.例如:
For some instructions, you can use an offset which is a register, sometimes with a shift. For example:
STR r0, [r1, r2] ; Store at address r1 + r2
STR r0, [r1, r2 LSL #2] ; Store at address r1 + r2 x 4
并非所有的加载/存储指令都可以具有所有寻址模式.
Not all load/store instructions can have all the addressing modes.