String 如何使用MIPS分隔字符串中的单词?
我正在尝试将字符串中的单词分开,然后逐个打印每个单词。所以如果我的输入是String 如何使用MIPS分隔字符串中的单词?,string,char,mips,increment,String,Char,Mips,Increment,我正在尝试将字符串中的单词分开,然后逐个打印每个单词。所以如果我的输入是 你好,是我 应该是: Hello world its me 程序应打印每个字符,直到遇到空白或换行符。然后添加\n并转到下一个字符。假设我已经有一个名为input\u text的字符串,并且main\u end正确地处理字符串的终止,这是我目前为止的代码: la $a1, input_text #a1 points to the string li $t0, 0 #index nextChar: lb $t2
你好,是我
应该是:
Hello
world
its
me
程序应打印每个字符,直到遇到空白或换行符。然后添加\n并转到下一个字符。假设我已经有一个名为input\u text
的字符串,并且main\u end
正确地处理字符串的终止,这是我目前为止的代码:
la $a1, input_text #a1 points to the string
li $t0, 0 #index
nextChar:
lb $t2, 0(a1) #get the first byte pointed by the address
beqz $t2, main_end #means the string has terminated
#if the character is a white space:
li $t1, 32 #ASCII for blank space
beq $t2, $t1, notChar
#if the character is a new line:
li $t1, 10 #ASCII new line
beq $t2, $t1, notChar
#if it is a regular character, print the char at t2
li $v0, 11
add $t2, $zero, $t0
syscall
addi $a1, $a1, 1 #increment the address (move pointer one character)
j nextChar
notChar:
#print a new line
li $v0, 4
la $a0, newline
syscall
addi $a1, $a1, 1 #increment the address and jump to nextChar
j nextChar
我怎样才能解决这个问题
谢谢:)我们应该猜猜这有什么问题吗?你为什么不直接告诉我们呢。