2017-06-05 36 views
0

文字列と同じ行に1文字を入力し、その文字を文字列のある行に出力しようとしています。私はGETCとPUTCを試しましたが、私は '0'の結果を得ています。私はこのLC-3のものに本当に新しいものです。そして、道路のこの隆起を乗り越えるためのいくつかの助けに本当に感謝します。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 

答えて

1

はGETC

GETCのドキュメントです。キャラクターはコンソールにエコーされません。そのASCIIコードはR0にコピーされます。 R0の上位8ビットがクリアされます

あなたの問題は、すべてR0をld r0として使用しています。改行は、読み込んだ文字を壊します。GETCトラップを呼び出した後、R0の値を他のレジスタにコピーする必要がありますPUTCを呼び出すときにR0に戻します。

あなたの質問から、PUTCを2回呼び出す必要があります。あなたのGETCの直後に、新しい行の文字を出力した後。

関連する問題