2015-04-01 36 views

回答

0

要做到這一點,最好是設置一個'for'循環來計算輸入數量最多爲5個。當你從用戶存儲器獲取每個輸入的值後,再將其值存入另一個寄存器。當你做實際的比較時,你將需要NOT,並立即將1添加到其中一個數字。然後將這兩個數字加在一起並檢查它們是否等於零。

我會嘗試給你一些示例代碼,而不實際編寫所有代碼。通常LC-3用於大學內的ASM學習。

.ORIG x3000 

MAIN  
AND R1, R1, #0   ; Clear R1 

LOOP   
    LD R2, LIMIT 
    ADD R4, R1, R2  ; Check to see if we've hit our limit 
    BRz END_LOOP 

    getc    ; Capture a character and stores it in r0. 
    out     ; Sends the character in r0 to the terminal. 

    AND R3, R3, #0  ; Clear R3 
    ADD R3, R3, R0  ; Store the user's input into R3 to compare the next time we loop 

    ADD R1, R1, #1  ; Increment our loop counter 
    BR LOOP    ; Branch to LOOP 
END_LOOP 

HALT  

; Variables 
LIMIT .FILL x0005  ; Store the value of 5 into our loop limit variable 

.END