如何增加lc3中字符串中的字母? [英] How to increment a letter in string in lc3?

查看:880
本文介绍了如何增加lc3中字符串中的字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个LC3程序,它将程序后存储在存储器中的一个三字母单词的每个字母递增。 'a'成为'd','n'成为'q','z'成为'c'等。

I am writing an LC3 program that increments each letter of a three-letter word stored in memory following the program. 'a' becomes 'd', 'n' becomes 'q', 'z' becomes 'c', etc.

https://classes.soe.ucsc.edu/cmpe012/Winter09/lectures/06_LC3_Assembly.pdf =nofollow noreferrer> LC3 Assembly a reference

I am using this as LC3 Assembly a reference

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

Here is my code so far

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

>

我能够找出如何声明一个字符串的LC3从我的参考。但是有没有人如何做实际增量或有任何参考,我可以用来弄清楚如何做呢?

I was able to figure out how to declare a string of characters in LC3 from my reference. However does anyone how to do the actual incrementation or have any references that I could use to figure out how to do it?

推荐答案

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

Using a while loop, I was able to get it to increment each char of the string until a null value is found. I didn't code it to loop back around (z becoming c) but this should get you started.

;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

这篇关于如何增加lc3中字符串中的字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆