which nasm
查看nasm的安裝路徑,Mac系統默認安裝了nasm.通常默認返回的路徑是/usr/bin/nasmalias nasm=/usr/bin/nasm
nasm -v
若是配置成功的話,就會返回nasm的版本號NASM version 2.14.02 compiled on Dec 27 2018
,macs-MacBook-Pro:~ mac$ nasm nasm: error: unable to find utility "nasm", not a developer tool or in PATH
若是第一種方法配置失敗了,那麼考慮第二種方法。重裝nasmhtml
brew reinstall nasm
vim helloworld.asm
,新建helloworld文件,文件類型爲asmSECTION .data msg: db "Hello World!", 0x0a len: equ $-msg SECTION .text global _main kernel: syscall ret _main: mov rax,0x2000004 mov rdi,1 mov rsi,msg mov rdx,len call kernel mov rax,0x2000001 mov rdi,0 call kernel
nasm -f macho64 -o helloworld.o helloworld.asm
ld -o helloworld -e _main helloworld.o -macosx_version_min 10.13 -lSystem
./helloworld
Hello World!