This is my C code:
#include <stdio.h>
void sum();
int newAlphabet;
int main(void)
{
sum();
printf("%d\n",newAlphabet);
}
And this is my assembler code:
.globl _sum
_sum:
movq $1, %rax
movq %rax, _newAlphabet
ret
I'm trying to call the sum function, from my main function, to set newAlphabet equal to 1, but when I compile it (gcc -o test assembler.c assembler.s, compiled on a 64-bit OSX laptop) I get the following errors:
32-bit absolute addressing is not supported for x86-64 cannot do signed 4 byte relocation both caused by the line "movq %rax, _newAlphabet"
I'm sure I'm making a very basic mistake. Can anyone help? Thanks in advance.
EDIT:
Here are the relevant portions of the C code once it has been translated to assembler:
.comm _newAlphabet,4,2
...
movq _newAlphabet@GOTPCREL(%rip), %rax
_newAlphabetin the assembler? Also, I'm pretty sure thatintis 32-bits on OSX (even in x86-64).newAlphabet(i.e. without underscore)? If this does not help I would advice to compile some simple program that use this external variable with-Soption to see its assembly instructions (that is, to recognize how this variable is referenced).movinstruction (seems to be duplicate of it if I am reading correctly).