【问题标题】:Reading from a binary file in MIPS从 MIPS 中读取二进制文件
【发布时间】:2017-01-02 16:40:26
【问题描述】:

我有一张 PGM 照片,我正试图在 MIPS 中打开和阅读它。 当 PGM 文件中的值是 ASCII 时,一切都按预期工作。当它们是 HEX 格式时,系统调用 14(读取)只读取几个值然后停止,我最终只得到 缓冲区中文件的一部分。

左边的十六进制 - 不工作,右边的 ASCII - 工作。同一个文件。

这就是我的代码(缓冲区在数据部分中声明并且有足够的空间来分配文件)

#open a file
    li $v0, 13 #Syscall for loading files
    la $a0, image_file #Saving the address to $a0
    li   $a1, 0       # flag for reading
    li   $a2, 0       # mode is ignored
    syscall
    move $s6, $v0 #Placing the descriptor in $s6 for later-use  

#read from file
    li $v0, 14 #Syscall to read from files
    move $a0, $s6 #Moving descriptor to $a0
    la   $a1, buffer   # address of buffer to which to read
    li   $a2, 65555     # hardcoded buffer length
    syscall

【问题讨论】:

  • 你有什么发现吗?如果你这样做了,你也可以回答你自己的问题。

标签: binary hex ascii mips pgm


【解决方案1】:

答案是它实际上是在读取整个文件,由于 EOF 符号,控制台不会显示所有内容。保存文件后,您需要再次指定文件的确切长度,以便在 EOF 符号之前保存所有内容,而不仅仅是数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-24
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 2011-03-14
    相关资源
    最近更新 更多