我正在学习ARM测试,我有这段代码
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调试它,我的问题是我不太了解标记的指令。
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解散它,我就知道了,然后我知道LDR R2, =serie
它与LDR R2,[PC, #offset]
相同,但#offset的值放在文字池中?我不知道价值为0x001C
的原因。
答案 0 :(得分:1)
这是程序的对象转储(修改为在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.
程序的.text部分和数据的.data部分(DCD,DCB)。在程序结束时,有两个单词将包含.data部分的地址,它们被定义为“serie”和“resul”。 ldr r2, [pc, #28]
中地址的地址是pc reg + dec 28 = hex 2c的值。对于ldr r2, [pc, #8]
,pc reg + dec 8 = hex 30中的值也是如此。