我试图在汇编中编写一个相当简单的程序,并遇到一些问题。我设法使用while循环编写应用程序,但它在递归时似乎有奇怪的结果。当我为第一个整数输入100而第二个输入10时,它返回正确的答案。但是,如果我选择100和15,我会得到意想不到的结果。
BR main
x: .BLOCK 2
y: .BLOCK 2
answer: .BLOCK 0
;
retVal: .EQUATE 12
result: .EQUATE 10
n: .EQUATE 8
m: .EQUATE 6
n1: .EQUATE 2
m1: .EQUATE 0
myMod: SUBSP 4,i
if: LDA n,sf
CPA m,sf
BRGE else,i
LDA n,sf
STA result,d
BR endIf
else: LDA n,sf
SUBA m,sf
STA n1,d
LDA m,sf
STA m1,d
LDA n1,i
STA -4,s
LDA m1,i
STA -6,s
SUBSP 6,i
CALL myMod
ADDSP 6,i
STA result,d
endIf: LDA result,d
STA retVal,s
RET4
main: STRO openMsg,d
DECI x,d
STRO openMsg,d
DECI y,d
LDA x,i
STA -4,s
LDA y,i
STA -6,s
SUBSP 6,i
CALL myMod
ra1: ADDSP 8,i
DECO x,d
STRO msg1,d
DECO y,d
STRO msg2,d
DECO -2,s
STOP
openMsg: .ASCII "Enter a positive number: \x00"
msg1: .ASCII " % \x00"
msg2: .ASCII " is \x00"
.END