title: Behavior of read syscall in Assembly (ASM)
body: <p>I am currently learning the ASM, I have a question about the following code (which compiles)</p>
  
  <p>This code come from this <a href="https://www.tutorialspoint.com/assembly_programming/assembly_system_calls.htm" rel="nofollow noreferrer">tutorial</a>.</p>
  
  <p>The question is: Why do I have the same behaviour when the fd is egual to 0, 1 or 2 (corresponding to stdin, stdout and stderr), at the indicated line, and when the fd is egual to 3 or more, it does nothing (it skips the scanf).</p>
  
  <pre><code>section .data                           ;Data segment
     userMsg db 'Please enter a number: ' ;Ask the user to enter a number
     lenUserMsg equ $-userMsg             ;The length of the message
     dispMsg db 'You have entered: '
     lenDispMsg equ $-dispMsg                 
  
  section .bss           ;Uninitialized data
     num resb 5
  
  section .text          ;Code Segment
     global _start
  
  _start:                ;User prompt
     mov eax, 4
     mov ebx, 1
     mov ecx, userMsg
     mov edx, lenUserMsg
     int 80h
  
     ;Read and store the user input
     mov eax, 3
     mov ebx, 2 ; /!\ QUESTION IS ABOUT THIS LINE /!\
     mov ecx, num  
     mov edx, 5          ;5 bytes (numeric, 1 for sign) of that information
     int 80h
  
     ;Output the message 'The entered number is: '
     mov eax, 4
     mov ebx, 1
     mov ecx, dispMsg
     mov edx, lenDispMsg
     int 80h  
  
     ;Output the number entered
     mov eax, 4
     mov ebx, 1
     mov ecx, num
     mov edx, 5
     int 80h  
  
     ; Exit code
     mov eax, 1
     mov ebx, 0
     int 80h
  </code></pre>
  
  <p>We can compile and execute this code with the following command:</p>
  
  <pre><code>$&gt; nasm -f elf64 test.S
  $&gt; ld test.o
  $&gt; ./a.out
  </code></pre>
  
  <p>Thank you,</p>