首页
社区
课程
招聘
[翻译]ARM汇编简介(三)内存指令-加载和存储 (上)
发表于: 2018-6-18 16:29 6540

[翻译]ARM汇编简介(三)内存指令-加载和存储 (上)

2018-6-18 16:29
6540

1.Offset form: Immediate value as the offset       偏移形式:将立即数作为偏移

  Addressing mode: Offset                                           寻址模式:偏移寻址

  Addressing mode: Pre-indexed                                 寻址模式:先索引寻址

  Addressing mode: Post-indexed                               寻址模式:后索引寻址

2.Offset form:Register as the offset                      偏移形式:将寄存器作为偏移

  Addressing mode: Offset                                            寻址模式:偏移寻址

  Addressing mode: Pre-indexed                                  寻址模式:先索引寻址

  Addressing mode: Post-indexed                                寻址模式:后索引寻址

3.Offset form:Scaled register as the offset            偏移形式:将移位寄存器作为偏移

  Addressing mode: Offset                                            寻址模式:偏移寻址

  Addressing mode: Pre-indexed                                  寻址模式:先索引寻址

  Addressing mode: Post-indexed                                寻址模式:后索引寻址

Generally, LDR is used to load something from memory into a register, and STR is used to store something from a register to a memory address.

LDR operation: loads the value at the address found in R0 to the destination register R2.

STR operation: stores the value found in R2 to the memory address found in R1.

This is how it would look like in a functional assembly program:

When we load something into a register, the brackets ([ ]) mean: the value found in the register between these brackets is a memory address we want to load something from.

When we store something to a memory location, the brackets ([ ]) mean: the value found in the register between these brackets is a memory address we want to store something to.

译者注:可参考之前的翻译https://bbs.pediy.com/thread-228309.htm

Let’s call this program ldr.s, compile it and run it in GDB to see what happens.

我们调用这个程序ldr.s,在GDB中编译并运行它,看看会发生什么


The registers on my system are now filled with the following values (keep in mind that these addresses might be different on your system):

在我的系统中的寄存器现在被充满了以下值(记住,这些地址可能是与您的系统上的值不同):



下一个将被执行的指令是一条带有偏移地址模式的STR指令(译者注: str r2, [r1, #2])。它将R2(0x00000003)存储到R1(0x00001009C)中指定的内存地址+偏移量(#2)=0x1009E所指向的内存空间中。


The next STR operation uses the pre-indexed address mode. You can recognize this mode by the exclamation mark (!). The only difference is that the base register will be updated with the final memory address in which the value of R2 will be stored. This means, we store the value found in R2 (0x3) to the memory address specified in R1 (0x1009c) + the offset (#4) = 0x100A0, and update R1 with this exact address.

下一个STR操作(译者注: str r2, [r1, #4]!)使用先索引寻址模式。你可以通过感叹号识别这个模式(!)。和偏移寻址唯一的区别是, 基址寄存器将被最终的内存地址更新,这个内存地址里储存了R2的值。这意味着,我们将在R2的值 (0x3)存储到R1中指定的内存地址 (0x1009C) +偏移(#4)=0x100A0指定的内存空间中,并用这个确切的地址更新R1。

The last LDR operation uses the post-indexed address mode. This means that the base register (R1) is used as the final address, then updated with the offset calculated with R1+4. In other words, it takes the value found in R1 (not R1+4), which is 0x100A0 and loads it into R3, then updates R1 to R1 (0x100A0) + offset (#4) =  0x100a4.

最后一个LDR指令( ldr r3, [r1], #4)使用后索引寻址模式。这意味着基址寄存器(R1)作为最终地址,然后被R1+4计算结果更新。换句话说,它需要取出R1(不是R1+ 4)的值0x100A0,将其作为地址取出内容,加载到R3中,然后将R1 更新为R1(0x100A0)+偏移(#4)=0x100A4。

下面是对正在发生的事情的一个抽象说明:



[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2018-6-20 16:39 被r0Cat编辑 ,原因:
收藏
免费 1
支持
分享
打赏 + 5.00雪花
打赏次数 1 雪花 + 5.00
 
赞赏  junkboy   +5.00 2018/06/18
最新回复 (1)
雪    币: 888
活跃值: (2365)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
转战移动安全,arm汇编是基础,收藏阅读一波,支持楼主。
2018-6-19 10:57
0
游客
登录 | 注册 方可回帖
返回
//