##配置開發環境 ###方法一:html
- 打開命令行,輸入指令
which nasm
查看nasm的安裝路徑,Mac系統默認安裝了nasm.通常默認返回的路徑是**/usr/bin/nasm** - 接着輸入指令
alias 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
###方法二: 若是第一種方法配置失敗了,那麼考慮第二種方法。重裝nasmmacos
brew reinstall nasm
測試helloworld代碼
- 命令行輸入指令
vim helloworld.asm
,新建helloworld文件,文件類型爲asm
##helloworld彙編代碼vim
SECTION .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
##運行結果url
Hello World!
##參考文獻spa
- https://www.zhihu.com/question/29960200
- http://type.so/assembly/mac-nasm-helloworld.html
- https://stackoverflow.com/questions/52830484/nasm-cant-link-object-file-with-ld-on-macos-mojave
- https://stackoverflow.com/questions/53974320/how-can-i-get-nasm-to-work-as-a-command-in-terminal-in-macos
- http://caswenson.com/2009_09_26_assembly_language_programming_under_os_x_with_nasm
- http://www.ruanyifeng.com/blog/2018/01/assembly-language-primer.html