GDB调试arm汇编程序-入门

2018-11-22  本文已影响0人  勤学奋进小郎君

程序生成步骤

转自:https://azeria-labs.com/writing-arm-assembly-part-1/

只编译不链接形成.o文件。里面包含了对各个函数的入口标记,描述,当程序要执行时还需要链接(link)
链接就是把多个.o文件链成一个可执行文件

as helloworld.s -o helloworld.o
ld helloworld.o -o helloworld

GDB调试

程序代码

.data
var1: .word 3
var2: .word 4

.text
.global _start

_start:
    ldr r0, adr_var1         @ load the memory address of var1 via label adr_var1 to R0
    ldr r1, adr_var2         @ load the memory address of var2 via label adr_var2 to R1
    ldr r2, [r0]             @ load the value (0x03) at memory address found in R0 to R2
    str r2, [r1, r2, LSL#2]  @ address mode: offset. Store the value found in R2 (0x03) to the memory address found in R1 with the offset R2 left-shifted by 2. Base register (R1) unmodified.
    str r2, [r1, r2, LSL#2]! @ address mode: pre-indexed. Store the value found in R2 (0x03) to the memory address found in R1 with the offset R2 left-shifted by 2. Base register modified: R1 = R1 + R2<<2
    ldr r3, [r1], r2, LSL#2  @ address mode: post-indexed. Load value at memory address found in R1 to the register R3. Then modifiy base register: R1 = R1 + R2<<2
    bkpt

adr_var1: .word var1
adr_var2: .word var2
gdb helloworld
break _start
run 或者 r
nexti 3

x:十六进制,i:指令

x/10i $pc
info registers
或者: i r

x:十六进制
w:word,字类型

x/w 0x0001009F
上一篇 下一篇

猜你喜欢

热点阅读