title: Understanding %rip register in intel assembly
body: <p>Concerning the following small code, which was illustrated in another post about the size of structure and all the possibilities to align data correctly :</p>
  
  <pre><code>struct
  {
   char Data1;
   short Data2;
   int Data3;
   char Data4;
  } x;
  
  unsigned fun ( void )
  {
      x.Data1=1;
      x.Data2=2;
      x.Data3=3;
      x.Data4=4;
      return(sizeof(x));
  }
  </code></pre>
  
  <p>I get the corresponding disassembly (with 64 bits)</p>
  
  <pre><code>0000000000000000 &lt;fun&gt;:
     0:   55                      push   %rbp
     1:   48 89 e5                mov    %rsp,%rbp
     4:   c6 05 00 00 00 00 01    movb   $0x1,0x0(%rip)        # b &lt;fun+0xb&gt;
     b:   66 c7 05 00 00 00 00    movw   $0x2,0x0(%rip)        # 14 &lt;fun+0x14&gt;
    12:   02 00 
    14:   c7 05 00 00 00 00 03    movl   $0x3,0x0(%rip)        # 1e &lt;fun+0x1e&gt;
    1b:   00 00 00 
    1e:   c6 05 00 00 00 00 04    movb   $0x4,0x0(%rip)        # 25 &lt;fun+0x25&gt;
    25:   b8 0c 00 00 00          mov    $0xc,%eax
    2a:   5d                      pop    %rbp
    2b:   c3                      retq   
  </code></pre>
  
  <p>I don't know how to calculate the terms located on the right which seems to be the <code>address of local variables</code> used. Moreover, I don't know to calculate it with <code>%rip register</code></p>
  
  <p>Could you give an example which shows the link between <code>%rip</code> and <code>%rsp</code> or <code>%rbp</code>, i.e especially in the computation of address when I use <code>move</code> instructions. </p>