Reading and Printing content from a txt file using

2019-08-01 00:32发布

问题:

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

回答1:

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