操作系统学习笔记 002 安装NASM

下载源代码

下载地址:http://sourceforge.net/projects/nasm/files

NASM学习网址:http://www.nasm.us/doc/nasmdoc0.html

使用火狐下载源码(nasm-2.07.tar.gz),缺省存放~/Download,知道为什么装英文的了吧,否则目录是“下载”,好烦的

Make安装

切换到root用户

以后都用root用户,免得碰上莫名其妙的的问题,反正权限问题暂时不重要

# tar zxvf nasm-2.07.tar.gz

# cd nasm-2.07

# ./configure

# make

# make install

# which nasm

/usr/local/bin/nasm

安装Vim

不装Vim,Vi烦死你

# apt-get install vim

Vi基本操作

# vi hello.asm  ;新建或打开文件

Vi三种模式:命令模式(Command)、编辑模式(Insert)、末行模式(Line)

缺省进入命令模式

命令模式:按“i”进入文本输入模式

命令模式:按“:”进入末行模式

编辑模式:按“ESC”进入命令模式

末行模式:wq 保存退出,“ESC”进入命令模式

知道这些,编辑一个hello.asm就足够了

设置TAB显示4个空格:

编辑/etc/vim/vimrc,重启vim:

set ts=4            ;ts是tabstop的缩写,TAB显示为4个空格宽

set expandtab     ;设置这个之后,敲入TAB,自动展开为4个空格

 set nu              ;显示行号

set hlsearch        ;高亮查找结果

hello.asm

section .text
global main     ;导出符号到其他模块,猜测是gcc
                ;http://www.nasm.us/doc/nasmdoc6.html
main:
mov eax,4 ;   4号调用
mov ebx,1 ;   ebx送1表示输出
mov ecx,msge ; 字符串的首地址送入ecx
mov edx,14 ;  字符串的长度送入edx
int 80h ;    输出字串
mov eax,1 ;   1号调用
int 80h ;    结束 
msge:
db "Hello world!",0ah,0dh

编译运行

# nasm -f elf64 hello.asm  (elf64 or elf32)

# gcc -o hello hello.o

# ./hello

Hello world!

原文地址:https://www.cnblogs.com/zhuyingchun/p/4918417.html