DSEG SEGMENT
BUF DB 'please input a num$'
RESULT DB 0
DSEG ENDS
SSEG SEGMENT STACK
STK DB 100 DUP(?)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:MOV AX,DSEG
MOV DS,AX
MOV AH,9;输出提示用户输入的个数
MOV DX,OFFSET BUF
INT 21H
MOV AH,1
INT 21H
CALL SUM;调用子函数
MOV BH,RESULT;转换成ASC码才能输出
AND BH,0F0H
MOV CL,4
SHR BH,CL
CMP BH,9
JBE L2
ADD BH,7H
L2:
ADD BH,30H
MOV BL,RESULT
AND BL,0FH
CMP BL,9
JBE L3
ADD BL,7H
L3:
ADD BL,30H
MOV AH,2
MOV DH,BH
INT 21H
MOV AH,2
MOV DL,BL
INT 21H
HLT
SUM PROC NEAR
MOV CH,0
MOV CL,AL
MOV BL,2
MOV SI,OFFSET RESULT
L1: ADD [SI],BL
INC BL
INC BL
LOOP L1
RET
SUM ENDP
CSEG ENDS
END START
刚刚写的程序,希望对你有用。