Assembly 在哪里放置MARS的.txt文件
我正在使用MARS程序来编写一些MIPS汇编代码,我正在编写的程序需要接收一个输入文件,然后通过迭代来更改一些数字。我已经编写了所有代码体,但我不确定如何实际接收文件。我有以下代码读取输入并存储地址:Assembly 在哪里放置MARS的.txt文件,assembly,input,io,mips,mips32,Assembly,Input,Io,Mips,Mips32,我正在使用MARS程序来编写一些MIPS汇编代码,我正在编写的程序需要接收一个输入文件,然后通过迭代来更改一些数字。我已经编写了所有代码体,但我不确定如何实际接收文件。我有以下代码读取输入并存储地址: .data 0x0 magicNum: .asciiz "P2" #magic number zero: .word 0 newLine: .asciiz "\n" #new line character .text 0x3000 main:
.data 0x0
magicNum: .asciiz "P2" #magic number
zero: .word 0
newLine: .asciiz "\n" #new line character
.text 0x3000
main:
ori $v0, $0, 8 #8 is syscall to read string
ori $a0, $0, 100 #stores address of input buffer
ori $a1, $0, 3 #max character to read in
syscall
#the rest of the code is down here
但是,我应该将文件放在Windows上的什么位置才能接收它呢?您必须使用syscall 13打开文件,然后使用syscall 14读取文件并将其内容存储到缓冲区中 下面是一个片段,让您开始,只需用您的代码填补空白:
.data
filename: .asciiz "file.txt"
buffer: .space 1024
.text
la $a0, filename
li $a1, 0 # readonly
li $a2, 0
li $v0, 13
syscall # open file
bltz $v0, file_error
move $a0, $v0
la $a1, buffer
li $a2, 1024
read_file:
li $v0, 14
syscall
beqz $v0, read_done
bltz $v0, read_error
addu $a1, $a1, $v0 # adjust buffer pointer
subu $a2, $a2, $v0
bnez $a2, read_file # If buffer not full and not EOF, continue reading
read_done:
# File copied to buffer
# Your code goes here
file_error:
# Code to take action if file errors occur (e.g. file not found)
read_error:
# Code to take action if read errors occur
如果您使用的是MARS,那么该文件应该位于当前目录(您启动MARS的地方)。因为现在是这样,我只需使用多个系统调用一次接收一行输入