unix 匯程式設計序入門

2021-06-18 22:40:42 字數 1152 閱讀 9901

有兩種方式執行系統呼叫:使用c庫,或者直接系統呼叫。c庫的函式並不全部是系統呼叫外包,例如printf,malloc。直接的核心呼叫,更快速的獲得核心服務。

linux下的使用方法,eax中放呼叫號,可以在asm/unistd.h中查到。可傳遞6個引數,ebx,ecx,edx,esi,edi,ebp。如果還有更多的引數,他們將被簡單的傳成結構體作為第乙個引數。返回值放在eax中。沒有使用到棧。

section    .text

global _start            ;must be declared for linker (ld)

_start:

;tell linker entry point

movedx

,len    ;message length

movecx

,msg    ;message to write

movebx

,1    ;file descriptor (stdout)

moveax

,4    ;system call number (sys_write)

int    0x80    ;

call kernel

moveax

,1    ;system call number (sys_exit)

int    0x80    ;

call kernel

section    .data

msg    db    'hello, world!'

,0xa    ;our dear string

len    equ    $ - msg            ;

length

of our dear string

0xa代表'\n'

$ nasm -f elf hello.asm		# this will produce hello.o elf object file

$ ld -s -o hello hello.o # this will produce hello executable

./hello執行

結果類似於

write(1,msg,len);

0

給主人留下些什麼吧!~~

匯程式設計序 退出

作為第乙個匯程式設計序,本程式除了退出以外,並沒有執行其他的功能。目的 退出並向linux核心返回乙個狀態碼的簡單程式 輸入 無 輸出 返回乙個狀態碼.在執行程式後可通過輸入echo 來讀取狀態碼 變數 eax儲存系統呼叫號 ebx儲存返回狀態 section data section text g...

微機匯程式設計序

又是自學的一學期,呵呵。學到最後也就知道零星半點指令吧,複雜的程式可能還是不怎麼會寫,熟練當然也不敵c了,但是彙編之於嵌入式,往上走肯定少不了遇到,學好還是必要的!此次僅作入門吧。今日所學,明日之用。1 統計正負零的個數 datas segment array db 1,2,1,0,2,0,2,4,...

匯程式設計序呼叫c程式

首先是匯程式設計序,還是前面的例子,只是加了2行程式 extern main 說明這個函式從外面程式獲得 section data charact db a section text global start start mov ecx,charact push ecx call usestack ...