title: Reading a number into a register from stdin? Loading a scanf result
body: <p>I am currently busy with assembly and ran into the following problem:</p>
  <p>I'm trying to get a number that has been typed into the eax register. First i present a string which asks for input and then someone has to enter a number.</p>
  <p>I've used the following code, but I don't understand every bit of it. Please note the comments in the code.</p>
  <p>I know absolutely nothing happens now with the number, except that is has been moved into eax. What i do want to know is why i must use leal: why and what does it do? and why do i need to push eax back on the stack?</p>
  <pre><code>.text
  string1: .asciz &quot;Please enter a number\n&quot;
  input: .asciz &quot;%d&quot; 
  
  .global main
  main:
         # Editor's note: this code is broken / unsafe; missing push %ebp here
    movl %esp, %ebp
    
    push $string1          # prompt string
    call printf            #print the string
             # no add $4, %esp here: 4 bytes still allocated on the stack
  
    leal -4(%ebp), %eax   # ????
    pushl %eax            # the thing you pushed in eax is now pushed on the stack?
    pushl $input          #the number 
    
    call scanf      
    
    popl %eax
    popl %eax       # the number that has been entered is now in eax
    
    call end
    
  end:
    push $0
    call exit
  </code></pre>