title: call fgets from assembly code
body: <p>I would like to know how to call fgets from assembly code.
  I read these questions which are exactly the same as the this one: <a href="https://stackoverflow.com/questions/3689919/how-to-call-fgets-in-x86-assembly">How to call fgets in x86 assembly?</a>
  and this one: <a href="https://stackoverflow.com/questions/2567055/how-to-use-c-library-function-fgets-in-assembly-language">How to use c library function fgets in assembly language?</a>
  But both of them aren't satisfying for two reasons:
  1. I really want to use fgets since i want my code to run on both windows and linux ( I'm using NASM )
  2.I looked at the disassembled version of fgets, unfortunately it doesn't provide the necessary details to reproduce it naming how is <code>stdin</code> represented in assembly.
  Here are my C and assembly codes i got by using <code>gcc -S fgets.c</code> .</p>
  
  <p>fgets.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      char name[15];
      fgets(name, 16, stdin);
      return 0;
  }
  </code></pre>
  
  <p>fgets.s</p>
  
  <pre><code>    .file   "fgets.c"
      .def    ___main;    .scl    2;  .type   32; .endef
      .text
  .globl _main
      .def    _main;  .scl    2;  .type   32; .endef
  _main:
      pushl   %ebp
      movl    %esp, %ebp
      andl    $-16, %esp
      subl    $32, %esp
      call    ___main
      movl    __imp___iob, %eax
      movl    %eax, 8(%esp)
      movl    $16, 4(%esp)
      leal    17(%esp), %eax
      movl    %eax, (%esp)
      call    _fgets
      movl    $0, %eax
      leave
      ret
      .def    _fgets; .scl    2;  .type   32; .endef
  </code></pre>
  
  <p>First, i'm not good at reading AT&amp;T syntax and thus understanding the above assembly source easily.
  So can anyone help me figure out: (i) where is my local variable <code>name</code> located? in ESP+17 ? (ii) If <code>__imp___iob</code> is representing <code>stdin</code>, where is coming from so that i can use it?</p>
  
  <p>Thanks</p>