如何在lc3中增加字符串中的字母?

时间:2015-05-01 03:33:17

标签: string assembly encryption character lc3

我正在写一个LC3程序,它会在程序之后增加存储在内存中的三个字母单词的每个字母。 '一个'变成了',' n'成为' q'' z'变成了'等等。

我将其用作 LC3 Assembly参考

到目前为止,这是我的代码

.orig x3000
ADD R1, R1, #3 
LEA R2, STRING  
HALT
STRING  .STRINGZ "anz"    
.END

enter image description here

我能够弄清楚如何从我的引用中声明LC3中的字符串。然而,有人如何做实际增量或有任何参考,我可以用来弄清楚如何做到这一点?

1 个答案:

答案 0 :(得分:3)

使用while循环,我能够让它递增字符串的每个字符,直到找到空值。我没有编码来循环回来(z成为c),但这应该让你开始。

;tells simulator where to put my code in memory(starting location). PC is set to thsi address at start up
.orig x3000

MAIN
    AND R1, R1, #0      ; clear our loop counter

    WHILE_LOOP
        LEA R2, STRING      ; load the memory location of the first char into R1
        ADD R2, R2, R1      ; Add our counter to str memory location. R2 = mem[R1 + R2]
        LDR R3, R2, #0      ; Loads the value stored in the memory location of R2
        BRz END_WHILE       ; If there is no char then exit loop

        ADD R3, R3, #3      ; change the char 
        STR R3, R2, #0      ; store the value in R3 back to the location in R2
        ADD R1, R1, #1      ; add one to our loop counter
        BR WHILE_LOOP       ; jump to the top of our loop
    END_WHILE

    HALT

; Stored Data
STRING      .STRINGZ "anz"    

.END