问题
So, I'm new to learning Assembly and am very confused on how the memory works in Assembly etc.
I got the following code:
.global main
.text
format_input: .asciz "%ld"
main:
subq $8, %rsp
leaq -8(%rbp), %rsi
movq $format_input, %rdi
movq $0, %rax
call scanf
movq %rsp, %rdi
call printf
end:
movq $0, %rax
call exit
What I wanted to do here is to input a number and output the same number. But here, I'm already having a problem. If I input a number, I get a Segmentation fault
. If I input one character, like the letter a
, it runs without any errors? It only doesn't output anything.
What am I doing wrong here?
来源:https://stackoverflow.com/questions/39679848/simple-input-to-output-program-in-assembly