语法不清楚参考https://blog.csdn.net/qq_40570410/article/details/106903645这篇博文。
执行时建立一个file.txt文件,路径和汇编代码的位置放在一起,可以直接放在桌面上使用
# Sample MIPS program that read a file.
.data
fout: .asciiz "file.txt" #filename for read
buffer: .space 10 #sapce is 10
.text
.globl main
main:
# Open (for reading) a file
li $v0, 13 # system call for open file
la $a0, fout # read file name
li $a1, 0 # flags
syscall # open a file (file descriptor returned in $v0)
move $t0, $v0 # save file descriptor in $t0
# Read to file just opened
li $v0, 14 # system call for read to file
la $a1, buffer # address of buffer from which to write
li $a2, 10 # number of characters to write
move $a0, $t0 # put the file descriptor in $a0
syscall # write to file
# Get the value from certain address
la $a0, buffer #load the address into $a0
li $v0, 4 # print the string out
syscall
# Close the file
li $v0, 16 # system call for close file
move $a0, $t0 # Restore containing
syscall # close file
li $v0, 10 # end the file
syscall