什么是ARMv6中装配=标签和[标签]之间的区别? [英] What is the difference between =label and [label] in ARMv6 assembly?

查看:180
本文介绍了什么是ARMv6中装配=标签和[标签]之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的烘焙丕<沿着以下/ A>剑桥大学,其中一个简单的操作系统是建立用于ARMv6指令集,针对树莓派路线。

我们一直在使用加载数据的两种方式为通过 LDR 指令寄存器,到目前为止,我现在意识到,我使用他们在一起,我不知道完全明白他们都做。

所以,我用的东西像 LDR R0,= 0x20200000 ,它其实我理解为读取存储在内存位置0x20200000到寄存器R0中的数据。

然后我用的东西,如:

  LDR R0,[R1,#4]

我已经理解为读取存储在内存地址中的数据指出,由R1,以4个字节偏移到寄存器R0。

然后我遇到这样的:

  LDR R0,=格局
LDR R0,[R0]

模式这里是一个 .INT 。数据部(位图重新presenting通/断状态的一个序列的LED)。我知道在阅读本文时, = foo的我的previous理解一定是错误的,否则上述两个指令会做同样的事情。

= X 语法基本都类似于C的指针,而 [X] 语法如果被指向 X 内存实际读?

假设下面 PTR 中的C是为int * ,做我的意见想着相当于总成(概念,不是字面上的)任何意义?

  R0 = PTR; / *等同于:LDR R0,= PTR * /
R0 = * PTR; / *等效于:LDR R0,[PTR] * /
R0 = *(PTR + 4)/ *等价于:LDR R0,[PTR,#4] * /


  LDR R0,=东西
...
东西:

指的标签东西的地址加载到寄存器R0。然后汇编器增加了一个字某处LDR指令的范围,并用其替换

  LDR R0,[PC,#偏移]

指令

所以这个快捷方式

  LDR R0,= 0x12345678的

表示负载为0x12345678到R0。

主要是固定长度的指令,你不能一个完整的32位立即加载到寄存器一个指令,它可以采取一些指令完全加载寄存器与一个32位的数字。很大程度上取决于数。例如:

  LDR R0,= 0x00010000在

将通过GNU汇编被替换为一条指令MOV R0,#0x00010000在如果是ARM指令,Thumb指令虽然它仍然可能要LDR R0,[PC,#偏移]

这些LDR RD =东西是一条捷径,伪指令,不是真实的。

  LDR路[RM,#偏移]
LDR路[RM,RN]

是真实的说明和地址RM从内存中读出的意思+偏移或RM + RN,并采取读出的值,并把它在寄存器rd

在=东西更像是与放大器;一些用C

  unsigned int类型的东西;
unsigned int类型R0;
无符号整型R1;R0 =安培;东西;
R1 = *(无符号整数*)R0;

和组装

 的东西:
    .word 0LDR R0,=东西
LDR R1,[R0]

I'm following along with the Baking Pi course from Cambridge University, in which a simple operating system is built in the ARMv6 instruction set, targeting the Raspberry Pi.

We've been using two ways of loading data into registers via the ldr instruction so far and I realize now that I'm using them together, I don't fully understand what they both do.

So I've used things like ldr r0,=0x20200000, which I actually understood as "read the data stored at the memory location 0x20200000 into register r0.

Then I've used things like:

ldr r0,[r1,#4]

Which I've understood as being "read the data stored at the memory address pointed to by r1, at an offset of 4 bytes, into register r0".

Then I encounter this:

ldr r0,=pattern
ldr r0,[r0]

pattern here is a .int in the .data section (a bitmap representing a sequence of on/off states for an LED). I realize upon reading this, that my previous understanding of =foo must be wrong, otherwise both of the above instructions would do the same thing.

Is the =x syntax basically more like a pointer in C, while the [x] syntax is as if the memory that is being pointed to by x is actually read?

Let's say ptr in the C below is an int*, do my comments thinking about equivalent assembly (conceptually, not literally) make any sense?

r0 = ptr;     /* equivalent to: ldr r0,=ptr     */
r0 = *ptr;    /* equivalent to: ldr r0,[ptr]    */
r0 = *(ptr+4) /* equivalent to: ldr r0,[ptr,#4] */

解决方案

ldr r0,=something
...
something:

means load the address of the label something into the register r0. The assembler then adds a word somewhere in reach of the ldr instruction and replaces it with a

ldr r0,[pc,#offset]

instruction

So this shortcut

ldr r0,=0x12345678

means load 0x12345678 into r0.

being mostly fixed length instructions, you cant load a full 32 bit immediate into a register in one instruction, it can take a number of instructions to completely load a register with a 32 bit number. Depends heavily on the number. For example

ldr r0,=0x00010000

will get replaced by the gnu assembler with a single instruction mov r0,#0x00010000 if it is an ARM instruction, for a thumb instruction though it may still have to be ldr r0,[pc,#offset]

These ldr rd,=things are a shortcut, pseudo instructions, not real.

ldr rd,[rm,#offset]
ldr rd,[rm,rn]

are real instructions and mean read from memory at address rm+offset or rm+rn and take the value read and put it in the register rd

the =something is more like &something in C.

unsigned int something;
unsigned int r0;
unsigned int r1;

r0 = &something;
r1 = *(unsigned int *)r0;

and in assembly

something:
    .word 0

ldr r0,=something
ldr r1,[r0]

这篇关于什么是ARMv6中装配=标签和[标签]之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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