You have to use syscall 13 to open a file, and then use syscall 14 to read from it and store its contents into a buffer.
Here's a snippet to get you started, just fill in the gaps with your code:
.data
filename: .asciiz "file.txt"
buffer: .space 1024
.text
la $a0, filename
li $a1, 0 # readonly
li $a2, 0
li $v0, 13
syscall # open file
bltz $v0, file_error
move $a0, $v0
la $a1, buffer
li $a2, 1024
read_file:
li $v0, 14
syscall
beqz $v0, read_done
bltz $v0, read_error
addu $a1, $a1, $v0 # adjust buffer pointer
subu $a2, $a2, $v0
bnez $a2, read_file # If buffer not full and not EOF, continue reading
read_done:
# File copied to buffer
# Your code goes here
file_error:
# Code to take action if file errors occur (e.g. file not found)
read_error:
# Code to take action if read errors occur
If you are using MARS the file should be located in the current directory (the place where you started MARS).