The 64-bit Mach-O format does not support 32-bit absolute addresses. NASM

advertisements

When I use nasm -f macho64 asm1.asm I get the following error:

asm1.asm:14: error: Mach-O 64-bit format does not support 32-bit absolute addresses

This is asm1.asm

SECTION .data           ;initialized data

msg: db "Hello world, this is assembly", 10, 0

SECTION .text           ;asm code

extern printf
global _main

_main:
    push rbp
    mov rbp, rsp

    push msg
    call printf

    mov rsp, rbp
    pop rbp
    ret

I'm really new to assembly and barely know what these commands do. Any idea what's wrong here?


Mac OS X, like other UNIX/POSIX systems, uses a different calling convention for 64-bit code. Instead of pushing all the arguments to the stack, it uses RDI, RSI, RDX, RCX, R8, and R9 for the first 6 arguments. So instead of using push msg, you'll need to use something like mov RDI, msg.