我正在尝试在程序集中制作一个小程序(对于AT & T)。我试图以整型的形式从用户那里得到一个输入,然后递增,然后输出递增的值。但是,该值不会增加。我花了最后几个小时尝试所有我能想到的东西,但它仍然不起作用,所以我有这样的想法,即我可能理解集会中的一个概念不好,导致我没有发现错误。这是我的代码:我的(AT&T)程序集(x86-x64)代码应该增加,但不会
1 hiString: .asciz "Hi\n"
2 formatstr: .asciz "%ld"
3
4 .global main
5
6 main:
7 movq $0, %rax #no vector registers printf
8 movq $hiString, %rdi #load hiString
9 call printf #printf
10 call inout #inout
11 movq $0, %rdi #loading exit value into register rdi
12 call exit #exit
13
14 inout:
15 pushq %rbp #Pushing bp
16 movq %rsp, %rbp #Moving sp to bp
17 subq $8, %rsp #Space on stack for variable
18 leaq -8(%rbp), %rsi
19 movq $formatstr, %rdi #1st argument scanf
20 movq $0, %rax #no vector for scanf registers
21 call scanf #scanf
22 incq %rsi
23 call printf
从教程中,我得到了我的朋友,我了解到,线路17至19是必要的,但是,我想我不使用堆栈空间我ADRESS那里,所以我怀疑这个错误有什么。我不确定的课程。先谢谢你。
编辑,更新的代码(printf的仍然是所谓的现在子程序)
1 hiString: .asciz "hi\n"
2 formatstr: .asciz "%ld"
3
4 .global main
5
6 main:
7 movq $0, %rax
8 movq $hiString, %di
9 call printf
10 call inout
11 movq $0, %rdi
12 call exit
13
14 inout:
15 pushq %rbp
16 movq %rsp, %rbp
17 subq $8, %rsp
18 leaq -8(%rbp), %rsi
19 movq $formatstr, %rdi
20 movq $0, %rax
21 call scanf
22 popq %rax
23 incq %rax
24 movq %rax, %rsi
25 movq $0, %rax
26 call printf
27 addq $8, %rs
它运行和增量但是,现在,当增加值outputed,那里显示的数值后一些奇怪的迹象。
编辑:无所谓,上面只发生过一次,现在没有增加值输出,只有奇怪的迹象。
您的上次编辑再次从'inout'的末尾删除'ret'。 –