CODE SEGMENT ASSUME CS:CODE MAX DW -32768 MIN DW 32767 START: PUSH CS POP DS PUSH CS POP ES CALL INPUTNUM CALL LFCR LEA SI,@ARRAY MOV CX,@NUM CLD @0: LODSW CMP AX,MAX JLE @1 MOV MAX,AX @1: CMP AX,MIN JGE @2 MOV MIN,AX @2: LOOP @0 MOV AX,MAX CALL DSPAXS CALL LFCR MOV AX,MIN CALL DSPAXS MOV AH,4CH INT 21H;============================== LFCR PROC NEAR PUSH AX PUSH DX MOV AH,2 MOV DL,13 INT 21H MOV DL,10 INT 21H POP DX POP AX RET LFCR ENDP;===============================================; 键盘输入数值数组子程序(数组名为@array,元素个数存放在@num中); 可以是负数; 采用字符串缓冲方式输入 INPUTNUM PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI PUSH DI PUSHF ; 对数组@array清零 MOV CX,100 MOV AX,0 LEA DI,@ARRAY CLD REP STOSW ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 初始化序号数组 MOV CX,100 MOV AX,1 LEA DI,@XUHAO @WXUHAO: STOSW INC AX LOOP @WXUHAO ;;;;;;;;;;;;;;;;;;;;;;;;;;;; MOV WORD PTR @NUM,0 ; 输入的数据以一个空格分隔,以回车符结束输入 LEA DX,@STRA MOV AH,10 INT 21H MOV CL,@STRN MOV CH,0 MOV WORD PTR @STRM,CX LEA SI,@STR CLD LEA DI,@ARRAY ;将数组第一个元素的有效地址置入DI MOV WORD PTR @NUM,0 @STIN: MOV AX,0 PUSH AX MOV BYTE PTR @SIGNN,0 @AGAIN1: CMP WORD PTR @STRM,0 JE @LINE0 LODSB DEC WORD PTR @STRM CMP AL,' ' JE @LINE0 CMP AL,'-' JNE @INPUT1 MOV BYTE PTR @SIGNN,1 JMP @AGAIN1 @INPUT1: SUB AL,30H MOV AH,0 MOV BX,AX POP AX MOV CL,10 MOV CH,0 MUL CX ADD AX,BX PUSH AX JMP @AGAIN1 @LINE0: POP AX CMP BYTE PTR @SIGNN,1 JNE @INPUT2 NEG AX @INPUT2: MOV WORD PTR[DI],AX INC WORD PTR @NUM CMP WORD PTR @STRM,0 JE @STINEND INC DI INC DI JMP @STIN @STINEND: POPF POP DI POP SI POP DX POP CX POP BX POP AX RET @STRA DB 255 @STRN DB ? @STR DB 255 DUP(?) @STRM DW 0 @ARRAY DW 100 DUP(0) @NUM DW 0 @CHAR DB ? @SIGNN DB 0 @XUHAO DW 100 DUP(0) INPUTNUM ENDP;=============================== DSPAXS PROC NEAR PUSH AX TEST AX,8000H JNS @DSPAXS1 PUSH AX PUSH DX MOV AH,2 MOV DL,'-' INT 21H POP DX POP AX NEG AX @DSPAXS1: CALL DSPAX POP AX RET DSPAXS ENDP;=============================== DSPAX PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX PUSHF XOR CX,CX MOV BX,10 @DSPAX1: XOR DX,DX DIV BX INC CX OR DX,30H PUSH DX CMP AX,0 JNE @DSPAX1 MOV AH,2 @DISPAX2: POP DX INT 21H LOOP @DISPAX2 POPF POP DX POP CX POP BX POP AX RET DSPAX ENDP;============================== CODE ENDS END START