PRINT MACRO OPT;输出十进制数字的宏 MOV AX,OPT MOV BL,10 DIV BL ;余数在ah,商在al ,商为十位,余数为个位 MOV DX,AX ADD DH,30H ADD DL,30H MOV AH,02H INT 21H ;输出十位 MOV DL,DH MOV AH,02H ;输出个位 INT 21H MOV DL,20H MOV AH,02H INT 21H ;输出空格 ENDM ;..................................................................................................................... DATA SEGMENT ARRAY DW 3,2,1 MESSAGE1 DB "ORIGINAL ARRAY:",13,10,'$' MESSAGE2 DB 13,10,"AFERT SELECTEDSORT:",13,10,'$' TEMP DW 0 COUNT DW 3 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA ;..................................................................................................................... MAIN PROC FAR START: MOV AX,DATA MOV DS,AX LEA DX,MESSAGE1 MOV AH,09H INT 21H ;提示输出原始数组 MOV CX, COUNT LEA SI,ARRAY ORG_PRINT: PRINT [SI] ADD SI,2 LOOP ORG_PRINT MOV DL,0 MOV AH,02H INT 21H CALL SORT;调用排序子程序 LEA DX,MESSAGE2 MOV AH,09H INT 21H MOV CX,COUNT LEA SI,ARRAY SORTED_PRINT: PRINT [SI] ADD SI,2 LOOP SORTED_PRINT MOV AH,4CH INT 21H MAIN ENDP ;................................................................................................................................ SORT PROC NEAR;选择排序子程序 MOV CX,COUNT LEA DI,ARRAY LOP1: MOV DX,CX MOV SI,DI MOV BX,DI ADD BX,2 LOP2: MOV AX,[SI] CMP AX,[BX] JLE CONTINUE MOV SI,BX CONTINUE: ADD BX,2 LOOP LOP2 MOV AX,[DI] XCHG AX,[SI] MOV [DI],AX ADD DI ,2 MOV CX,DX LOOP LOP1 RET SORT ENDP CODE ENDS END START