I'm a begginer at MIPS and I'm having trouble with a concatenation program I have. The code I wrote is here
# _strConcat
#
# Concatenate the second string to the end of the first string
#
# Arguments:
# - $a0: The address of the first string
# - $a1: The address of the second string
# Return Value:
# - None
_strConcat:
move $t0, $a0 #string in buffer 1
move $t1, $a1 #string in buffer3
j _strCopy #copies buffer1 into buffer2 at address $a1
move $t2, $a1 #saves buffer1 string to buffer2
#add string inbuffer3 to end of string in buffer 1
# $t0 contains destination, $t1 and $t2 contain strings to concatenate
first:
lb $t4, ($t2)
beqz $t0, endFirst
sb $t4, ($t0)
addi $t2, $t2, 1
addi $t0, $t0, 1
j first
endFirst:
beqz $t0, endSecond
addi $t1, $t1, 1
addi $t0, $t0, 1
j endFirst
endSecond:
jr $ra
It will only print out the first string instead of the second or the concatenated string; My train of though was since a0 contains the first string at buffer1 and a1 contains the second string at buffer 3 and I need to return a concatenated string back in buffer1. So I copied the string into buffer2 from buffer1 and tried putting the buffer2 and buffer3 together in buffer1. I don't necessarily have to use strCopy if it's not needed.