欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

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

发布时间:2024/3/12 编程问答 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 汇编学习之nasm编译器下载使用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
  • 下载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 orglobal _start ;loader. They conventionally recognize _start as their;entry point. Use ld -e foo to override the default. _start: ;write our string to stdoutmov eax,4 ;system call number (sys_write)mov ebx,1 ;first argument: file handle (stdout)mov ecx,msg ;second argument: pointer to message to writemov edx,len ;third argument: message lengthint 0x80 ;call kernel ;and exitmov eax,1 ;system call number (sys_exit)xor ebx,ebx ;first syscall argument: exit codeint 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位系统官网下载
    这个直接点进去下载就可以了,下载后的使用也是黑窗口的样式的。

    总结

    以上是生活随笔为你收集整理的汇编学习之nasm编译器下载使用的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。