循环访问文本MIPS

问题描述

我有以下代码,用于打开文本文件并读取它。如何开始访问每个单词?假设我想打印一个文本文件的前3个单词,每个单词都换行到一个新的文本文件,我该怎么做?

# opening file for reading
        
        li   $v0,13                    # system call for open file
        la   $a0,text_file  # input_text 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

        move $t0,$0                    # idx = 0

READ_LOOP:                              # do {
        li   $v0,14                    # system call for reading from file
        move $a0,$s0                   # file descriptor
                                        # input_text[idx] = c_input
        la   $a1,input_text($t0)             # address of buffer from which to read
        li   $a2,1                    # read 1 char
        syscall                         # c_input = fgetc(input_text_file);
        blez $v0,END_LOOP              # if(feof(input_text_file)) { break }
        lb   $t1,input_text($t0)          
        beq  $t1,$0,END_LOOP        # if(c_input == '\0')
        addi $t0,$t0,1                # idx += 1
        j    READ_LOOP
END_LOOP:
        sb   $0,input_text($t0)       # input_text[idx] = '\0'

        # Close the file 

        li   $v0,16                    # system call for close file
        move $a0,$s0                   # file descriptor to close
        syscall                         # fclose(input_text_file)

*here is where I would write the first 3 words to a predetermined text file*

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...