写一个程序求2个数的和
Write a program to sum 2 numbers
你好,我想写一个练习来对 0 到 9 之间的 2 个数字求和,问题是当我只能得到最多 15 的结果时,如果结果是 17,它会回到 0将显示 1.
我做错了什么?
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
;*******************************
;* Programa: CONDIC4.ASM *
;*******************************
.MODEL small
.STACK 512d
.DATA
msg1 DB 'Decimal 1 (0 to 9): ', 024h
msg2 DB 0Dh, 0Ah, 'Decimal 2 (0 to 9): ', 024h
msg3 DB 0Dh, 0Ah, 'Sum = ', 024h
msg4 DB 0Dh, 0Ah, 'Invalid', 024h
.CODE
LEA DX, msg1
CALL write
CALL read
MOV BH, AL
LEA DX, msg2
CALL write
CALL read
MOV BL, AL
LEA DX, msg3
CALL write
XCHG AX, BX
ADD AL, AH
SUB AH, AH
AAA
MOV DX, AX
MOV AH, 0Eh
CMP DH, 0h
JE not_zero
OR DH, 30h
MOV AL, DH
INT 010h
not_zero:
OR DL, 30h
MOV AL, DL
INT 010h
INT 020h
write PROC NEAR
MOV AH, 09h
INT 021h
RET
write ENDP
read PROC NEAR
MOV AH, 01h
INT 021h
CMP AL, 030h
JL erro
CMP AL, 03Ah
JGE erro
SUB AL, 030h
RET
erro:
LEA DX, msg4
CALL write
INT 020h
RET
read ENDP
我使用 MOV (MOV AH, 0h) 命令而不是 SUB (SUB AH,AH) 命令修复了它,因为手册说 MOV 不会更改任何标志。
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
;*******************************
;* Programa: CONDIC4.ASM *
;*******************************
.MODEL small
.STACK 512d
.DATA
msg1 DB 'Decimal 1 (0 to 9): ', 024h
msg2 DB 0Dh, 0Ah, 'Decimal 2 (0 to 9): ', 024h
msg3 DB 0Dh, 0Ah, 'Sum = ', 024h
msg4 DB 0Dh, 0Ah, 'Invalid', 024h
.CODE
LEA DX, msg1
CALL write
CALL read
MOV BH, AL
LEA DX, msg2
CALL write
CALL read
MOV BL, AL
LEA DX, msg3
CALL write
XCHG AX, BX
ADD AL, AH
MOV AH, 0h ;Clears AH WITHOUT CHANGING FLAGS
AAA
MOV DX, AX
MOV AH, 0Eh
CMP DH, 0h
JE not_zero
OR DH, 30h
MOV AL, DH
INT 010h
not_zero:
OR DL, 30h
MOV AL, DL
INT 010h
INT 020h
write PROC NEAR
MOV AH, 09h
INT 021h
RET
write ENDP
read PROC NEAR
MOV AH, 01h
INT 021h
CMP AL, 030h
JL erro
CMP AL, 03Ah
JGE erro
SUB AL, 030h
RET
erro:
LEA DX, msg4
CALL write
INT 020h
RET
read ENDP
你好,我想写一个练习来对 0 到 9 之间的 2 个数字求和,问题是当我只能得到最多 15 的结果时,如果结果是 17,它会回到 0将显示 1.
我做错了什么?
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
;*******************************
;* Programa: CONDIC4.ASM *
;*******************************
.MODEL small
.STACK 512d
.DATA
msg1 DB 'Decimal 1 (0 to 9): ', 024h
msg2 DB 0Dh, 0Ah, 'Decimal 2 (0 to 9): ', 024h
msg3 DB 0Dh, 0Ah, 'Sum = ', 024h
msg4 DB 0Dh, 0Ah, 'Invalid', 024h
.CODE
LEA DX, msg1
CALL write
CALL read
MOV BH, AL
LEA DX, msg2
CALL write
CALL read
MOV BL, AL
LEA DX, msg3
CALL write
XCHG AX, BX
ADD AL, AH
SUB AH, AH
AAA
MOV DX, AX
MOV AH, 0Eh
CMP DH, 0h
JE not_zero
OR DH, 30h
MOV AL, DH
INT 010h
not_zero:
OR DL, 30h
MOV AL, DL
INT 010h
INT 020h
write PROC NEAR
MOV AH, 09h
INT 021h
RET
write ENDP
read PROC NEAR
MOV AH, 01h
INT 021h
CMP AL, 030h
JL erro
CMP AL, 03Ah
JGE erro
SUB AL, 030h
RET
erro:
LEA DX, msg4
CALL write
INT 020h
RET
read ENDP
我使用 MOV (MOV AH, 0h) 命令而不是 SUB (SUB AH,AH) 命令修复了它,因为手册说 MOV 不会更改任何标志。
#make_COM#
; COM file is loaded at CS:0100h
ORG 100h
;*******************************
;* Programa: CONDIC4.ASM *
;*******************************
.MODEL small
.STACK 512d
.DATA
msg1 DB 'Decimal 1 (0 to 9): ', 024h
msg2 DB 0Dh, 0Ah, 'Decimal 2 (0 to 9): ', 024h
msg3 DB 0Dh, 0Ah, 'Sum = ', 024h
msg4 DB 0Dh, 0Ah, 'Invalid', 024h
.CODE
LEA DX, msg1
CALL write
CALL read
MOV BH, AL
LEA DX, msg2
CALL write
CALL read
MOV BL, AL
LEA DX, msg3
CALL write
XCHG AX, BX
ADD AL, AH
MOV AH, 0h ;Clears AH WITHOUT CHANGING FLAGS
AAA
MOV DX, AX
MOV AH, 0Eh
CMP DH, 0h
JE not_zero
OR DH, 30h
MOV AL, DH
INT 010h
not_zero:
OR DL, 30h
MOV AL, DL
INT 010h
INT 020h
write PROC NEAR
MOV AH, 09h
INT 021h
RET
write ENDP
read PROC NEAR
MOV AH, 01h
INT 021h
CMP AL, 030h
JL erro
CMP AL, 03Ah
JGE erro
SUB AL, 030h
RET
erro:
LEA DX, msg4
CALL write
INT 020h
RET
read ENDP