汇编学习之nasm编译器下载使用

  1. 下载nasm编译器
    我是在centos7虚拟机上面进行试验学习,所以对应的结果和输入都是命令行的输入输出。
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz

使用wegt命令下载压缩包,解压

tar -xvzf nasm-2.14.tar.gz

切换到对应目录并编译安装

cd nasm-2.14
./configure
make		编译
make install		安装

编译安装过程中会出现很多warning,一开始也是很紧张,不过暂时还没发现有什么不好的现象,主要是说c99不支持之类的警告信息
2. 测试nasm编译器
直接就当前目录进行编程

vim hello.s

直接照抄网上大神的一篇hello,world的汇编测试代码

section .data                           ;section declaration
msg     db      "Hello, world!",0xA     ;our dear string
len     equ     $ - msg                 ;length of our dear string
section .text                           ;section declaration
                       ;we must export the entry point to the ELF linker or
   global _start       ;loader. They conventionally recognize _start as their
                       ;entry point. Use ld -e foo to override the default.
_start:
;write our string to stdout
       mov     eax,4   ;system call number (sys_write)
       mov     ebx,1   ;first argument: file handle (stdout)
       mov     ecx,msg ;second argument: pointer to message to write
       mov     edx,len ;third argument: message length
       int     0x80    ;call kernel
;and exit
       mov     eax,1   ;system call number (sys_exit)
       xor     ebx,ebx ;first syscall argument: exit code
       int     0x80    ;call kernel

编译

nasm -f elf64 hello.s -o hello.o

链接

 ld -s hello.o -o hello.out

最后运行hello.out就行,输出结果如下:

[root@jack nasm-2.14]# ./hello.out
Hello, world!

至此nasm编译器的学习和使用算是拉开了序幕。

补:win10下64位系统官网下载
这个直接点进去下载就可以了,下载后的使用也是黑窗口的样式的。

猜你喜欢

转载自blog.csdn.net/weixin_44948269/article/details/117253678