安装
安装很简单,直接在终端输入以下命令即可
sudo apt-get install nasm
安装完成后,如果可以查看到nasm的版本号即可视为安装成功
nasm -version
测试
创建汇编文件
创建一个asm文件
vim hello.asm
文件内容如下
section .datahello: db 'Hello world!',10 ; 'Hello world!' plus a linefeed characterhelloLen: equ $-hello ; Length of the 'Hello world!' string; (I'll explain soon)section .textglobal _start_start:mov eax,4 ; The system call for write (sys_write)mov ebx,1 ; File descriptor 1 - standard outputmov ecx,hello ; Put the offset of hello in ecxmov edx,helloLen ; helloLen is a constant, so we don't need to say; mov edx,[helloLen] to get it's actual valueint 80h ; Call the kernelmov eax,1 ; The system call for exit (sys_exit)mov ebx,0 ; Exit with return code of 0 (no error)int 80h
编译
nasm -f elf64 hello.asm
链接
ld -s -o hello hello.o
运行
./hello
输出hello world!