'Replacing a word in a string by another word with MIPS

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!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source