0

I had an assigment to translate a C code to Assembly intel syntax x86.

int a;

void fg(){
   a=2;
}

int main(){
   fg();
   return a;
}

The result was this:

fg:
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR a[rip], 2
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        mov     eax, 0
        call    fg
        mov     eax, DWORD PTR a[rip]
        pop     rbp
        ret

Could someone explain to me how does the addressing of a global variable work? And what does a[rip] means exactly?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Maybe? https://stackoverflow.com/questions/42215105/understanding-rip-register-in-intel-assembly – Russ J Dec 02 '20 at 14:41
  • `a[rip]` means use position independent addressing to access `a`. The assembler/linker will figure out the distance from the current instruction pointer (rip) to `a` and use that offset. – Jester Dec 02 '20 at 14:43

0 Answers0