我正在用MIPS进行编码,并尝试用用户提供的另一个字符替换字符串中的每个匹配字符。我的问题是实际更换。我正在尝试使用sb将替换字符移动到正确的位置,但是它似乎没有用。
while:
lb $t2, 0($t5) #Loads the next byte of the string into
temporary storage
beqz $t2, exit #If the next byte is empty, we're done
beq $t2, $t1, replacer #If the next character matches, replace the
character
replacerContinue:
addi $t0, $t0, 1 #Increments the address for the modded array
addi $t5, $t5, 1 #Increments original string
j while
.
.
.
.
replacer:
sb $t4, 0($t0) <---- #Stores the replacement character at the bit
in the current offset for the modified string
j replacerContinue
syscall
这是寄存器的键,我知道这有点混乱:
$ t0 =应该包含新字符串的原始字符串的修改后的版本 字符替换旧字符
$ t1 =用户要在字符串中替换的字符
$ t2 = $ t5字符串中的字节
$ t4 =用户选择用替换旧字符的字符
$ t5 =原始字符串。它是由用户较早输入的,我有 存储在.data组件中
我期望当我使用sb $ t4,0($ t0)时,它将替换字符存储到旧字符的对应位置(注意,我在循环末尾增加了地址,所以我不需要添加偏移量。
相反,我无法确定是否正在发生任何事情。我正在使用MARS,当我查看寄存器值以查看替换是否发生在$ t0时,它仅显示地址的值。
感谢您的帮助。让我知道是否可以提供更多信息,或者您在代码编写中发现任何不良做法。我对MIPS还是很陌生。