使用Mips程序集从txt文件中读取和打印内容

时间:2017-10-08 05:54:47

标签: assembly printing mips

我正在尝试阅读并打印.txt文件中的内容 后来我想从mips读取转储文件。
我看到了代码,看起来没问题,但没有任何结果......

.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 个答案:

答案 0 :(得分:3)

问题出在我文件的path上 我认为路径将从源代码开始,但它从.jar文件开始。

我所要做的就是提供一个带有双\\

的fullPath
.data
myFile: .asciiz "c:\\Users\\johnDoe\\Documents\\Assembly\\test.txt" # filename for input