Reputation: 2942
I'm trying to read and print the content inside a .txt file.
Later i'd like to read the dumped file from mips aswell.
I see the code and it seems ok but nothing is outputed...
.data
myFile: .asciiz "teste.txt" # filename for input
buffer: .space 1024
.text
# Open file for reading
li $v0, 13 # system call for open file
la $a0, myFile # 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
# Printing File Content
li $v0, 4 # system Call for PRINT STRING
la $a0, buffer # buffer contains the values
syscall # print int
li $v0, 10 # Finish the Program
syscall
Upvotes: 4
Views: 7533
Reputation: 1
For somebody tried the above answer and still code does not run, maybe pay attension to how you named the file. I left click and create a txt file and named it temp.txt and it show in explorer as normal like this https://i.sstatic.net/lQET8YR9.png. Now guess the file real name, it's temp.txt.txt, wasted 1h of my life for this🙄
Upvotes: 0
Reputation: 2942
The problem was about the path
of my file.
I thought the path would start from the source code, but it starts from the .jar
file.
All I had to do is provide a fullPath with double\\
.data
myFile: .asciiz "c:\\Users\\johnDoe\\Documents\\Assembly\\test.txt" # filename for input
Upvotes: 4