アセンブリ学習用の 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		安装

コンパイルとインストールのプロセス中に多くの警告が表示されます。最初は非常に緊張していましたが、まだ悪いものは見つかりませんでした。主な警告メッセージは、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