1

My code:

section .data
   res db 0

section .text
   global _main
   extern _printf
   extern _scanf

_main
   ..blablabla.....
   mov rax,[res]
   ..blablbabla....
ret

And error: Mach-O 64-bit format does not support 32-bit absolute addresses on mov rax,[res].

So, in macho64, I can't link res, in [res]?

What should I do?

nrz
  • 10,435
  • 4
  • 39
  • 71
Aleeewka
  • 41
  • 1
  • 2

1 Answers1

1

I don't know macho64 format, but there are alternatives to mov rax,[res]:

mov rax,res
mov rax,[rax]

Or using RIP-relative addressing:

mov rax,[rel res]
nrz
  • 10,435
  • 4
  • 39
  • 71
  • Thx, nrz. I repeat it tomorrow! :) – Aleeewka Mar 11 '13 at 13:48
  • `rel` should be your first suggestion, or a `default rel` directive. Also, `mov rax, res` will assemble to `mov r64, imm64`, with a 64-bit absolute address. `lea rdi, [rel res]` is a more efficient (and smaller, and position-independent) way to get the pointer in a register. Or for AL/AX/EAX/RAX specifically, you *can* use a 64-bit absolute address if you really want: `mov rax, [qword res]` to get something like `48 a1 8a 00 40 00 00 00 00 00 movabs rax,ds:0x40008a`. But RIP-relative is more efficient. – Peter Cordes Mar 24 '18 at 11:06