title: Scan an integer and print the interval (1, integer) in NASM
body: <p>I am trying to learn the assembly language from a Linux Ubuntu 16.04 x64.
  For now I have the following problem:
  - scan an integer n and print the numbers from 1 to n. </p>
  
  <p><em>For n = 5 I should have 1 2 3 4 5</em>.
  I tried to do it with scanf and printf but after I input the number, it exits.</p>
  
  <p>The code is:</p>
  
  <pre><code>;nasm -felf64 code.asm &amp;&amp; gcc code.o &amp;&amp; ./a.out
  
  SECTION .data
      message1: db "Enter the number: ",0
      message1Len: equ $-message1
      message2: db "The numbers are:", 0
      formatin: db "%d",0
      formatout: db "%d",10,0 ; newline, nul
      integer: times 4 db 0 ; 32-bits integer = 4 bytes
  
  SECTION .text
      global main
      extern scanf
      extern printf
  
  main:
  
      mov eax, 4
      mov ebx, 1
      mov ecx, message1
      mov edx, message1Len
      int 80h
  
      mov rdi, formatin
      mov rsi, integer
      mov al, 0
      call scanf
      int 80h
  
      mov rax, integer
      loop:
          push rax
          push formatout
          call printf
          add esp, 8
          dec rax
      jnz loop
  
      mov rax,0
  
  ret
  </code></pre>
  
  <p>I am aware that in this loop I would have the inverse output (5 4 3 2 1 0), but I did not know how to set the condition.</p>
  
  <p>The command I'm using is the following:</p>
  
  <pre><code>nasm -felf64 code.asm &amp;&amp; gcc code.o &amp;&amp; ./a.out
  </code></pre>
  
  <p>Can you please help me find where I'm going wrong?</p>