Search code examples
lc3

How do i output a user input string


I'm very new to LC-3 assembly language, Currently doing an assignment, One of the questions I am asked is to output a user input string, for example:

Please enter a text: Hello world123

The text you have entered is: Hello world123

Here is the Code that I have been using:

.orig x3000

Lea r0, Name

Puts

Lea r0, inputstring

Puts

lea r2, outputstring

loop

getc

add r1,r0, -10

brz outside

out

str r0,r2, #0

add r2, r2, #1

brnzp loop

outside 

lea r0, output_text

puts

Halt

Name .stringz "Francois Van Zyl"

inputstring .stringz "\nPlease enter a text: "

output_text .stringz "\nThe text you have typed is: "

outputstring .blkw 99

.end

I expect that after the user inputted a string, the program would show the result. How can I fix this?


Solution

  • I finally found it! by experimenting a lot. here is the code I have done:

    .orig   x3000
    Lea r1, storeString
    
    Lea r0, Student
    puts
    
    Lea r0, Userinput
    puts
    
    LOOP
    getc
    
    out
    str r0, r1, 0
    add r1, r1, 1
    add r0, r0, -10
    
    brz OUTSIDE
    
    brnzp LOOP
    
    OUTSIDE
    
    Lea r0, Outputtext
    puts
    
    Lea r0, storeString
    puts
    
    Halt
    Student .stringz "Francois Van Zyl"
    Userinput .stringz "\n\nPlease enter a text: "
    Outputtext .stringz "The text you have typed is: "
    storeString .blkw 99
    
    .end