Mac nasm 匯編入門


下載

brew install nasm
  • code
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 asm1.o asm1.asm
  • 錯誤鏈接命令

    ld -o asm1 -e _main asm1.o 
    
  • 提示如下

    ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
    
  • 正確鏈接

# 方式一   -macosx_version_min 10.15你的Mac版本
ld -o asm1 -e _main asm1.o -macosx_version_min 10.15 -static
# 方式二 ,會提示警告 ,如下
ld -o asm1 -e _main asm1.o -macosx_version_min 10.15 -lSystem
  • 警告如下

    ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from asm1.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM