MIPS 字符串切片 |检测字符串中的给定单词
我正在尝试制作一个函数,以检测字符串的一部分是否等于给定单词。
我想过要用嵌套的循环穿过字符串,并检测发现的子字符串是否等于给定的单词。但是,我不知道要用嵌套循环切片。我只能提出一个程序,该程序能够通过循环浏览字符串是否等于给定字符的字符。
这是我所做的:
la $a0,string #load address of string
lb $a1,orig #load original character
lb $a2,new #load new character
li $a3,0 #load replace with zero first
li $t0,0 #load index
loop:
lb $t0,0($a0) #load character
beqz $t0,exit #exit when loop finish
bne $t0,$a1,skip #compare with original character
sb $a2,0($a0) #replace character
add $a3,$a3,1 #increase replace count by one
skip:
add $a0,$a0,1 #increase count by one
j loop
exit:
end:
li $v0,4
la $a0,rprompt
syscall
我真的很感谢任何帮助!
I am trying to make a function that detects if a part of a string is equal to a given word.
I thought of going through the string with a nested loop and detecting if the substring found would be equal to the word given. However, I don't know of to slice a string with a nested loop. I am only able to come up with a program that is able to detect if a character of a string is equal to a given character by looping through it.
Here is what I made:
la $a0,string #load address of string
lb $a1,orig #load original character
lb $a2,new #load new character
li $a3,0 #load replace with zero first
li $t0,0 #load index
loop:
lb $t0,0($a0) #load character
beqz $t0,exit #exit when loop finish
bne $t0,$a1,skip #compare with original character
sb $a2,0($a0) #replace character
add $a3,$a3,1 #increase replace count by one
skip:
add $a0,$a0,1 #increase count by one
j loop
exit:
end:
li $v0,4
la $a0,rprompt
syscall
I would really appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论