我爲LC-3編寫了一個程序,用於輸入10以下的數字,直到達到0,然後輸出輸入的最大數字。LC-3程序正在返回一些無法打印的東西
一切似乎工作,但我不斷得到一個不正確的,或不存在的結果。例如,如果我輸入1,2,3,然後0,它應該說:
零輸入,結束程序。輸入的最大整數是3
但我沒有得到任何回報。
我試圖用來輸出最大的整數的方法是使用二進制補碼系統來確定更大的二進制數,如果沒有進入0則返回,但我認爲我的邏輯有一個主要問題。
對不起,格式化可能有些不可靠,如果您需要更多信息或者我做了錯誤的事情(關於後 - 我知道我的代碼是錯誤的),請告訴我。
預先感謝您! (我也有在代碼的底部的樣本輸出。)
.ORIG x3000
AND R0,R0,#0 ;clear R0
AND R0,R0,#0 ;clear R1
LEA R0, MSG1 ;load address of message 1
PUTS ;display message
GETC ;read in character from keyboard
OUT ;echo input
ST R0, NUM1 ;store the number in num1
LD R2, NUM1
LD R1, POS48
ADD R2,R2, R1 ;adds 48 to make the character a number
BRz ZERO ;checks if the number is zero
LD R0, NEWLINE ;load newline
OUT ;execute newline
LOOP LEA R0, MSG1 ;load address of message 1
PUTS ;display message
GETC ;read in character from keyboard
OUT ;echo input
ST R0, NUM2 ;store character in num2
LD R2, POS48
LD R3, NUM2
ADD R0, R3, R2 ;adds 48 to make the character a number
BRz ZERO ;checks if the number is zero
LD R0, NEWLINE ;load newline
OUT ;execute newline
LD R1, NUM1 ;load the first number
LD R2, NUM2 ;load the second number
NOT R2, R2 ;two's complement of R2
ADD R2, R2, #1 ;getting negative of num 2
ADD R0, R1, R2 ;adding the two values
ST R0, MAX ;storing larger number in NUM5
BRnz LOOP ;Branch if R0 is positive
ZERO LEA R0, MSG2 ;load message if number entred is zero
PUTS ;display message
LD R0, NEWLINE ;load newline
OUT ;execute newline
LEA R0, MSG3 ;load largest int message
PUTS ;display
LD R2, MAX
LD R1, POS48
ADD R1, R2, R1 ;adds 48 to make the character a number
LD R0, MAX ;load largest int
OUT ;display largest int
HALT ;end program
;*** Data ***
MSG1 .STRINGZ "Enter a single-digit integer: "
MSG2 .STRINGZ "Zero entered, ending program."
MSG3 .STRINGZ "The largest integer is: "
POS48 .FILL #48
NEWLINE .FILL #10
NUM1 .BLKW 1
NUM2 .BLKW 1
MAX .BLKW 1
.END
樣本輸出 - 輸入一個單位的整數:1 輸入一個單個位的整數:2 輸入一個單個位的整數:3 輸入一位數的整數:0 零輸入,結束程序。