title: what does this instruction do?:- mov %gs:0x14,%eax
body: <p>My hello &amp; regards to all. I have a C program, basically wrote for testing Buffer overflow.</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
      void display()
      {
              char buff[8];
              gets(buff);
              puts(buff);
      }
      main()
      {
          display();
          return(0);
      }
  </code></pre>
  
  <p>Now i disassemble display and main sections of it using GDB. The code:-</p>
  
  <p>Dump of assembler code for function main:</p>
  
  <pre><code>    0x080484ae &lt;+0&gt;:    push   %ebp        # saving ebp to stack
      0x080484af &lt;+1&gt;:    mov    %esp,%ebp   # saving esp in ebp
      0x080484b1 &lt;+3&gt;:    call   0x8048474 &lt;display&gt;   # calling display function
      0x080484b6 &lt;+8&gt;:    mov    $0x0,%eax   # move 0 into eax , but WHY ????
      0x080484bb &lt;+13&gt;:   pop    %ebp        # remove ebp from stack
      0x080484bc &lt;+14&gt;:   ret                # return
  </code></pre>
  
  <p>End of assembler dump.</p>
  
  <p>Dump of assembler code for function display: </p>
  
  <pre><code>    0x08048474 &lt;+0&gt;:    push   %ebp          #saves ebp to stack        
      0x08048475 &lt;+1&gt;:    mov    %esp,%ebp     # saves esp to ebp
      0x08048477 &lt;+3&gt;:    sub    $0x10,%esp    # making 16 bytes space in stack
      0x0804847a &lt;+6&gt;:    mov    %gs:0x14,%eax  # what does it mean ????
      0x08048480 &lt;+12&gt;:   mov    %eax,-0x4(%ebp) # move eax contents to 4 bytes lower in stack
      0x08048483 &lt;+15&gt;:   xor    %eax,%eax       # xor eax with itself (but WHY??)
      0x08048485 &lt;+17&gt;:   lea    -0xc(%ebp),%eax  #Load effective address of 12 bytes 
                                                lower placed value ( WHY???? )
  
      0x08048488 &lt;+20&gt;:   mov    %eax,(%esp)      #make esp point to the address inside of eax
      0x0804848b &lt;+23&gt;:   call   0x8048374 &lt;gets@plt&gt;  # calling get, what is "@plt" ????
      0x08048490 &lt;+28&gt;:   lea    -0xc(%ebp),%eax       # LEA of 12 bytes lower to eax
      0x08048493 &lt;+31&gt;:   mov    %eax,(%esp)         # make esp point to eax contained address
      0x08048496 &lt;+34&gt;:   call   0x80483a4 &lt;puts@plt&gt;  # again what is "@plt" ????
      0x0804849b &lt;+39&gt;:   mov    -0x4(%ebp),%eax    # move (ebp - 4) location's contents to eax
      0x0804849e &lt;+42&gt;:   xor    %gs:0x14,%eax         # # again what is this ????
      0x080484a5 &lt;+49&gt;:   je     0x80484ac &lt;display+56&gt; # Not known to me
      0x080484a7 &lt;+51&gt;:   call   0x8048394 &lt;__stack_chk_fail@plt&gt;  # not known to me
      0x080484ac &lt;+56&gt;:   leave                        # a new instruction, not known to me
      0x080484ad &lt;+57&gt;:   ret                          # return to MAIN's next instruction
  </code></pre>
  
  <p>End of assembler dump.</p>
  
  <p>So folks, you should consider my homework. Rest all of the code is known to me, except few lines. I have included a big "WHY ????" and some more questions in the comments ahead of each line. The first hurdle for me is "mov %gs:0x14,%eax" instruction, I cant make flow chart after this instruction. Somebody plz explain me, what these few instructions are meant for and doing what in the program? Thanks...</p>