Reading Files Using the MIPS Assembly

I am trying to write a program that reads characters from a .dat file, corresponding to the different colors that will be displayed in the LED simulator; x = off, R = red, etc. My problem is that I cannot understand what I am doing wrong by opening the .dat file. I looked around and tried everything I could think of, but every time I build and run, I get -1 in $ v0, which means an error. Here is my code for opening / reading / closing a file:

.data  
fin: .asciiz "maze1.dat"      # filename for input
buffer: .asciiz ""

.text
#open a file for writing
li   $v0, 13       # system call for open file
la   $a0, fin      # board file name
li   $a1, 0        # Open for reading
li   $a2, 0
syscall            # open a file (file descriptor returned in $v0)
move $s6, $v0      # save the file descriptor 

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

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

The maze1.dat file is in the same directory as the MIPS program. Any help or suggestions are welcome.

+3
source share
3 answers

, , ( ). buffer: .space 1024 . .

, , . .dat .

+3

, MARS , . MARS.jar , "maze1.dat", .

0

. , Linux, "./maze1.dat".

0

Source: https://habr.com/ru/post/1774154/


All Articles