【发布时间】:2017-07-21 10:58:22
【问题描述】:
我是 MIPS 的初学者,但我在使用连接程序时遇到了问题。我写的代码在这里
# _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
它只会打印出第一个字符串而不是第二个或连接的字符串;我的训练是因为 a0 在缓冲区 1 包含第一个字符串,而 a1 在缓冲区 3 包含第二个字符串,我需要在缓冲区 1 中返回一个连接的字符串。所以我将字符串从buffer1复制到buffer2中,并尝试将buffer2和buffer3放在buffer1中。如果不需要,我不一定非得使用 strCopy。
【问题讨论】: