一个有符号字数组以0为结束标志,编程求这个数组的最大值、 最小值、平均值。
DATAS SEGMENT
BUF DW 7FFFH,7FFFH,0
MAX DW 0000H
MIN DW 0000H
EVA DW 0000H
NUM DW 16
OPT DB 'THE MAX IS'
OMAX DB '0000H',0DH,0AH,'THE MIN IS'
OMIN DB '0000H',0DH,0AH,'THE EVA IS'
OEVA DB '0000H$'
;此处输入数据段代码
DATAS ENDS
CODES SEGMENT
MAIN PROC FAR
ASSUME CS:CODES,DS:DATAS
MOV AX,DATAS
MOV DS,AX
CALL FMAX
CALL FMIN
CALL FEVA
CALL TRAN
LEA DX,OPT
MOV AH,09H
INT 21H
;此处输入代码段代码
MOV AH,4CH
INT 21H
MAIN ENDP
FMAX PROC NEAR
MOV AX,BUF
LEA BX,BUF+2
F1: MOV DX,[BX]
CMP DX,0
JZ EMAX
CMP AX,DX
JG NMAX
MOV AX,DX
NMAX:
ADD BX,2
JMP F1
EMAX:
MOV MAX,AX
RET
FMAX ENDP
FMIN PROC NEAR
MOV AX,BUF
LEA BX,BUF+2
F2: MOV DX,[BX]
CMP DX,0
JZ EMIN
CMP AX,DX
JL NMIN
MOV AX,DX
NMIN:
ADD BX,2
JMP F2
EMIN:
MOV MIN,AX
RET
FMIN ENDP
FEVA PROC NEAR
MOV AX,BUF
MOV CX,1
;MOV DX,0
MOV DI,0
LEA SI,BUF+2
F3:
MOV BX,[SI]
CMP BX,0
JZ EEVA
JG NF3
ADD DI,1
NF3:
ADD AX,BX
ADC DX,0
ADD SI,2
INC CX
JMP F3
EEVA:
SUB DX,DI
IDIV CX
MOV EVA ,AX
RET
FEVA ENDP
TRAN PROC NEAR
MOV AX,MAX
LEA BX,OMAX+3
CALL TRANS
MOV AX,MIN
LEA BX,OMIN+3
CALL TRANS
MOV AX, EVA
LEA BX,OEVA+3
CALL TRANS
RET
TRAN ENDP
TRANS PROC NEAR
MOV CX,4
L1:
MOV DX,0
DIV NUM
CMP DL,9
JNA NEXT
ADD DL,7
NEXT:
ADD [BX],DL
DEC BX
LOOP L1
RET
TRANS ENDP
CODES ENDS
END MAIN