8086汇编语言求数组中的最大值的程序,谁会?急求……⊙﹏⊙
发布网友
发布时间:2024-07-03 18:15
我来回答
共1个回答
热心网友
时间:2024-07-29 18:23
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
START:
PUSH CS
POP DS
PUSH CS
POP ES
CALL INPUTNUM
LEA SI,ARRAY
MOV CX,[NUM]
MOV AX,0
MOV [NUM_MAX],AX
@MAIN0: MOV AX,WORD PTR [SI]
CMP [NUM_MAX],AX
JNC @MAIN1 ; 无符号数用 jnc,有符号数用 jl
MOV [NUM_MAX],AX
@MAIN1: INC SI
INC SI
LOOP @MAIN0
LEA DX,LFCR
MOV AH,9
INT 21H
MOV AX,[NUM_MAX]
CALL DISPAX
MOV AH,4CH
INT 21H
NUM_MAX DW ?
LFCR DB 10,13,'$'
;==============================================================
; 键盘输入数值数组子程序(数组名为array,元素个数存放在num中)
INPUTNUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSHF
; 输入的字数据以一个空格分隔,以回车符结束输入
LEA DI,ARRAY ;将数组第一个元素的有效地址置入DI
MOV WORD PTR[NUM],0
STIN:
MOV AX,0
PUSH AX
AGAIN1:
MOV AH,1
INT 21H
MOV BYTE PTR[CHAR],AL
CMP AL,13
JE LINE0
CMP AL,' '
JE LINE0
SUB AL,30H
MOV AH,0
MOV SI,AX
POP AX
MOV CL,10
MOV CH,0
MUL CX
ADD AX,SI
PUSH AX
JMP AGAIN1
LINE0:
POP AX
MOV WORD PTR[DI],AX
INC WORD PTR[NUM]
CMP BYTE PTR[CHAR],13
JE STINEND
INC DI
INC DI
JMP STIN
STINEND:
POPF
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
ARRAY DW 500 DUP(0)
NUM DW 0
CHAR DB ?
INPUTNUM ENDP
; 将要显示的无符号数置于 ax 中
DISPAX PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSHF
;================
PUSH CS
POP DS
MOV BYTE PTR NZ,0
PUSH AX
LEA SI,DIVARR
MOV CX,5
@1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @2
CMP BYTE PTR NZ,1
JE @2
CMP CX,1
JE @2
MOV DL,20H
JMP @3
@2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZ,1
@3:
MOV AH,2
INT 21H
INC SI
INC SI
LOOP @1
POP DX
;=============
MOV DL,32
MOV AH,2
INT 21H
POPF
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARR DW 10000,1000,100,10,1
NZ DB 0
DISPAX ENDP
CODE ENDS
END START