我给出的最初的问题让我采取了一个错误的程序并修复它,它几乎与下面的那个一样,它不会显示大于10的数字,现在我面临另一个问题。如何才能将三位数字加在一起得到四位数?
我已经尝试使用GETC来查看我是否可以尝试以这种方式获得多个数字,但是到目前为止我尝试的每次尝试都不起作用或者错误程序。
.ORIG x3000 ; begin at x3000
; input two numbers
IN ;input an integer character (ascii) {TRAP 23}
LD R3, HEXN30 ;subtract x30 to get integer
ADD R0, R0, R3
ADD R1, R0, x0 ;move the first integer to register 1
IN ;input another integer {TRAP 23}
ADD R0, R0, R3 ;convert it to an integer
; add the numbers
ADD R2, R0, R1 ;add the two integers
; print the results
LEA R0, MESG ;load the address of the message string
PUTS ;"PUTS" outputs a string {TRAP 22}
ADD R0, R2, x0 ;move the sum to R0, to be output
LD R2, NEG_TEN ; load -10 into R2
ADD R2, R2, R0 ; minus ten from our sum
BRn JUMP ; skip this code if our value is less than 10
AND R4, R4, #0 ; clear R4
ADD R4, R4, R2 ; store R2 into R4
LD R0, ASCII_1 ; load the ascii char '1'
OUT ; print '1' to the console
AND R0, R0, #0 ; clear R0
ADD R0, R0, R4 ; store R4 back into R1
JUMP
LD R3, HEX30 ;add 30 to integer to get integer character
ADD R0, R0, R3
OUT ;display the sum {TRAP 21}
; stop
HALT ;{TRAP 25}
; data
MESG .STRINGZ "The Sum is: "
HEXN30 .FILL xFFD0 ; -30 HEX
HEX30 .FILL x0030 ; 30 HEX
NEG_TEN .FILL #-10
ASCII_1 .FILL x0031 ; ASCII char '1'
.END
最终输出应该让我能够在第一个数字中输入999,然后在第二个数字中输入999,并将它们添加到1998
GETC / IN不允许您输入多个字符。它们只读取一个字符(事先用IN打印提示)。读入的值将以ASCII格式显示。
在阅读所需的3个字符时,您需要保持总数。
这个伪代码应该处理读取3位数字的核心问题。
total = 0;
GETC
total += r0 - '0'
total *= 10
GETC
total += r0 - '0'
total *= 10
GETC
total += r0 - '0'
请注意,* 10s可以通过重复ADD完成。