反彙編代碼分析

1.這裏直接給出反彙編代碼,對應的彙編代碼見 【OK6410裸機程序】點亮LED

arm-linux-objdump -D -S led.elf  > led.dis

-D ,--disassemlbe-all  Display assembler contents of all sections

-S, --source Intermix source code with disassembly


Disassembly of section .text:

00000000 <_start>:
   0: eaffffff b 4 <reset>
00000004 <reset>:
//  ldr r0, =0x70000000
   4: e3a00207 mov  r0, #1879048192; 0x70000000
   8: e3800013 orr r0, r0, #19; 0x13
   c: ee0f0f92 mcr 15, 0, r0, cr15, cr2, {4}
// ldr r0, =0x7E004000
  10: e59f0020 ldr r0, [pc, #32]; 38 <halt+0x4>
  14: e3a01000 mov r1, #0; 0x0
  18: e5801000 str r1, [r0]
// ldr r1, =0x7F008820
  1c: e59f1018 ldr r1, [pc, #24]; 3c <halt+0x8>
  20: e3a00a01 mov r0, #4096; 0x1000
  24: e5810000 str r0, [r1]
// ldr r1, =0x7F008824
  28: e59f1010 ldr r1, [pc, #16]; 40 <halt+0xc>
  2c: e3a00000 mov r0, #0; 0x0
  30: e5810000 str r0, [r1]

00000034 <halt>:
  34: eafffffe b 34 <halt>
  38: 7e004000 .word 0x7e004000
  3c: 7f008820 .word 0x7f008820
  40: 7f008824 .word 0x7f008824


2. ldr僞指令解析。僞指令沒有對應的機器碼,要轉換爲響應的機器碼指令。

對於ldr r0, =0x70000000這樣一個規律的立即數,可以直接用一條mov r0, #1879048192指令實現,對應的機器碼爲e3a00207 

cond=0b1110  無條件執行

I=1 立即數

S=0 不更新狀態爲

SBZ=0b0000 

Rd=0b0000  R0

shifter_operand=0b0010_0000_0111  

根據計算規則 shifter_operand = immed_8 Rotate_Right (rotate_imm * 2),0x07右移4位,得到0x7000_0000

   


對於ldr r0, =0x7E004000,不規則的立即數,則將0x7E004000保存在某個內存地址,再用ldr指令裝載到對應的寄存器。

  10: e59f0020 ldrr0, [pc, #32]; 38 <halt+0x4>  

38: 7e004000 .word0x7e004000

   

3. b halt 解析


halt:
b halt

對應的機器碼

00000034 <halt>:
  34: eafffffe b34 <halt>


cond=0b1110 無條件執行

L=0b0  不裝載LR寄存器

signed_immed_24=0b1111_1111_1111_11111_1111_1110

Operation
if ConditionPassed(cond) then
if L == 1 then
LR = address of the instruction after the branch instruction
PC = PC + (SignExtend_30(signed_immed_24) << 2)

(SignExtend_30(signed_immed_24) << 2) = -8

此行命令地址爲0x34, 所以PC=0x34+8. 

最後PC=PC+(-8)=0x34. 又調回原地址繼續執行,所以是死循環。

發佈了34 篇原創文章 · 獲贊 7 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章