代码:
DATA SEGMENT
BUFF DB 07,02,01,05,04,08,09,03,06
COUNT EQU $-BUFF
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CX,COUNT-1
MOV AH,0
MOV BH,0
L1:MOV DX,8 ;大循环变量
SUB DX,CX
MOV BX,DX
MOV AL,BUFF[BX]
L2:CMP AL,BUFF[BX+1]
JNB NO_EXCHAN ;不小于就不变,小于就交换
XCHG AL,BUFF[BX+1]
MOV AH,BL
MOV BL,DL
MOV BUFF[BX],AL
MOV BL,AH
INC BL
CMP BL,8
JLE L2
LOOP L1
NO_EXCHAN:
INC BL
CMP BL,8
JLE L2
LOOP L1
XOR BX,BX ;显示数字
MOV CX,9
L3:MOV DL,BUFF[BX]
ADD DL,30H
INC BL
MOV AH,2
INT 21H
LOOP L3
MOV AX,4C00H
INT 21H
CODE ENDS
END START