Nasm使用教程:基于X86编程教学
第一个程序
在了解 nasm 之前,让我们确保你可以输入和运行程序。确保 nasm 和 gcc 都已安装。根据你的机器平台,将以下程序之一保存为 hello.asm。然后根据给定的说明运行程序。
如果你使用的是基于 Linux 的操作系统:
; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
; To assemble and run:
;
; nasm -felf64 hello.asm && ld hello.o && ./a.out
; ----------------------------------------------------------------------------------------
global _start
section .text
_start: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 60 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
section .data
message: db "Hello, World", 10 ; note the newline at the end


