欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

汇编三星题目:一个有符号字数组以0为结束标志,编程求这个数组的最大值、 最小值、平均值

程序员文章站 2024-01-30 23:26:40
...
ASSUME CS:CODES,DS:DATAS

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
 MOV AX,DATAS
 MOV DS,AX
 CALL FMAX ;FMAX
 CALL FMIN ;FMIN
 CALL FEVA ;FEVA
 CALL TRAN ;TRAN
 LEA DX,OPT

 MOV AH,09H
 INT 21H
 
 MOV AH,4CH
 INT 21H
 
 ;----FMAX----
 FMAX PROC NEAR
 MOV AX,BUF
 LEA BX,BUF+2
 
 F1:
 MOV DX,[BX]
 CMP DX,0
 JZ EMAX ;EMAX
 CMP AX,DX
 JG NMAX ;NMAX
 MOV AX,DX
 
 NMAX:
 ADD BX,2
 JMP F1 ;F1
 EMAX:
 MOV MAX,AX
 RET
 FMAX ED

 ;----FMIN-----
 FMIN PROC NEAR
 MOV AX,BUF
 LEA BX,BUF+2
 
 F2:
 MOV DX,[BX]
 CMP DX,0
 JZ EMIN ;EMIN
 CMP AX,DX
 JZ NMIN ;NMIN
 MOV AX,DX
 
 NMIN:
 ADD BX,2
 JMP F2
 EMIN:
 MOV MIN,AX
 RET
 FMIN ENDP
 
 ;-----FEVA----
 FEVA PROC NEAR
 MOV AX,BUF
 MOV CX,1
 ;MOV DX,0
 MOV DI,O
 LEA SI,BUF+2
 F3:
 MOV BX,[SI]
 CMP BX,0
 JZ EEVA ;EEVA
 JG NF3 ;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-----
 TRAN PROC NEAR
 MOV AX,MAX
 LEA BX,OMAX+3
 CALL TRANS
 MOV AX,MIN
 LEA BX,OMIN+3
 CALL TRANS
 MOV AX EVA
 LEABX,OEVA+3
 CALL TRANS
 RET 
 TRAN ENDP
 ;-----TRANS------
 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