Simple input to output program in Assembly

南笙酒味 提交于 2020-01-05 05:00:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!