I have written a small piece of assembly with AT&T syntax and have currently declared three variables in the .data
section. However, when I attempt to move any of those variables to a register, such as %eax
, an error from gcc
is raised. The code and error message is below:
.data
x:.int 14
y:.int 4
str: .string "some string\n"
.globl _main
_main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl x, %eax; #attempting to move the value of x to %eax;
leave
ret
The error raised is:
call_function.s:14:3: error: 32-bit absolute addressing is not supported in 64-bit mode
movl x, %eax;
^
I have also tried moving the value by first adding the $
character in front of x
, however, a clang
error is raised:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone know how the value stored in x
can be successfully moved to %eax
? I am using x86 assembly on Mac OSX and compiling with gcc
.
movl x(%rip), %eax
. – Jesterx(%rip)
works! If you could write an answer with an explanation, I will accept it. – Ajax1234movl x, %eax
is supported by the architecture, but you are not supposed to use it. – fuzmoffs
forms ofmov
(with a 64-bit absolute address) use themovabs
mnemonic, so plainmov
implies you want themov r32, r/m32
opcode with a ModR/M byte. The MachO64 output format doesn't support 32-bit absolute relocations at all, and the image base address is above 2^32 on OS X so a[disp32]
addressing mode can't work. Thus formov
, RIP-relative is the only option. – Peter Cordes