LC-3 - 如何存储输入字符然后在字符串后打印输入和输出的输入字符?
LC-3 - How to store input character then print input character with both input and output after strings?
我试图在与字符串相同的行上输入单个字符,然后将该字符也与字符串输出到同一行。我已经尝试过 GETC 和 PUTC,但我得到的结果是 '0 我对这个 LC-3 东西真的很陌生,非常感谢一些帮助来克服这个障碍。
这是我目前的情况。
.ORIG x3000 ;start assembly directive
MyMain
lea r0, input ;point to input string
trap x22 ;print string out
GETC
ld r0, newLine ;get <crlf>
trap x21 ;print it out
lea r0, output ;point to output string
trap x22 ;print string out
PUTC
ld r0, newLine ;get <crlf>
trap x21 ;print it out
lea r0, term ;point to termination string
trap x22 ;print string out
ld r0, newLine ;get <crlf>
trap x21 ;print it out
MyMainEnd trap x25 ;stop the program
; constants
newLine .FILL x0A ;line feed and Carriage return in LC-3
input .STRINGZ "Please input a character: "
output .STRINGZ "You input the character: "
term .STRINGZ "Program execution terminated!"
.END ;end assembly directive
这是 GETC 的文档
GETC - 从键盘读取单个字符。该字符不会回显到控制台上。它的 ASCII 码被复制到 R0 中。 R0高8位清零
您的问题是将 R0 用于所有内容,因为 ld r0,换行符会破坏您读入的字符。调用 GETC 陷阱后,您需要将 R0 的值复制到其他寄存器,然后将其移回 R0当你想打电话给 PUTC.
另外,根据您的问题,您需要两次调用 PUTC。在您的 GETC 之后,然后在您输出换行符之后。
我试图在与字符串相同的行上输入单个字符,然后将该字符也与字符串输出到同一行。我已经尝试过 GETC 和 PUTC,但我得到的结果是 '0 我对这个 LC-3 东西真的很陌生,非常感谢一些帮助来克服这个障碍。
这是我目前的情况。
.ORIG x3000 ;start assembly directive
MyMain
lea r0, input ;point to input string
trap x22 ;print string out
GETC
ld r0, newLine ;get <crlf>
trap x21 ;print it out
lea r0, output ;point to output string
trap x22 ;print string out
PUTC
ld r0, newLine ;get <crlf>
trap x21 ;print it out
lea r0, term ;point to termination string
trap x22 ;print string out
ld r0, newLine ;get <crlf>
trap x21 ;print it out
MyMainEnd trap x25 ;stop the program
; constants
newLine .FILL x0A ;line feed and Carriage return in LC-3
input .STRINGZ "Please input a character: "
output .STRINGZ "You input the character: "
term .STRINGZ "Program execution terminated!"
.END ;end assembly directive
这是 GETC 的文档
GETC - 从键盘读取单个字符。该字符不会回显到控制台上。它的 ASCII 码被复制到 R0 中。 R0高8位清零
您的问题是将 R0 用于所有内容,因为 ld r0,换行符会破坏您读入的字符。调用 GETC 陷阱后,您需要将 R0 的值复制到其他寄存器,然后将其移回 R0当你想打电话给 PUTC.
另外,根据您的问题,您需要两次调用 PUTC。在您的 GETC 之后,然后在您输出换行符之后。