現在、文字列を取り、その文字列をスペースなしで出力するコードを記述しようとしています。私のコードのすべてが現在動作しますが、出力は文字列の以前の値を削除しません。たとえば、入力が「ジャックであり、ジルが丘を走った」場合、出力は「ジャンド・ジャラン・ヒル・ヒル・ヒル」です。私の文字列はまだ古い値を保持しているようです。なぜこれをやっているのか、それを修正する方法は誰にも分かりますか?MIPSの文字列から空白を削除する
.data
string1: .space 100
string2: .space 100
ask: .asciiz "Enter string: "
newstring: .asciiz "New string:\n"
.text
main:
la $a0,ask #ask for string1
li $v0,4
syscall
#load String1
la $a0,string1
li $a1, 100
li $v0,8 #get string
syscall
load:
la $s0,string1 #Load address of string1 into s0
lb $s1, ($s0) #set first char from string1 to $t1
la $s2 ' ' #set s2 to a space
li $s3, 0 #space count
compare:
#is it a space?
beq $s1, $zero, print #if s1 is done, move to end
beq $s1, $s2, space #if s1 is a space move on
bne $s1, $s2, save #if s1 is a character save that in the stack
save:
#save the new string
sub $s4, $s0, $s3,
sb $s1, ($s4)
j step
space:
addi $s3, $s3, 1 #add 1 if space
step:
addi $s0, $s0, 1 #increment first string array
lb $s1, ($s0) #load incremented value
j compare
print:
#tell strings
la $a0, newstring
li $v0,4
syscall
#print new string
la $a0, string1
li $v0, 4
syscall
end:
#end program
li $v0, 10
syscall #end