使用 MIPS 将字符串中的单词替换为另一个单词
我正在尝试制作一个MIPS函数,该功能采用3个字符串参数,TXT1,TXT2和TXT3,并用TXT2替换TXT1中TXT1的任何出现。目前,我只能用txt1和txt2是单个字符来做到这一点,我该怎么做?
我想制作的示例: INP:txt1,txt2,txt3 = xx,yy,xxxx; 出去:xxyy
这是我所做的:
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 MIPS function that takes 3 string parameters, txt1, txt2, and txt3, and replaces any occurrence of the txt1 in txt3 with txt2. For the moment I am only able to do it with txt1 and txt2 being single characters, how could I do it with words?
Example of what I am trying to make:
Inp: txt1, txt2, txt3 = xx, yy, XXxx;
Out: XXyy
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
Would really appreciate any sort of help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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