1

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.

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

enter image description here

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?

committedandroider
  • 8,711
  • 14
  • 71
  • 126
  • There is plenty of information out there, for example at https://www.cs.auckland.ac.nz/courses/compsci210s2c/tutorials/ and you'll have to study some examples rather than ask someone to write the code. – Weather Vane May 01 '15 at 14:52
  • Can you take a look at this? http://stackoverflow.com/questions/30005154/what-does-stripping-off-the-ascii-template-mean I read the appropriate documentation this time – committedandroider May 02 '15 at 17:27

1 Answers1

3

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
Chris M
  • 651
  • 6
  • 10
  • Start with the LC3edit to save and assemble the code. After open up the LC3 simulator and load the assembled code. From there you can click the run code button to see what your program does. – Chris M May 01 '15 at 18:00
  • The code sample I gave you doesn't print to the console window, you would have to code that in. If you want to see the changes made to the string you would just go to the memory location of STRING after you run the program. – Chris M May 01 '15 at 18:01
  • You're on the right track but the SEXT is a process the LC3 does with information passed to it. The SEXT is called the sign extension because it takes short values like 001011100 and extends it to 0000000001011100. It has little to do with the LEA command storing the memory location of STRING into R2 – Chris M May 02 '15 at 21:41
  • I'll explain better in your other post – Chris M May 02 '15 at 21:44
  • The only way to view a string in anything other than ASCII values is to print it out to the console. Load the memory address of the string into R0 and then use PUTs to display it on the console window. – Chris M May 03 '15 at 02:39