2017-06-05 170 views
0

我試圖在一個字符串的同一行輸入單個字符,然後用一個字符串在一行上輸出該字符。我已經嘗試過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兩次。緊接在GETC之後,然後在輸出新的行字符之後。