1.求无符号数组BUF中的最大值存放于MAX中
DATAS SEGMENT
BUF DB 5, 6, 1, 8, 6 ,9 ;BUF是数组名 DB是类型
N=$-BUF ;数组的长度
MAX DB ?
DATAS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS
START:
MOV AX,DATAS
MOV DS,AX
MOV CX,N-1
MOV SI,OFFSET BUF ;等效于LEA SI, BUF
MOV AL,[SI]
CYCLE:
INC SI
CMP AL,[SI]
JAE NEXT
MOV AL,[SI]
NEXT:
LOOP CYCLE
MOV MAX,AL
;该段注释取消后可以运行后在屏幕打印MAX值
;MOV AH,02H
;MOV DL,MAX
;OR DL,30H
;INT 21H
MOV AH,4CH
INT 21H
CODES ENDS
END START
2.求有符号数组BUF中的最小值存放于MIN中
DATAS SEGMENT
BUF DB 5, 6, 1, 8, 6 ,9
N=$-BUF
MIN DB ?
DATAS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS
START:
MOV AX,DATAS
MOV DS,AX
MOV CX,N-1
MOV SI,OFFSET BUF
MOV AL,[SI]
CYCLE:
INC SI
CMP AL,[SI]
JBE NEXT
MOV AL,[SI]
NEXT:
LOOP CYCLE
MOV MIN,AL
MOV AH,4CH
INT 21H
CODES ENDS
END START