title: mmap() system call linux 32-bit x86 NASM(i386)
body: <p>I am trying to use mmap for my code but I dont have a clue to choose the values to store in the registers in pre interrupt processing. I picked up below part of code from somewhere. I am trying to print the return value (ig this will be stored in eax) after the interrupt but the value is negative(-14) which means the process is unsucessfull what should I change here?</p>
  <pre><code>mov     ebx,0                ;address
  
  mov     edx,0x1              ;protection
  
  mov     esi,0x2              ;flags
  
  mov     edi,[file_descriptor];file descriptor
  
  mov     ecx,4096             ;size
  
  mov     ebp,0                ;offset is 0
  
  mov     eax,192              ;mmap instruction code(90)
  
  int     0x80                 ;For mmap
  
  PutLInt eax                  ;printing the returned value after the system-call
  </code></pre>
  <p>I am getting strace output as:</p>
  <pre><code>        strace ./a
  execve(&quot;./a&quot;, [&quot;./a&quot;], 0x7ffcdf6517c0 /* 49 vars */) = 0
  strace: [ Process PID=20342 runs in 32 bit mode. ]
  read(0, 3
  &quot;3\n&quot;, 256)                     = 2
  creat(&quot;input.txt&quot;, 0700)                = 3
  read(0, 4
  &quot;4\n&quot;, 20)                      = 2
  write(3, &quot;4\n&quot;, 2)                      = 2
  read(0, 5
  &quot;5\n&quot;, 20)                      = 2
  write(3, &quot;5\n&quot;, 2)                      = 2
  read(0, 6
  &quot;6\n&quot;, 20)                      = 2
  write(3, &quot;6\n&quot;, 2)                      = 2
  write(1, &quot;\n&quot;, 1
  )                       = 1
  write(1, &quot;3&quot;, 13)                        = 1
  write(1, &quot;\n&quot;, 1
  )                       = 1
  write(1, &quot;3&quot;, 13)                        = 1
  write(1, &quot;\n&quot;, 1
  )                       = 1
  mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0) = -1 EACCES (Permission denied)
  write(1, &quot;-&quot;, 1-)                        = 1
  write(1, &quot;1&quot;, 11)                        = 1
  write(1, &quot;3&quot;, 13)                        = 1
  exit(0)                                 = ?
  +++ exited with 0 +++
  </code></pre>