为什么在ARM汇编MOV(反之亦然)使用LDR? [英] Why use LDR over MOV (or vice versa) in ARM assembly?

查看:367
本文介绍了为什么在ARM汇编MOV(反之亦然)使用LDR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待通过本教程:<一href=\"http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/os/ok01.html\">http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/os/ok01.html

组件的第一行是:

ldr r0,=0x20200000

第二个是:

mov r1,#1

我觉得 LDR 是装载值从内存到寄存器中。但似乎在 = 表示0x20200000是一个值不是一个内存地址。两条线似乎装载的绝对值。

I thought ldr was for loading values from memory into registers. But it seems the = means the 0x20200000 is a value not a memory address. Both lines seem to be loading the absolute values.

推荐答案

这是一个把戏/快捷方式。比方说

It is a trick/shortcut. say for example

ldr r0,=main

会发生什么样的汇编程序将分配一个数据字,指令附近,但是指令路径之外

what would happen is the assembler would allocate a data word, near the instruction but outside the instruction path

ldr r0,main_addr
...
b somewhere
main_addr: .data main

现在展开招常数/立即数,尤其是那些不能放入一个举动立即指令:

Now expand that trick to constants/immediates, esp those that cannot fit into a move immediate instruction:

top:
add r1,r2,r3
ldr r0,=0x12345678
eor r1,r2,r3
eor r1,r2,r3
b top

然后组装拆卸

00000000 <top>:
   0:   e0821003    add r1, r2, r3
   4:   e59f0008    ldr r0, [pc, #8]    ; 14 <top+0x14>
   8:   e0221003    eor r1, r2, r3
   c:   e0221003    eor r1, r2, r3
  10:   eafffffa    b   0 <top>
  14:   12345678    eorsne  r5, r4, #125829120  ; 0x7800000

和你看到的汇编程序中加入了数据字给你,改变了LDR到pc相对一个给你。

and you see the assembler has added the data word for you and changed the ldr into a pc relative for you.

现在,如果您使用即时,它适合在一个MOV指令,然后根据汇编程序或许,肯定有,因为我使用,它变成了一个MOV我

now if you use an immediate that does fit in a mov instruction, then depending on the assembler perhaps, certainly with the gnu as I am using, it turned it into a mov for me

top:
add r1,r2,r3
ldr r0,=0x12345678
ldr r5,=1
mov r6,#1
eor r1,r2,r3
eor r1,r2,r3
b top


00000000 <top>:
   0:   e0821003    add r1, r2, r3
   4:   e59f0010    ldr r0, [pc, #16]   ; 1c <top+0x1c>
   8:   e3a05001    mov r5, #1
   c:   e3a06001    mov r6, #1
  10:   e0221003    eor r1, r2, r3
  14:   e0221003    eor r1, r2, r3
  18:   eafffff8    b   0 <top>
  1c:   12345678    eorsne  r5, r4, #125829120  ; 0x7800000

所以它基本上是一个打字快捷方式,了解你给汇编的权力,找个地方粘常数,它通常做得很好,有时会抱怨,不知道我是否已经看到了挡不它安全。有时候,你需要在code进行.ltorg或.pool鼓励汇编找个地方。

So it is basically a typing shortcut, understand that you are giving the assembler the power to find a place to stick the constant, which it usually does a good job, sometimes complains, not sure if I have seen it fail to do it safely. Sometimes you need a .ltorg or .pool in the code to encourage the assembler to find a place.

这篇关于为什么在ARM汇编MOV(反之亦然)使用LDR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆