我正在使用 EMU8086。如何添加 4 位数字并使用一个变量在 Assembly 中显示总和?
DATA SEGMENT
MSG1 DB "ENTER NUMBER WITH FOUR DIGITS : $"
MSG2 DB 10,13,"RESULT : $"
D1 DB ?
D2 DB ?
D3 DB ?
D4 DB ?
SUM DB ?
RES DB 10 DUP ('$')
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV AH,0
MUL AL
MOV D1,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV AH,0
MUL AL
MOV D2,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV AH,0
MUL AL
MOV D3,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV AH,0
MUL AL
MOV D4,AL
ADD AL,D3
ADD AL,D2
ADD AL,D1
MOV SUM,AL
LEA SI,RES
CALL HEX2DEC
LEA DX,MSG2
MOV AH,9
INT 21H
LEA DX,RES
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP
END START