0
我已經給出了一個計算器在8086裝配中的添加,減去,乘除大十進制數字。這些數字最多可以是30位數字。我用3個數組來存放這些數字(num1,num2,result)。我一直堅持加入,因爲每次運行程序時,都會顯示結果數組爲空(它顯示一個加號和60個零),您能告訴我的代碼出了什麼問題嗎?裝配大數字計算器
ADDER:
MOV BP, offset num1
MOV SI, offset num2
MOV DI, offset result
MOV CL, byte ptr CS:[BP]
MOV CH, byte ptr CS:[SI]
CMP CL, CH
JZ addgood
CMP CL, '-'
JNZ svers
MOV byte ptr CS:[BP], '+'
MOV SI, offset num1
MOV BP, offset num2
JMP SUBSTRACTOR
svers:
CMP CH, '-'
MOV byte ptr CS:[SI], '+'
JMP SUBSTRACTOR
addgood:
lastdigit1:
MOV AL, byte ptr CS:[BP]
CMP AL, 127
JZ gotlastdigit1
INC BP
JMP lastdigit1
gotlastdigit1:
lastdigit2:
MOV AL, byte ptr CS:[SI]
CMP AL, 127
JZ gotlastdigit2
INC SI
JMP lastdigit2
gotlastdigit2:
MOV DI, offset result
ADD DI, 60
initialaddition:
CMP byte ptr CS:[BP], '+'
JNZ notover1
JMP num1end
notover1:
CMP byte ptr CS:[BP], '-'
JNZ notover2
JMP num1end
notover2:
CMP byte ptr CS:[SI], '+'
JNZ notover3
JMP num2end
notover3:
CMP byte ptr CS:[SI], '-'
JNZ notover4
JMP num2end
notover4:
MOV CH, byte ptr CS:[BP]
MOV CS:[DI], CH
MOV CH, byte ptr CS:[SI]
ADD CS:[DI], CH
DEC BP
DEC SI
DEC DI
JMP initialaddition
afteriniadd:
DEC DI
MOV CL, 127
MOV CS:[DI], CL
MOV DI, offset result
ADD DI, 60
truaddition:
MOV CH, 0
MOV CL, byte ptr CS:[DI]
CMP CL, 10
JNAE movealong
CALL pisdod
movealong:
MOV CS:[DI], CL
DEC DI
MOV CL, byte ptr CS:[DI]
CMP CL, 127
JZ isspecial
ADD CS:[DI], CH
JMP truaddition
isspecial:
CMP CH, 0
JZ afteradd
MOV CS:[DI], CH
afteradd:
DEC DI
MOV CS:[DI], 127
MOV SI, offset num1
MOV CL, CS:[SI]
MOV DI, offset result
CMP CL, '+'
JZ adplus
MOV byte ptr CS:[DI], '-'
JMP adminus
adplus:
MOV byte ptr CS:[DI], '+'
adminus:
RET
子程序
num1end:
MOV CL, '-'
CMP byte ptr CS:[SI], CL
JNZ noneed1
JMP afteriniadd
noneed1:
MOV CL, '+'
CMP byte ptr CS:[SI], CL
JNZ noneed2
JMP afteriniadd
noneed2:
MOV CL, byte ptr CS:[SI]
MOV byte ptr CS:[DI], CL
DEC DI
DEC SI
JMP num1end
;......................................
num2end:
MOV CL, '-'
CMP byte ptr CS:[BP], CL
JNZ noneed3
JMP afteriniadd
noneed3:
MOV CL, "+"
CMP byte ptr CS:[BP], CL
JNZ noneed4
JMP afteriniadd
noneed4:
MOV CL, byte ptr CS:[BP]
MOV byte ptr CS:[DI], CL
DEC DI
DEC BP
JMP num2end
pisdod:
CMP CL, 10
JGE notyet
RET
notyet:
SUB CL, 10
INC CH
JMP pisdod
而且數組聲明
num1 db 31 DUP(?), 127
num2 db 31 DUP(?), 127
result db 61 DUP(?), 127
隨着127用作標記物,其中執行數字開始和結束。