2017-08-01 352 views
0

我爲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:對不起,我知道它不是很好。

+0

這個問題已經被多次詢問和回答了...... –

+0

是啊,我一直在尋找很多線程,但仍不明白我可以通過手動了解'serie'的地址嗎?不知道如何確定'#offset'的值,在這種情況下是'#0x001C' – Hector

+1

**你不能,彙編器/鏈接器可以。該值放置在文字池中(您不知道確切的位置),並且指令中編碼的地址偏移量被編碼。 – Jester

回答

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. 

數據(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