在 MIPS 中迭代和修改字符串

Iterating through and modifying a string in MIPS

我正在尝试编写一种方法,用 MIPS 汇编语言对文本字符串进行凯撒移位。我的加密方式如下:

encryptMessage:
    la $s0, message     #s0 will hold message that will be iterated through
    lw $t1, key     #s1 will hold the key to shift by
    li $t0, 0       #t0 will be iterator, starting at 0

encryptionLoop:
    add $s1, $s0, $t0   #$s1 = message[i]
    lb $s2, 0($s1)      #Loading char to shift into $s2
    beq $s2, $zero, exit    #Breaking the loop if we've reached the end: 
    add $s2, $s2, $t1   #Shifting the character by the key amount
    la $s1, ($s2)       #Changing the character in message to the shifted character
    addi $t0, $t0, 1    #i++
    j encryptionLoop    #Going back to the beginning of the loop

但是,在我打印出所谓的加密消息的退出方法中,它只是打印出最初输入的消息。我的代码不是 "remembering" 我更改了字符,我不知道如何记住它。我怀疑这条线

la $s1, ($s2)       #Changing the character in message to the shifted character

与此有关,但我不知道如何解决。

想通了。我怀疑那行应该是

sb $s2 ($s1)