用多行读取文件

时间:2018-01-09 20:16:43

标签: assembly mips

我正在尝试编写MIPS代码来读取包含多行的文件:

Hello World
Hello World1
Hello World2

我设法读取了该文件,但无法越过第一行。

.data  
fin: .asciiz "file.txt"      # filename for input
buffer: .space 128

      .text

main:

# Open file for reading

li   $v0, 13       # system call for open file
la   $a0, fin      # input file name
li   $a1, 0        # flag for reading
li   $a2, 0        # mode is ignored
syscall            # open a file
move $s0, $v0      # save the file descriptor

# reading from file just opened

li   $v0, 14       # system call for reading from file
move $a0, $s0      # file descriptor
la   $a1, buffer   # address of buffer from which to read
li   $a2,  11  # hardcoded buffer length
syscall            # read from file

li  $v0, 4          #
la  $a0, buffer     # buffer contains the values
syscall             # print int

li      $v0, 10              #program done: terminating
syscall



# Close the file

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

结果输出是: Hello Word

我是否需要将文件加载到数组而不是缓冲区?

0 个答案:

没有答案