第一次在这里提问。我对 MIPS 的家庭作业感到非常沮丧。作业状态:输入将是一个纯文本文件,输出将是另一个文件,其中包含单词列表及其频率。输出文件有两列,左列是一个单词,右列是输入文件中的频率数。例如,输出文件可能如下所示:
有:2
他们:3
是:4
我:5
我们假设使用 MIPS 程序集对此进行编码。我不明白我应该如何处理这种问题。我在想首先将旧文件中的所有字符读入内存中的数组,然后尝试找出一种方法来构造第二个数组,其中包含所有唯一单词及其频率。
到目前为止,我只能将原始文件读入数组。.data chars: .space 1024 fin: .ascii "chill.txt" # 要读取的文件名 uniqueWord: .space 1024
.text 主要内容:
Open a file
li $v0, 13 # syscall for open file
la $a0, fin # output file name
li $a1, 0 # open for read
li $a2, 0
syscall
move $s6, $v0 # save the file descriptor
read from the file that just opened
li $v0, 14 # syscall for read from file
move $a0, $s6 # file descriptoer
la $a1, chars
li $a2, 1024
syscall
I try to use these to find the beginning and the ending or a word.
add $t4, $zero, $zero # I = 0
add $t0, $zero, $zero # TOTAL = 0
add $t1, $zero, 44 # ENDPOINT = ','
add $t2, $zero, 32 # ENDPOINT = ' '
addi $t3, $zero, 46 # ENDPOINT = '.'
loop:
lb $t5, chars($t4) # for c in chars
beq $t5, $zero, endloop #
beq $t5, $t3,uniqueWord # if c == '.' go to uniqueWord
beq $t5, $t1,uniqueWord # if c == ',' go to endloop
beq $t5, $t2, uniqueWord # if c == ' ' go to endloop
addi $t4, $t4, 1 # i += 1 increment index
addi $t0, $t0, 1 # total += 1
j loop
如果有人能指导我完成这项任务,我将不胜感激。感谢一百万次。