如何在LC3中以十进制打印?

时间:2019-03-25 02:48:28

标签: ascii lc3

我有一个代码,可以让用户输入5个数字,它们将被加起来并显示总和。如果用户按ENTER键,将显示总和,如果按q,程序将停止。我是LC3的新手,我从不了解如何将ASCII值更改为十进制。我不知道该值是否未存储或求和运算是否不正确。有人知道该怎么做吗?

我已经尝试使用x0030(48)并将其从总和中减去,但它不起作用。

.ORIG x3000

RESTART
AND R0, R0, #0
AND R1, R1, #0  
AND R2, R2, #0  
AND R3, R3, #0      ;Clear all registers
AND R4, R4, #0
AND R5, R5, #0
AND R6, R6, #0

LEA R0, MESSAGE     ;Load and print first prompt message
PUTS

ADD R4, R4, #4      ;Set counter

SUM
GETC            ;Get input and echo it
OUT 
ADD R1, R0, #0

LD R6, QKEY
NOT R6, R6
ADD R1, R6, R0      ;Check if user pressed the letter q
BRz DONE

LD R2, ENTER
NOT R2, R2      ;Check if user pressed ENTER key
ADD R1, R2, R0
BRz FINISH

ADD R1, R0, R1      ;Store sum value in R1
LEA R0, NEXT        
PUTS            ;Load and print next prompt

ADD R4, R4, #-1     ;Decrement counter
BRp SUM         ;Loop

GETC            ;Get final input and echo it
OUT 
ADD R1, R0, #0

LD R6, QKEY
NOT R6, R6
ADD R1, R6, R0      ;Check if user pressed the letter q
BRz DONE

LD R2, ENTER
NOT R2, R2      ;Check if user pressed ENTER key
ADD R1, R2, R0
BRz FINISH

FINISH
LEA R0, OUTPUT      ;Load and print prompt of sum
PUTS
LD R3, NEG30
NOT R3, R3
ADD R3, R3, #1
ADD R1, R1, R0
OUT

BR RESTART      ;Restart program
DONE
LEA R0, QUIT
PUTS            ;Load and print quit prompt
HALT


MESSAGE .STRINGZ    "\n Enter Start Number (0 - 9): "
NEXT    .STRINGZ    "\n Enter Next Number (0 - 9): "
OUTPUT  .STRINGZ    "\n The sum of the numbers is: "
NEG30   .FILL       x30
QUIT    .STRINGZ    "\n Thank you for playing!"
QKEY    .FILL       x70
ENTER   .FILL       x09

.END

0 个答案:

没有答案