程序生成步驟
- 寫好匯編代碼到
helloworld.s
- 編譯文件(但是沒有鏈接)
只編譯不鏈接形成.o文件。里面包含了對各個函數(shù)的入口標(biāo)記柒莉,描述纲熏,當(dāng)程序要執(zhí)行時還需要鏈接(link)
鏈接就是把多個.o文件鏈成一個可執(zhí)行文件
as helloworld.s -o helloworld.o
- 鏈接文件,形成可執(zhí)行文件
ld helloworld.o -o helloworld
GDB調(diào)試
程序代碼
.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
- 進(jìn)入調(diào)試
gdb helloworld
- 下斷點(diǎn)棚辽。在_start函數(shù)下好斷點(diǎn)
break _start
- 運(yùn)行技竟。會執(zhí)行到斷點(diǎn)位置
run 或者 r
- 向下執(zhí)行3步
nexti 3
- 查看下面的10條指令
x:十六進(jìn)制,i:指令
x/10i $pc
- 查看所有寄存器狀態(tài)數(shù)據(jù)
info registers
或者: i r
- 查看指定內(nèi)存地址存儲的數(shù)據(jù)
x:十六進(jìn)制
w:word屈藐,字類型
x/w 0x0001009F