补全求极值代码 CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX …… DATA SEGMENT ARRAY DB 25,46,3,75,5,30 MAX DB ? MIN DB ? DATA ENDS END START
时间: 2024-02-10 20:32:44 浏览: 177
C语言求极值问题~源码
4星 · 用户满意度95%
补全的求极值代码如下:
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
; 求最大值
MOV AL,ARRAY
MOV MAX,AL
MOV BL,6
MOV CX,1
MAX_LOOP:
CMP CX,BL
JE MAX_END
MOV AL,ARRAY[CX]
CMP AL,MAX
JLE MAX_NEXT
MOV MAX,AL
MAX_NEXT:
INC CX
JMP MAX_LOOP
MAX_END:
; 求最小值
MOV AL,ARRAY
MOV MIN,AL
MOV BL,6
MOV CX,1
MIN_LOOP:
CMP CX,BL
JE MIN_END
MOV AL,ARRAY[CX]
CMP AL,MIN
JGE MIN_NEXT
MOV MIN,AL
MIN_NEXT:
INC CX
JMP MIN_LOOP
MIN_END:
; 显示结果
MOV AH,09H
LEA DX,MAX_MSG
INT 21H
MOV DL,MAX
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,0DH
MOV AH,02H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,09H
LEA DX,MIN_MSG
INT 21H
MOV DL,MIN
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,0DH
MOV AH,02H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV AH,4CH
INT 21H
MAX_MSG DB 'MAX: $'
MIN_MSG DB 'MIN: $'
DATA SEGMENT
ARRAY DB 25,46,3,75,5,30
MAX DB ?
MIN DB ?
DATA ENDS
END START
阅读全文