gnu as簡介

18
Wen Liao GNU AS 簡介 台南市,虎尾寮

Upload: wen-liao

Post on 05-Aug-2015

257 views

Category:

Software


0 download

TRANSCRIPT

Page 1: GNU AS簡介

Wen Liao

GNU AS 簡介

台南市,虎尾寮

Page 2: GNU AS簡介

Disclaimer

投影片資料為作者整理資料及個人意見,沒有經過嚴謹確認,請讀者自行斟酌

Page 3: GNU AS簡介

目標

介紹GNU AS以及binutils的用法

Page 4: GNU AS簡介

測試環境:Guest OS

Page 5: GNU AS簡介

測試環境:Qemu

Page 6: GNU AS簡介

關於GNU AS

● 簡稱gas,或是直接as● 組合語言是也

○ 把組合語言轉成binary的object file

Page 7: GNU AS簡介

gas原始碼組成

● Symbol○ label也是一個symbol

● directive○ .開頭的字○ 有些通用,有些和CPU平台相關

● Expression● Instruction

○ 最後會轉成機械碼的東西

Page 8: GNU AS簡介

今天不會提到的

● 巨集● 條件式directive● 除錯相關directive● 硬體架構相關

Page 9: GNU AS簡介

還記得linker script嘛?

● Sections○ .text○ .bss○ .data○ .rodata○ …

● 進入點 ● 這些全部要自行處理

Page 10: GNU AS簡介

還記得ABI嘛?

● 一樣要自己處理○ Call convention○ Frame pointer○ Call stack

Page 11: GNU AS簡介

在組合語言中一切自己來

● printf?沒這東西● 開檔案?寫東西,請愛用system call

Page 12: GNU AS簡介

兩光的Hello World

directives

Page 13: GNU AS簡介

兩光的Hello World

section

Page 14: GNU AS簡介

兩光的Hello World

symbol

Page 15: GNU AS簡介

兩光的Hello World

systemcall

r0 = write(1, hello_str, hello_len)

exit(r0)

Page 16: GNU AS簡介

兩光的Hello World

expression

Page 17: GNU AS簡介

上面是爛程式碼示範

● 好的程式碼示範 ( 感謝Scott Tasi大大)

Page 18: GNU AS簡介

回家作業:九九乘法表

● 檔案結構○ Makefile○ main.S○ multi_table.S

● 執行 ● nm 觀察● objdump 反組譯比對。看Symbol● gdb

○ Hint■ --gstabs+ 參數