# 2017q3 Homework3 (simulator) contributed by <`kevin550029`> --- ## 研究 full-stack-hello ### 組譯器使用 * 組譯 ( Assembling ): 將組合語言轉成機械語言 ``` $ ./as_exec -h Usage: as_exec [-w] [-x] [-o <out_file>] <in_file> -w Assemble <in_file> and write to an ELF file, see -o below -o if -w is specifed, <out_file> is used to store the object code -x Load <in_file> and execute it ``` * 無參數: 組譯並執行 ``` $ ./as_exec tests/hello.s Hello World ``` * -w: 組譯並輸出 ELF 格式目的檔 `tests/hello.o` * 目的檔ELF格式 ( Executable and Linking Format ) * 可用來記錄目的檔 (object file)、執行檔 (executable file)、動態連結檔 (share object)、與核心傾印 (core dump) 檔等格式,並且支援較先進的動態連結與載入等功能 * 參考 [目的檔格式 (ELF)](http://sp1.wikidot.com/elfobjfile/) ``` $ ./as_exec -w tests/hello.s ``` * -o: 組譯並輸出 ELF 到給定的路徑 ``` $ ./as_exec -o tests/hello.o -w tests/hello.s ``` * -x: 載入目的檔並執行 ``` $ ./as_exec -x tests/hello.o Hello World ``` * 用 objdump 工具分析和觀察 ELF * 可以根據目的檔案來生成可讀性比較好的彙編檔 ( 顯示二進位檔案資訊 ) ``` $ objdump -x tests/hello.o tests/hello.o: file format elf64-little tests/hello.o architecture: UNKNOWN!, flags 0x00000102: EXEC_P, D_PAGED start address 0x0000000000000000 Program Header: 0x464c457f off 0x0000000000000000 vaddr 0x0000000100000002 paddr 0x0000000000000000 align 2**54 filesz 0x0000000000000000 memsz 0x0000000000000000 flags -w- 10100 INTERP off 0x0000000000000001 vaddr 0x00000000000000e8 paddr 0x0000000000000000 align 2**5 filesz 0x0000000000000000 memsz 0x0000000000000018 flags --- 0x20 off 0x0000000000000001 vaddr 0x0000000000000100 paddr 0x0000000000000000 align 2**5 filesz 0x0000000000000000 memsz 0x000000000000001c flags --- Sections: Idx Name Size VMA LMA File off Algn SYMBOL TABLE: no symbols ``` --- ### 架構分析 專案中包含幾個部份 driver, as, elf, opcode 和 vm