Declaring and accessing a global variable in C.
static int i; // declare a global variable ... i = 0; // access the global variable
The C code compiled into position independent Intel 80x86 assembler.
.comm i,4,4 ;declare i as 4 bytes aligned at 4 bytes boundary ... call __get_thunk ;get program starting address in ECX addl $_GOT_,%ecx ;calculate address of global table of addresses in ECX movl $0,i@GOT(%ecx) ;write value 0 into target address i relative from ECX
The assembler code compiled into position independent Intel 80x86 machine code.
E8 ;call 1C000000 ;target address 0000001Ch bytes away from here 81C1 ;addl target ECX D9110000 ;value 000011D9h C781 ;movl target address relative from ECX 20000000 ;target address 00000020h bytes away from ECX 00000000 ;value 00000000h