LC-3 Print string from user input

lc3
user3556715 picture user3556715 · Apr 21, 2014 · Viewed 12.5k times · Source

Im working on an assignment and im currently stuck. This is part of the question:

Accepts exactly 7 characters and echoes them to the console. Moves on to the next line after 7 characters without waiting for return/enter.

So ive made a loop which loops 7 times, gets input and displays on the screen and also stores the characters (i think). But i am unable to print the saved string on the next line.

This is my current code:

        LEA R2, memorySpace ; allocates memory to R2 for string storage
        LD  R1, upiLoop ; condition for loop (loops 7 times)
loop    
        GETC
        PUTC

STR     R0, R2, #0       ; r0 -> ( memory address stored in r2 + 0 )
ADD     R2, R2, #1       ; increments the memory pointer    


ADD     R1, R1, #-1 ; decrements loop
BRz     loop

upiLoop         .FILL 7
memorySpace .blkw 100   ; empty space to store string

All i can do is just see the characters which i type in.. I want to print the characters on the next line as 1 string.

Answer

aqua picture aqua · Jul 7, 2014

So far you've taken in characters and made a string. Now you just need to print the string. You do this by supplying R0 with the starting address of the string and calling the PUTS trap. Note that the last character of the string will need to be NULL. So, after the loop:

LEA R0, memorySpace
PUTS