ubuntu安装开源汇编调试器NASM

时间:2024-03-12 14:25:52

安装

安装很简单,直接在终端输入以下命令即可

sudo apt-get install nasm

安装完成后,如果可以查看到nasm的版本号即可视为安装成功

nasm -version

测试

创建汇编文件

创建一个asm文件

vim hello.asm

文件内容如下

section .data
  hello:     db 'Hello world!',10    ; 'Hello world!' plus a linefeed character
  helloLen:  equ $-hello             ; Length of the 'Hello world!' string
                                     ; (I'll explain soon)

section .text
  global _start

_start:
  mov eax,4            ; The system call for write (sys_write)
  mov ebx,1            ; File descriptor 1 - standard output
  mov ecx,hello        ; Put the offset of hello in ecx
  mov edx,helloLen     ; helloLen is a constant, so we don't need to say
                       ;  mov edx,[helloLen] to get it's actual value
  int 80h              ; Call the kernel

  mov eax,1            ; The system call for exit (sys_exit)
  mov ebx,0            ; Exit with return code of 0 (no error)
  int 80h

编译

nasm -f elf64 hello.asm

链接

ld -s -o hello hello.o

运行

./hello

输出hello world!