使用 MIPS 将字符串中的单词替换为另一个单词

发布于 2025-01-20 15:26:22 字数 786 浏览 0 评论 0原文

我正在尝试制作一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文