-1

I am trying to make a program in LC3 that asks the user to enter a string and will proceed to print it out. My program is only ably to print out the first letter from the user inputted string. For example, I typed in "Hello" and it would only print out "H". Is there a way to fix this? thanks

.orig   x3000
Lea r1, storeString

Lea r0, EnterText
puts

LOOP
getc

str r0, r1, 0
add r1, r0, -10
brz OUTSIDE

out
brnzp LOOP

OUTSIDE

Lea r0, UserEnter
puts

Lea r0, storeString
puts

Halt
EnterText .stringz "\nPlease enter a text: "
UserEnter .stringz "\nThe text you have typed is: "
storeString .BLKW 99

.end

1 Answers1

0

Learn to use your debugger. You are overwriting r1 (which is your pointer) during the end of line check when in fact you should be incrementing it by 1 so it points to the place for the next character. You are lucky this doesn't just blow up.

Something like this should work better:

LOOP
getc

str r0, r1, 0
add r1, r1, 1    ; next character
add r0, r0, -10  ; just subtract in place
brz OUTSIDE

out
brnzp LOOP
Jester
  • 56,577
  • 4
  • 81
  • 125