nasm生成elf文件

生成elf文件並非只能用gcc。nasm可以生成各個平臺的中間文件和可執行文件。下面我們用nasm來生成hello.o:
先寫一個hello.s源文件

section .data
	msg: db "hello world!",0ah,0dh;
	msglen: equ $ - msg;
section .text 
	global main
main: 
	mov eax,4;
	mov ebx,1;
	mov ecx,msg;
	mov edx,14;
	int 80h;
	mov eax,1;
	mov ebx,0;
	int 80h;
 

再用命令:
nasm -f elf hello.s
便可生成hello.o文件,但是這個文件不能夠使用gcc的鏈接器,因爲是386和32位的,我們來看下其header信息:
header
我們來看下其符號表:
在這裏插入圖片描述
可以看到msg和msglen兩個定義的變量,並且,nasm自動生成了main符號。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章