【问题标题】:Assembly AT&T x86 read from file [closed]从文件中读取的组装 AT&T x86 [关闭]
【发布时间】:2013-06-10 10:04:21
【问题描述】:

我正在尝试编写一段代码来显示 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 $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。

【问题讨论】:

  • 问题是..?
  • 如何让它不打印 0 而是打印所需的值。
  • 为什么你两次调用fscanf,第二次没有推送文件句柄?你的意思是打电话给printf
  • 是的,我手动输入了它,因为它来自的计算机无法访问堆栈溢出
  • 当您将ebx 压入堆栈时,您确定ebx 包含有效的文件句柄吗?并且文件的行 exactly 匹配 "%d \n"(可能文件中的行结尾略有不同)。你真的应该检查你调用的函数的返回值。

标签: c assembly att


【解决方案1】:

问题解决后发现 %ebx 中的文件处于追加模式而不是写入模式

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多