Nasm use under mac

 

# Install nasm
brew install nasm

#Create a file
we hello.asm
Write the following
msg: db "hello world!", 0x0a
len: equ $-msg
   
SECTION .text
global _main
   
kernel:
     syscall
     right
  
_main:
     rax, 0x2000004 
     rdi, 1
     mov rsi,msg
     mov rdx,len
     call kernel
   
     rax, 0x2000001 
     rdi, 0
     call kernel


# Compiler
nasm -f macho64 -o hello.o hello.asm
#link
ld hello.o -o hello -macosx_version_min 10.13 -lSystem
#run
bogon:Desktop macname$ ./hello 
hello world!




reference:
https://www.cnblogs.com/Cindy632/p/10767100.html

 

Guess you like

Origin www.cnblogs.com/sea-stream/p/11647347.html