Linux下彙編學習 1

2021-12-29 20:00:53 字數 757 閱讀 3104

教材:programming from the ground up

第乙個程式

.section .data

.section .text

.globl _start

_start:

movl $1, %eax

movl $0, %ebx

int $0x80

我們給這個名字取名為exit.s,這個程式什麼也沒有做,只是呼叫了linux的乙個exit系統呼叫,程式返回值為0,這個值我們可以通過命令echo$?去檢視。.section命令用於定義乙個段,我們這裡定義了兩個段,乙個.data段,乙個.text段。_start它是乙個符號,它是匯程式設計序的入口點,相當於c程式的main函式,.globl的意思是指明_start是乙個全域性符號,這個符號要被鏈結器用到。然後給eax暫存器傳遞了乙個值1,at&t語法中規定暫存器前面要加%符號,立即數前面要加上$符號,傳遞的1表示使用的exit系統呼叫,然後給ebx暫存器傳送了乙個值0,ebx暫存器值用於返回給作業系統。int指令是典型的中斷指令,0x80是它的中斷號。

然後我們編譯這個程式。使用as命令

as exit.s -o exit.o

然後鏈結這個程式,使用ld命令

ld exit.o -o exit

然後執行這個程式

./exit

檢視程式返回狀態是不是我們分析的0

echo $?

列印出來確實是0,看來我們前面分析的是正確的

摘自 mcgrady_tracy的專欄

Linux下彙編學習 1

教材 programming from the ground up.pdf 直接看 purpose program that exits and returns a status code back to the linux kernel input none output returns a st...

Linux 下彙編學習

linux下彙編學習 在ubuntu下用學習組合語言程式設計,在使用ld鏈結時有碰到ld i386 architecture of input file eatsyscall.o is incompatible with i386 x86 64 output的問題。很明顯,root cause 是我...

Linux下彙編學習 4

purpose this program will compute the value of 2 3 5 2 section data section text globl start start pushl 3 pushl 2 call power addl 8,esp pushl eax pus...