;x86上运行
;适合两个数之和不超出五位数
;加数低于五位输入时最高位要补0
;相加结果用ASCII码存储在DATA1中
;by 蓝潇枫子
STACK SEGMENT STACK 'STACK'
DB 20 DUP(?)
STACK ENDS
DATA SEGMENT
DATA1 DB "06909"
DATA2 DB "17859"
SYM1 DB "DATA1="
SYM2 DB "DATA2="
SYM3 DB "SUM= "
BUFFER DB 30 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK,ES:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
;显示加数和被加数
LEA SI,SYM1
LEA DI,BUFFER
MOV CX,6
CLD
REP MOVSB
LEA SI,DATA1
CALL DISP
LEA SI,SYM2
LEA DI,BUFFER
MOV CX,6
CLD
REP MOVSB
LEA SI,DATA2
CALL DISP
;两数相加
MOV CX,5
MOV SI,0
AGAIN1:
MOV AL,DATA1[SI]
SUB AL,30H
MOV DATA1[SI],AL
MOV AL,DATA2[SI]
SUB AL,30H
MOV DATA2[SI],AL
INC SI
LOOP AGAIN1
MOV CX,5
AGAIN2:
DEC SI
MOV AL,DATA1[SI]
MOV BL,DATA2[SI]
ADC AL,BL
AAA
MOV DATA1[SI],AL
LOOP AGAIN2
MOV CX,5
AGAIN3:
MOV AL,DATA1[SI]
ADD AL,30H
MOV DATA1[SI],AL
MOV AL,DATA2[SI]
ADD AL,30H
MOV DATA2[SI],AL
INC SI
LOOP AGAIN3
;显示结果
LEA SI,SYM3
LEA DI,BUFFER
MOV CX,6
CLD
REP MOVSB
LEA SI,DATA1
CALL DISP
MOV AH,4CH
INT 21H
DISP PROC
LEA DI,BUFFER+6
MOV CX,5
CLD
REP MOVSB
MOV AL,0DH
MOV [DI],AL
INC DI
MOV AL,0AH
MOV [DI],AL
INC DI
MOV AL,'$'
MOV [DI],AL
LEA DX,BUFFER
MOV AH,09H
INT 21H
RET
DISP ENDP
CODE ENDS
END START