我正在尝试创建一个简单的汇编程序,它允许用户输入一个值并将其打印出来。到目前为止,我得到了以下信息:运行程序时出现错误:分段错误。有人可以帮我吗?
.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