C 装配AT&;T x86从文件中读取
我正在尝试编写一段代码来显示txt文件的内容。新文件中只存储了数字,每行一个数字(%d\n)。当前代码如下所示:C 装配AT&;T x86从文件中读取,c,assembly,att,C,Assembly,Att,我正在尝试编写一段代码来显示txt文件的内容。新文件中只存储了数字,每行一个数字(%d\n)。当前代码如下所示: movl $0 , 320(%ebp) #a pre reserved location on the stack for the first number that needs to be cleared first leal 320(%ebp), %eax #a pre-chosen location for the memory push %eax push $d
movl $0 , 320(%ebp)
#a pre reserved location on the stack for the first number that needs to be cleared first
leal 320(%ebp), %eax #a pre-chosen location for the memory
push %eax
push $dataformat # . asciz "%d \n"
push %ebx #the result from the fopen is stored in ebx
call _fscanf
push 320(%ebp)
push %dataformat
call _printf
但是,除非我将movl$0更改为其他值,否则结果仍然为0。问题解决后,发现%ebx中的文件处于附加模式而不是写入模式,问题是..?如何使其不打印0,而是打印所需的值。为什么要调用
fscanf
两次,而不是第二次推送文件句柄?你的意思是调用printf
?Yhea我手动输入了它,因为它来自的计算机没有访问堆栈溢出的权限。当你在堆栈上按下ebx
时,你确定ebx
包含有效的文件句柄吗?而且文件的行与“%d\n”
完全匹配(可能文件中的行尾稍有不同)。您确实应该检查您调用的函数的返回值。