使用Mips Assembly从txt文件读取和打印内容 [英] Reading and Printing content from a txt file using Mips Assembly

查看:163
本文介绍了使用Mips Assembly从txt文件读取和打印内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取和打印.txt文件中的内容.
后来我也想从mips中读取转储的文件.
我看到了代码,看起来还可以,但是什么也没输出...

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

推荐答案

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

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.

我要做的就是提供带有double \\

All I had to do is provide a fullPath with double\\

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

这篇关于使用Mips Assembly从txt文件读取和打印内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆