0

I'm trying to write a simple x64 assembly program on mac using nasm. Here is my program:

global start

section .text
start:
    mov r10, 3; Store 3 to r10
    mov r9, 4; Store 4 to r9
    mov rax, r10; Move 3 to rax because multiply needs an arg in rax
    mul r9; Multiply 3*4. Result in rax.
    mov r9, rax; Move result back to r9.
    mov [myVar], r9; Store result to global
    mov r11, [myVar]; Load global result into r11
    mov rdi, r11; Move result into rax, the argument for syscall
    mov rax, 0x02000001; Select exit system call
    syscall

section .bss
myVar:
    resq 1

I'm assembling using this command:

nasm -fmacho64 test.s

I get this error:

test.s:10: error: Mach-O 64-bit format does not support 32-bit absolute addresses
test.s:11: error: Mach-O 64-bit format does not support 32-bit absolute addresses

What am I missing? I just want a 64 bit global variable I can read to and write from.

Drew
  • 12,578
  • 11
  • 58
  • 98
  • 1
    Try changing `[myVar]` to `[rel myVar]`. – fuz Mar 24 '18 at 08:53
  • 1
    Or simply use `default rel` at the top of your file, because absolute is unfortunately the default. – Peter Cordes Mar 24 '18 at 10:08
  • Thanks, that worked. If you want to make this comment an answer I can mark it correct. – Drew Mar 24 '18 at 18:11
  • It's a duplicate; I'm in the middle of sorting out the dozen or so exact duplicates of this with the same error message and similar answers, trying to find the best one to close all the others as duplicates of it. I guess I can close this now and edit the duplicate list later if needed. – Peter Cordes Mar 24 '18 at 19:59

0 Answers0