title: What does gdb 'x' command do?
body: <p>I am reading a <a href="https://rads.stackoverflow.com/amzn/click/com/1593271441" rel="noreferrer" rel="nofollow noreferrer">book</a> about hacking and it has a chapter about assembly.</p>
  
  <p>Following is my tiny program written in C.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(int argc, char const *argv[])
  {
      int i;
  
      for (i = 0; i &lt; 10; i++) {
          puts("Hello World!");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>And the following is <code>gdb</code> test:</p>
  
  <pre><code>(gdb) break main
  Breakpoint 1 at 0x40050f: file main.c, line 7.
  (gdb) run
  Breakpoint 1, main (argc=1, argv=0x7fffffffe708) at main.c:7
  7       for (i = 0; i &lt; 10; i++) {
  (gdb) disassemble main
  Dump of assembler code for function main:
     0x0000000000400500 &lt;+0&gt;: push   rbp
     0x0000000000400501 &lt;+1&gt;: mov    rbp,rsp
     0x0000000000400504 &lt;+4&gt;: sub    rsp,0x20
     0x0000000000400508 &lt;+8&gt;: mov    DWORD PTR [rbp-0x14],edi
     0x000000000040050b &lt;+11&gt;:    mov    QWORD PTR [rbp-0x20],rsi
  =&gt; 0x000000000040050f &lt;+15&gt;:    mov    DWORD PTR [rbp-0x4],0x0
     0x0000000000400516 &lt;+22&gt;:    jmp    0x400526 &lt;main+38&gt;
     0x0000000000400518 &lt;+24&gt;:    mov    edi,0x4005c4
     0x000000000040051d &lt;+29&gt;:    call   0x4003e0 &lt;puts@plt&gt;
     0x0000000000400522 &lt;+34&gt;:    add    DWORD PTR [rbp-0x4],0x1
     0x0000000000400526 &lt;+38&gt;:    cmp    DWORD PTR [rbp-0x4],0x9
     0x000000000040052a &lt;+42&gt;:    jle    0x400518 &lt;main+24&gt;
     0x000000000040052c &lt;+44&gt;:    mov    eax,0x0
  ---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
     0x0000000000400531 &lt;+49&gt;:    leave  
     0x0000000000400532 &lt;+50&gt;:    ret    
  End of assembler dump.
  </code></pre>
  
  <p>The following part is the things that I don't understand. <strong>Please note that $rip is the "instruction pointer" and points to</strong> <code>0x000000000040050f &lt;+15&gt;</code></p>
  
  <pre><code>(gdb) x/x $rip
  0x40050f &lt;main+15&gt;: 0x00fc45c7
  (gdb) x/12x $rip
  0x40050f &lt;main+15&gt;: 0x00fc45c7  0xeb000000  0x05c4bf0e  0xbee80040
  0x40051f &lt;main+31&gt;: 0x83fffffe  0x8301fc45  0x7e09fc7d  0x0000b8ec
  0x40052f &lt;main+47&gt;: 0xc3c90000  0x1f0f2e66  0x00000084  0x1f0f0000
  (gdb) x/8xb $rip
  0x40050f &lt;main+15&gt;: 0xc7    0x45    0xfc    0x00    0x00    0x00    0x00    0xeb
  (gdb) x/8xh $rip
  0x40050f &lt;main+15&gt;: 0x45c7  0x00fc  0x0000  0xeb00  0xbf0e  0x05c4  0x0040  0xbee8
  (gdb) x/8xw $rip
  0x40050f &lt;main+15&gt;: 0x00fc45c7  0xeb000000  0x05c4bf0e  0xbee80040
  0x40051f &lt;main+31&gt;: 0x83fffffe  0x8301fc45  0x7e09fc7d  0x0000b8ec
  </code></pre>
  
  <p>First command <code>x/x $rip</code> outputs <code>0x40050f &lt;main+15&gt;:   0x00fc45c7</code>. </p>
  
  <p>Is it the instruction at 0x40050f? 
  Is <code>0x00fc45c7</code> same as <code>mov    DWORD PTR [rbp-0x4],0x0</code> (assembled instruction at 0x40050f)?</p>
  
  <p>Secondly, if it is the instruction, what are those hex numbers from the output of commands <code>x/12x $rip</code>, <code>x/8xw $rip</code>, <code>x/8xh $rip</code>?</p>