PRINTS MACRO BUFFER ;打印字符串
LEA DX,BUFFER
MOV AH,09H
INT 21H
ENDM
ENTERR MACRO ;回车换行
MOV DL,0DH
MOV AH,02H
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
ENDM
EXIT MACRO ;结束程序
MOV AH,4CH
INT 21H
ENDM
STACK SEGMENT PARA STACK 'STACK'
STA DB 512 DUP(?)
TOP EQU LENGTH STA
STACK ENDS
DATA SEGMENT
NOTE0 DB 'Input numbers: ','$'
NOTE1 DB 'Before Sort: ','$'
NOTE2 DB 'After Sort: ','$'
NOTE3 DB 'The Max Number: ','$'
NOTE4 db 'The Min Number: ','$'
DATAS DB 10 DUP(00H)
NUM DB 10
DATA ENDS
;----------------------------------------------------------------
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
START: MOV AX,STACK
MOV SS,AX
MOV SP,TOP
MOV AX,DATA
MOV DS,AX
;--------------------------
PRINTS NOTE0
;--------------------------输入待排序数据
LEA SI,DATAS
MOV CL,10
GETC: MOV AH,01H
INT 21H
CMP AL,'-'
JE FNUM
SUB AL,30H
MOV [SI],AL
INC SI
DEC CL
MOV AH,01H
INT 21H
CMP CL,0
JNZ GETC
JMP EN0
FNUM: MOV AH,01H
INT 21H
SUB AL,30H
NOT AL
ADD AL,1
MOV [SI],AL
INC SI
DEC CL
MOV AH,01H
INT 21H
CMP CL,0
JNZ GETC
JMP EN0
;--------------------------
EN0: ENTERR
;----------------------------“冒泡法”排序
LEA DI,DATAS
MOV SI,DI
MOV CH,NUM
SUB CH,1
MOV CL,CH
CMPN: MOV AL,[SI]
CMP AL,[SI+1]
JG COUNT
MOV DL,[SI+1]
MOV [SI+1],AL
MOV [SI],DL
COUNT: INC SI
DEC CL
CMP CL,0
JNZ CMPN
MOV SI,DI
DEC CH
MOV CL,CH
CMP CH,0
JNZ CMPN
;-----------------------------
PRINTS NOTE2
;-----------------------------输出排序后数据
MOV CL,NUM
LEA SI,DATAS
PRINT2: MOV DL,[SI]
CMP DL,0
JL PF2
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,20H
MOV AH,02H
INT 21H
INC SI
DEC CL
CMP CL,0
JNZ PRINT2
JMP EN2
PF2: MOV DL,'-'
MOV AH,02H
INT 21H
MOV DL,[SI]
NOT DL
ADD DL,01H
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,20H
MOV AH,02H
INT 21H
INC SI
DEC CL
CMP CL,0
JNZ PRINT2
JMP EN2
;-------------------------------
EN2: ENTERR
;-------------------------------输出最大值及最小值
MAX: PRINTS NOTE3
LEA SI,DATAS
MOV DL,[SI]
CMP DL,0
JL FSHU0
ADD DL,30H
MOV AH,02H
INT 21H
JMP ENT0
FSHU0: MOV DL,'-'
MOV AH,02H
INT 21H
MOV DL,[SI]
NOT DL
ADD DL,01H
ADD DL,30H
MOV AH,02H
INT 21H
ENT0: ENTERR
MIN: PRINTS NOTE4
ADD SI,09H
MOV DL,[SI]
CMP DL,0
JL FSHU1
ADD DL,30H
MOV AH,02H
INT 21H
JMP QUIT
FSHU1: MOV DL,'-'
MOV AH,02H
INT 21H
MOV DL,[SI]
NOT DL
ADD DL,01H
ADD DL,30H
MOV AH,02H
INT 21H
;-------------------------------
QUIT: EXIT
;-------------------------------程序结束
CODE ENDS
END START
冒泡法排序(8086汇编)
最新推荐文章于 2023-07-15 17:30:02 发布