.
ORIG x3000
LEA R0, PROMPT ; First two lines load the prompt into register 0,
and I use PUTS to print it out. Once it reaches a null character in the string the
; next instruction is LD R1, STRING.
PUTSP
LD R1, STRING ; Here, register 1 is loaded with the starting
address of the string values for the input values.
ADD R3, R3, #2 ; Here I need a value to keep track of how many
times I need to do a left shift for R0.
ADD R4, R4, #2 ; Another global variable, same as R3, except I'm
using this to check what to add for the STRING at R1.
INPUT GETC ; The program has the prompt shown by now and the
user enters there string, where here it takes the value of the character entered,
and prints out that character
; to the console.
OUT
ADD R3, R3, #0 ; If the value of R3 is 2, then start left shift
function
BRp START_LEFT_SHIFT
BRz RESET ; After the shift R3 will have a value of 0, so it
goes to store.
START_LEFT_SHIFT ADD R3, R3, #0 ; Checking whether or not to continue doing
a shift after decrementing in LEFT_SHIFT.
BRp LEFT_SHIFT
RESET ADD R3, R3, #2 ; Resetting the value at R3 back to 2.
BR STORE
STORE LD R2, ENTER ; Loading the value of the enter character,
x000A into R2.
NOT R2, R2 ; NOT the enter value, then AND the result to R0 and
store back in R2.
AND R2, R0, R2
BRZ ESCAPE ; If that value is zero, branch to escape and print
what starts at x3100. However, unless the last number entered is "enter", or x000A,
the program will continue, since R0 holds the current value the user typed in.
STR R0, R1, #0 ; The contents of R0, which is the letter typed, is
stored into the address specified at R1, which is the starting address for STRING.
ADD R1, R1, #1 ; Add the next address to STRING, so the next value
will be stored there instead of overwriting the current value.
BR INPUT ; Branch back to the beginning of the loop.
LEFT_SHIFT ADD R0, R0, R0 ; Here, I'm attempting to bitwise left shift my R0
value by two so as to take the ASCII code stored there and
ADD R3, R3, #-1 ; move it into the first 8 bits of hex code.
BR START_LEFT_SHIFT
ESCAPE LD R0, STRING ; User has pressed enter, so the brz from the loop
branches here. Load R0 with the starting address of the held strings in memory from
x3100 to x31XX, depending on how much the user wrote.
PUTSP ; Prints the full string the user typed out to
console, so the output would be whatever the user originally typed, then pressing
enter, the program will print out the values it stored, and it appears as if it
"echoed" their input.
HALT ; Halts the processor.
PROMPT .FILL x6E45 ; packed string for the prompt: "Enter string to
echo "
.FILL x6574
.FILL x2072
.FILL x7473
.FILL x6972
.FILL x676E
.FILL x7420
.FILL x206F
.FILL x6365
.FILL x6F68
.FILL x0020
.FILL x0000
ENTER .FILL x000A
STRING .FILL x3100
.END