Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mach-O 64-bit format does not support 32-bit absolute addresses. NASM [duplicate]

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?

like image 994
Daniel says Reinstate Monica Avatar asked Oct 16 '14 00:10

Daniel says Reinstate Monica


1 Answers

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.

like image 142
Drew McGowen Avatar answered Nov 08 '22 18:11

Drew McGowen