我正在尝试创建一个子程序来输出用户输入数字的自定义提示。
IN陷阱例程通常表示Input a character>
。我需要说出来
Please enter a number between 0 and 9:
目前我有这个:
.ORIG x3000
JSR SAVE ; THIS WILL JUMP TO SUBROUTINE TO SAVE CURRENT REGISTER CONTENTS
SAVE ST R7, x3031 ;SAVES REGISTER VALUE INTO THE ADDRESS
ST R3, x3030 ;SAVES REGISTER VALUE INTO THE ADDRESS
ST R2, X302F ;SAVES REGISTER VALUE INTO THE ADDRESS
ST R1, X302E ;SAVES REGISTER VALUE INTO THE ADDRESS
LD R0, ten ;LOADS TEN FILL VALUE
JSR check
LEA R1, msg1
LDR R0, R1, #0
BRz error
JMP check
ADD R1, R1, #1
check ST R7, X300D
LDI R3, dsr
BRzp x300D
STI R0, ddr
LD R7, x300D
RET
ten .FILL x000A
dsr .FILL xFE04
ddr .FILL xFE06
msg2 .STRINGZ "Enter a number (0 - 9) to subtract from the first number:
msg1 .STRINGZ "Please enter a number between 0 and 9:
.END
答案 0 :(得分:1)
您的代码存在很多问题。
编写子程序的步骤应按如下方式完成
SUBR
; save used registers
; do computation
; restore used registers
; ret
例如,在R0中打印出单个数字整数的子程序(没有任何错误检查)将如下所示
PRINT_SINGLE_DIGIT
ST R7, R7SAVE ; out is a trap so r7 is clobbered we should save it.
ST R0, R0SAVE ; save R0.
ADD R0, R0, 15
ADD R0, R0, 15
ADD R0, R0, 15
ADD R0, R0, 3
OUT
LD R0, R0SAVE
LD R7, R7SAVE ; restore R7
RET
R0SAVE .blkw 1
R7SAVE .blkw 1