Q:

Assembly scanf retrieving value

I'm trying to create a simple assembly program, which allows the user to input a value and print it away. So far I've got the following:
When running the program I get the error: segmentation error.
Can anybody help me please?
    .text
    STRING: .asciz "test\n"

    input: .long

    .global main
    inout:
    pushl %ebp # Prolog: push the base pointer.
    movl %esp, %ebp # and copy stack pointer to EBP.

    formatstr: .asciz "%d"

    subl $4, %esp # Reserve stack space for variable
    leal -4(%ebp), %eax # Load address of stack var in eax
    pushl $input # Push second argument of scanf
    pushl $formatstr # Push first argument of scanf
    call scanf # Call scanf

    movl $8, %esp # Clear local variables from stack.

    pushl $input
    call printf

    movl $0, %eax
    movl %ebp, %esp
    popl %ebp # Restore caller's base pointer.
    ret # Return

    main:
    pushl $STRING #push the format string printing
    call printf # print the number
    call inout

    add $4, %esp
    pushl $0
    call exit

A:

If it didn't explode when you execute data at
 formatstr: .asciz "%d"

it most probably will give a segmentation fault trying to use the stack with a wonky stack pointer:
movl $8, %esp # Clear local variables from stack.

pushl $input

Perhaps you meant to
addl $8, %esp

