そのため、入力文字列を受け取り、その文字列の可能なすべての UNIQUE 順列を出力する MIPS プログラムを書くのに忙しくしています。(別名、単語が LoOp の場合、LoOp と LOop は同じです)。
これを行うには、入力文字列の最後に改行文字を付ける必要がないことはわかっていますが、改行文字が追加されていないことを確認する方法はわかりません。これが私がこれまでに持っているものです:
.data
newLine:
.asciiz "\n"
promptUser:
.asciiz "Enter a 20 letter or less word:\n"
word:
.space 21
.text
main:
la $a0, promptUser
li $v0, 4 # Ask User for Input
syscall
la $a0, word
li $a1,21 # Max number of characters 20
li $v0,8
syscall # Prompting User
la $a0,newLine # Newline
li $v0, 4
syscall
la $a0, word # Printing Word
li $v0, 4
syscall
「\n」が含まれないのは、入力された文字数がちょうど 20 文字の場合のみです。何か提案はありますか??
修理:
これは機能します:
li $s0,0 # Set index to 0
remove:
lb $a3,word($s0) # Load character at index
addi $s0,$s0,1 # Increment index
bnez $a3,remove # Loop until the end of string is reached
beq $a1,$s0,skip # Do not remove \n when string = maxlength
subiu $s0,$s0,2 # If above not true, Backtrack index to '\n'
sb $0, word($s0) # Add the terminating character in its place
skip: