冒泡法排序(8086汇编)

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值