在 MIPS 中迭代和修改字符串

Nic*_*ert 11 string assembly loops 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: http://stackoverflow.com/questions/12739463/how-to-iterate-a-string-in-mips-assembly
    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
Run Code Online (Sandbox Code Playgroud)

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

la $s1, ($s2)       #Changing the character in message to the shifted character
Run Code Online (Sandbox Code Playgroud)

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

Nic*_*ert 8

弄清楚了。我怀疑的那条线应该是

sb $s2 ($s1)
Run Code Online (Sandbox Code Playgroud)