【问题标题】:MIPS won't read my .txt file to the bufferMIPS 不会将我的 .txt 文件读入缓冲区
【发布时间】:2022-01-14 03:07:08
【问题描述】:

我一直在努力让这段代码工作一段时间。有没有人可以向我解释为什么缓冲区在系统调用后保持为空。 .txt 文件、.asm 文件和 mars.jar 都在同一个目录中。我试过指定文件的完整路径,但也没有用。

.data
fin:    .asciiz "input.txt"
        .align 2
buffer: .space 2048

.text
# Open file
li      $v0, 13     # System call for opening files
la      $a0, fin    # load file name adress in $a0
li      $a1, 0      # Open for writing
li      $a2, 0      # mode is ignored
syscall             # open a file (file descriptor returned in $v0)
move    $s3, $v0    # save file descriptor to $s3

# Read from file to buffer
li      $v0, 14     # system call for read from file
move    $a0, $s3    # file descriptor
la      $a1, buffer # address of buffer to which to load the contents
li      $a2, 2048   # hardcoded max number of characters
syscall             # read file

# Close file
li      $v0, 16     # system call for close file
move    $a0, $s3    # file descriptor to close
syscall             # close file

【问题讨论】:

  • 无法在 Windows 上使用 Mars 4.5 进行复制。在我看来,您的当前工​​作目录不是 Mars 目录,即您是从其他地方启动 Mars。
  • 我已经从 .asm 和 .txt 文件所在的工作目录启动了 Mars,所以这应该不是问题。
  • 代码没有检查返回值,你是在调试器里做的吗?很可能是公开呼叫失败,而不是读取失败。您使用的是 MAC 还是 PC?
  • 是的,我一直在检查调试器。 open 调用返回 0xffffffff 的文件描述符,所以我认为这可行。我在 Windows 和 Ubuntu 上都运行过它,但都不起作用。

标签: mips system-calls mars-simulator


【解决方案1】:

我找到了解决方案。您必须指定从根目录到文件的完整路径才能使其正常工作。希望这对将来的其他人有所帮助。

【讨论】:

    猜你喜欢
    • 2018-10-02
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多