我如何输出用户输入字符串

时间:2019-04-23 12:18:14

标签: lc3

我对LC-3汇编语言很陌生,目前正在做作业,我要问的问题之一是输出用户输入的字符串,例如:

Please enter a text: Hello world123

The text you have entered is: Hello world123

这是我一直在使用的代码:

.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

我希望在用户输入字符串之后,程序将显示结果。我该如何解决?

1 个答案:

答案 0 :(得分:0)

我终于找到了!通过大量的实验 这是我完成的代码:

.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