I am studying for an ARM test and I have this code
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
And I'm debugging it with Keil, my problem is that I don't understand very well the instructionts marked.
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
I have this if I dissasembly it with Keil, then I know that LDR R2, =serie
its the same that LDR R2,[PC, #offset]
but the value of #offset are placed in the Literal Pool? I don't know why the value is 0x001C
.
PD: Sorry for my english, I know its not very good.
Here is an object dump of your program (modified to run on 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.
There is a .text section for the program and .data section for the data (DCD, DCB). At the end of the program, there are two words that will contain the address of the .data section that are defined "serie" and "resul". The address of those address in ldr r2, [pc, #28]
is the value of the pc reg + dec 28 = hex 2c. The same is true with the ldr r2, [pc, #8]
, value in the pc reg + dec 8 = hex 30.
User contributions licensed under CC BY-SA 3.0