ARM,帮助LDR指令
问题描述:
我为ARM试验研究,我有这样的代码ARM,帮助LDR指令
AREA datos, DATA, READWRITE
long EQU 7*4
serie DCD 1, 2, 4, 6, 8, 7, 9
resul DCB 0
AREA prog, CODE, READONLY
ENTRY
mov r0, #0
eor r1, r1, r1 ;result variable
ldr r2, =serie **This one**
buc ldr r3, [r2, r0]
add r1, r1, r3
add r0, r0, #4
cmp r0, #long
bne buc
ldr r2, =resul **This one**
str r1, [r2]
fin b fin
END
而且我使用Keil调试它,我的问题是,我不很了解标志着instructionts 。
8: mov r0, #0
0x40000000 E3A00000 MOV R0,#0x00000000
9: eor r1, r1, r1 ;result variable
10:
0x40000004 E0211001 EOR R1,R1,R1
11: ldr r2, =serie
0x40000008 E59F201C LDR R2,[PC,#0x001C]
12: buc ldr r3, [r2, r0]
0x4000000C E7923000 LDR R3,[R2,R0]
13: add r1, r1, r3
0x40000010 E0811003 ADD R1,R1,R3
14: add r0, r0, #4
0x40000014 E2800004 ADD R0,R0,#0x00000004
15: cmp r0, #long
0x40000018 E350001C CMP R0,#0x0000001C
16: bne buc
17:
0x4000001C 1AFFFFFA BNE 0x4000000C
18: ldr r2, =resul
0x40000020 E59F2008 LDR R2,[PC,#0x0008]
19: str r1, [r2]
20:
0x40000024 E5821000 STR R1,[R2]
21: fin b fin
我有这样的,如果我使用Keil dissasembly它,那么我就知道LDR R2, =serie
其同样是LDR R2,[PC, #offset]
但#offset的价值被放置在文字池?我不知道为什么价值是0x001C
。
PD:对不起,我知道它不是很好。
答
这是您的程序的对象转储(修改为在Raspberry Pi上运行)。
Disassembly of section .text:
00000000 <main>:
0: e3a00000 mov r0, #0
4: e0211001 eor r1, r1, r1
8: e59f201c ldr r2, [pc, #28] ; 2c <buc+0x20>
0000000c <buc>:
c: e7923000 ldr r3, [r2, r0]
10: e0811003 add r1, r1, r3
14: e2800004 add r0, r0, #4
18: e350001c cmp r0, #28
1c: 1afffffa bne c <buc>
20: e59f2008 ldr r2, [pc, #8] ; 30 <buc+0x24>
24: e5821000 str r1, [r2]
28: e12fff1e bx lr
2c: 00000000 andeq r0, r0, r0
30: 0000001c andeq r0, r0, ip, lsl r0
Disassembly of section .data:
00000000 <serie>:
0: 00000001 andeq r0, r0, r1
4: 00000002 andeq r0, r0, r2
8: 00000004 andeq r0, r0, r4
c: 00000006 andeq r0, r0, r6
10: 00000008 andeq r0, r0, r8
14: 00000007 andeq r0, r0, r7
18: 00000009 andeq r0, r0, r9
0000001c <resul>:
1c: 00000000 andeq r0, r0, r0
Disassembly of section .ARM.attributes:
00000000 <.ARM.attributes>:
0: 00001541 andeq r1, r0, r1, asr #10
4: 61656100 cmnvs r5, r0, lsl #2
8: 01006962 tsteq r0, r2, ror #18
c: 0000000b andeq r0, r0, fp
10: 01080206 tsteq r8, r6, lsl #4
14: Address 0x00000014 is out of bounds.
数据(DCD,DCB)的程序和.data部分有.text部分。在程序结束时,有两个词将包含定义为“serie”和“resul”的.data段的地址。这些地址在ldr r2, [pc, #28]
中的地址是pc reg + dec 28 = hex 2c的值。 ldr r2, [pc, #8]
的值也是如此,pc reg + dec 8 = hex 30中的值。
+0
是的,谢谢你的解释,现在我明白了! – Hector
这个问题已经被多次询问和回答了...... –
是啊,我一直在寻找很多线程,但仍不明白我可以通过手动了解'serie'的地址吗?不知道如何确定'#offset'的值,在这种情况下是'#0x001C' – Hector
**你不能,汇编器/链接器可以。该值放置在文字池中(您不知道确切的位置),并且指令中编码的地址偏移量被编码。 – Jester