title: Scanf on nasm assembly program
body: <p>I am trying to write a simple program using <code>scanf</code> and <code>printf</code>, but it is not storing my values properly.</p>
  
  <pre><code>        extern printf
          extern scanf
  
          SECTION .data
    str1: db "Enter a number: ",0,10
    str2: db "your value is %d, squared = %d",0,10
    fmt1: db "%d",0
    location: dw 0h
  
  
          SECTION .bss
    input1: resw 1 
  
          SECTION .text
          global main
  
     main:
          push ebp
          mov ebp, esp
  
          push str1
          call printf 
          add esp, 4
  
          push location
          push fmt1 
          call scanf
          mov ebx, eax            ;ebx holds input
  
          mul eax                 ;eax holds input*input
  
          push eax
          push ebx
          push dword str2
          call printf
          add esp, 12
  
          mov esp, ebp
          pop ebp
          mov eax,0
          ret
  </code></pre>
  
  <p>For some reason when I run the program, no matter what number I enter, the program prints 1 for both inputs.</p>
  
  <p>I am using nasm, linked with gcc</p>