当我输入第二个数字的第二个数字时没有任何反应。代码有什么问题?
Nothing happens when I enter 2nd digit of 2nd numbers. What is wrong with the code?
DATA SEGMENT
MSG1 DB 10,13,"ENTER THE FIRST NUMBER: $"
MSG2 DB 10,13,"ENTER THE SECOND NUMBER: $"
MSG3 DB 10,13,"ANSWER: $"
ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV CL,AL
ROL CL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD CL,AL
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV BL,AL
ROL BL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD BL,AL
ADD CL,BL
MOV BL,CL
ROL CL,04H
AND CL,0FH
LEA DX,MSG3
MOV AH,09
INT 21H
CALL OUTPUT8
MOV CL,BL
AND CL,0FH
CALL OUTPUT8
INPUT8 PROC
SUB AL,30H
RET
ENDP
OUTPUT8 PROC
ADD CL,30H
MOV DL,CL
MOV AH,02
INT 21H
RET
ENDP
MOV AH,4CH
INT 21H
ENDS
END START
命令提示符中的输出:
你在BL
和CL
中从键盘上捕获字符并将它们转换为十六进制数,这是因为你使用了高4位BL 保存一位数字,低 4 位保存第二位数字,对于十进制数字,此技术将不起作用。然后执行加法,但是,两个数字都是 hex,因此结果可能包含字母 (A..F)。在这种情况下,过程 OUTPUT8
需要检查 CL
中的数字是数字 (0..9) 还是字母 (A..F)。完成程序的中断也不在正确的位置。以下是两个修复:
DATA SEGMENT
MSG1 DB 10,13,"ENTER THE FIRST NUMBER: $"
MSG2 DB 10,13,"ENTER THE SECOND NUMBER: $"
MSG3 DB 10,13,"ANSWER: $"
ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV CL,AL
ROL CL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD CL,AL
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV BL,AL
ROL BL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD BL,AL
ADD CL,BL
MOV BL,CL
ROL CL,04H
AND CL,0FH
LEA DX,MSG3
MOV AH,09
INT 21H
CALL OUTPUT8
MOV CL,BL
AND CL,0FH
CALL OUTPUT8
MOV AH,4CH ;◄■■ THIS CODE COMES FROM
INT 21H ;◄■■ 26 LINES BELOW.
INPUT8 PROC
SUB AL,30H
RET
ENDP
OUTPUT8 PROC
cmp cl,9 ;◄■■ IF CL <= 9
jbe digit ;◄■■ JUMP TO "DIGIT".
;◄■■ NO JUMP IF CL > 9.
;IF NUMBER IS LETTER (A..F). ◄■■
add cl, 57h ;◄■■ CONVERT 10..15 TO 'A'..'F'.
jmp output8display ;◄■■ SKIP THE "DIGIT" BLOCK.
;IF NUMBER IS DIGIT (0..9). ;◄■■
digit: ;◄■■
ADD CL,30H
output8display: ;◄■■ DISPLAY CL (DIGIT OR LETTER).
MOV DL,CL
MOV AH,02
INT 21H
output8end:
RET
ENDP
;MOV AH,4CH ;◄■■ THIS CODE SHOULD
;INT 21H ;◄■■ BE 26 LINES ABOVE.
ENDS
END START
DATA SEGMENT
MSG1 DB 10,13,"ENTER THE FIRST NUMBER: $"
MSG2 DB 10,13,"ENTER THE SECOND NUMBER: $"
MSG3 DB 10,13,"ANSWER: $"
ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV CL,AL
ROL CL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD CL,AL
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV BL,AL
ROL BL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD BL,AL
ADD CL,BL
MOV BL,CL
ROL CL,04H
AND CL,0FH
LEA DX,MSG3
MOV AH,09
INT 21H
CALL OUTPUT8
MOV CL,BL
AND CL,0FH
CALL OUTPUT8
INPUT8 PROC
SUB AL,30H
RET
ENDP
OUTPUT8 PROC
ADD CL,30H
MOV DL,CL
MOV AH,02
INT 21H
RET
ENDP
MOV AH,4CH
INT 21H
ENDS
END START
命令提示符中的输出:
你在BL
和CL
中从键盘上捕获字符并将它们转换为十六进制数,这是因为你使用了高4位BL 保存一位数字,低 4 位保存第二位数字,对于十进制数字,此技术将不起作用。然后执行加法,但是,两个数字都是 hex,因此结果可能包含字母 (A..F)。在这种情况下,过程 OUTPUT8
需要检查 CL
中的数字是数字 (0..9) 还是字母 (A..F)。完成程序的中断也不在正确的位置。以下是两个修复:
DATA SEGMENT
MSG1 DB 10,13,"ENTER THE FIRST NUMBER: $"
MSG2 DB 10,13,"ENTER THE SECOND NUMBER: $"
MSG3 DB 10,13,"ANSWER: $"
ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV CL,AL
ROL CL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD CL,AL
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CALL INPUT8
MOV BL,AL
ROL BL,04H
MOV AH,01H
INT 21H
CALL INPUT8
ADD BL,AL
ADD CL,BL
MOV BL,CL
ROL CL,04H
AND CL,0FH
LEA DX,MSG3
MOV AH,09
INT 21H
CALL OUTPUT8
MOV CL,BL
AND CL,0FH
CALL OUTPUT8
MOV AH,4CH ;◄■■ THIS CODE COMES FROM
INT 21H ;◄■■ 26 LINES BELOW.
INPUT8 PROC
SUB AL,30H
RET
ENDP
OUTPUT8 PROC
cmp cl,9 ;◄■■ IF CL <= 9
jbe digit ;◄■■ JUMP TO "DIGIT".
;◄■■ NO JUMP IF CL > 9.
;IF NUMBER IS LETTER (A..F). ◄■■
add cl, 57h ;◄■■ CONVERT 10..15 TO 'A'..'F'.
jmp output8display ;◄■■ SKIP THE "DIGIT" BLOCK.
;IF NUMBER IS DIGIT (0..9). ;◄■■
digit: ;◄■■
ADD CL,30H
output8display: ;◄■■ DISPLAY CL (DIGIT OR LETTER).
MOV DL,CL
MOV AH,02
INT 21H
output8end:
RET
ENDP
;MOV AH,4CH ;◄■■ THIS CODE SHOULD
;INT 21H ;◄■■ BE 26 LINES ABOVE.
ENDS
END START