Download and use the nasm compiler for assembly learning

  1. Download the nasm compiler.
    I conducted experimental learning on the centos7 virtual machine, so the corresponding results and inputs are the input and output of the command line.
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz

Use the wegt command to download the compressed package and decompress it

tar -xvzf nasm-2.14.tar.gz

Switch to the corresponding directory and compile and install

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

There will be many warnings during the compilation and installation process. I was very nervous at first, but I haven't found anything bad yet. The main warning messages are that c99 is not supported. 2.
Test the nasm compiler
and program directly in the current directory.

vim hello.s

Directly copy the assembly test code of hello, world written by an online master.

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

compile

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

Link

 ld -s hello.o -o hello.out

Finally, just run hello.out and the output will be as follows:

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

At this point, the learning and use of the nasm compiler has begun.

Supplement: Download from the official website for 64-bit systems under win10.
Just click on it to download. After downloading, the use will also be in the style of a black window.

Guess you like

Origin blog.csdn.net/weixin_44948269/article/details/117253678