;自动化 11351011 ;计算一位数0-8的阶乘,包括异常处理 PRINT MACRO X ;宏定义输出字符串 LEA DX,X ;提示输出结果 MOV AH,09H INT 21H ENDM GoEnter MACRO ;回车,换行 PUSH AX MOV AH,02H MOV DL,0DH INT 21H MOV AH,02H MOV DL,0AH INT 21H POP AX ENDM DATA SEGMENT WARNING DB "===>Please input a value between 0 and 8 <===",0DH,0AH,'$' ;输入提示语句 RESULT DB "===>The result is ",0DH,0AH,'$' ;结果输出提示语句 ERR DB "===>Invalid number! Please try again....===>",0DH,0AH,'$' ;非法输入提示语句 TryAgain DB "===>Try again?(Enter 'Y'for Yes,'N'for No===>)",0DH,0AH,'$' ;询问用户是否再次尝试输入 ERR_ DB "===>Invalid number! Enter 'Y'for Yes,'N'for No===>",0DH,0AH,'$' ;非法输入提示语句 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATA MAIN PROC FAR MOV AX,DATA ;初始化DS MOV DS,AX PRINT WARNING ;提示用户输入 MOV AH,01H ;输入一位整数 INT 21H CMP AL,'0' JB ERR1 ;输入小于 0 则跳转 CMP AL,'8' JA ERR1 ;输入大于 8 则跳转 SUB AL,30H ;ASC码转为十进制 MOV CL,AL ;把用户输入值赋给CL MOV CH,00H MOV AX,1 ;初始化AX L: MUL CX ;利用循环计算阶乘 LOOP L GoEnter DISPLAY: MOV BX,10 MOV CX,0 ;对CX置零 L0: MOV DX,0 ;对DX置零 DIV BX OR DX,0E30H ;转换ASCII码(AH=0EH,AL=ASCII码) PUSH DX ;存储结果 INC CX ;统计ASCII码个数 CMP AX,0 ;跳转条件 JNZ L0 PRINT RESULT ;提示输出结果 L1: POP AX INT 10H ;显示输出结果 LOOP L1 ;循环cx次输出ASCII码 Again: GoEnter PRINT TryAgain ;询问 MOV AH,01H ;输入一位字符 INT 21H CMP AL,'Y' JE MAIN ;等于'Y' CMP AL,'Y' JNE J1 ;不等于'Y' J1: CMP AL,'N' JE Finish ;等于'N' CMP AL,'N' JNE ERR2 ;不等于'N' ERR1: GoEnter PRINT ERR ;提示输入错误 GoEnter JMP MAIN ;返回输入 ERR2: GoEnter PRINT ERR_ ;提示输入错误 GoEnter JMP Again Finish: MOV AH,4CH ;返回DOS INT 21H MAIN ENDP CODE ENDS END MAIN 本文来源:https://www.wddqw.com/doc/a2fa223213a6f524ccbff121dd36a32d7375c76a.html