ここで初めて質問します。MIPS の宿題にとてもイライラしています。割り当ては次のように述べています。入力はプレーンテキストファイルになり、出力は単語と頻度のリストを含む別のファイルになります。出力ファイルには 2 つの列があり、左の列は単語、右の列は入力ファイルの頻度の数になります。たとえば、出力ファイルは次のようになります。
have: 2
they: 3
is: 4
i: 5
これを MIPS アセンブリを使用してコーディングすることを想定しています。この種の問題にどのようにアプローチすればよいかわかりません。最初に古いファイルのすべての文字をメモリ内の配列に読み取り、すべての一意の単語とその頻度を含む 2 番目の配列を構築する方法を見つけようと考えていました。
これまでのところ、元のファイルを配列に読み込むことしかできません。.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
誰かがこの課題について私に指示を与えることができれば、本当に感謝しています. 百万回ありがとう。