DATA EQU 20H N EQU 8 TEST: MOV DPTR,#LIST MOV R0,#DATS MOV R2,#N CPY: CLR A MOVC A,@A+DPTR MOV @R0,A INC R0 INC DPTR DJNZ R2,COPY LCALL BUBSORT LIST: DB 53H,87H,12H,9AH DB 2FH,3CH,0A8H,0BCH BUBSORT: MOV R4,#N SRT1: CLR F0 MOV A,R4 DEC A MOV R4,A MOV R2,A JZ SRT4 MOV R0,#DATS SRT2: MOV A,@R0 MOV R3,A INC R0 MOV A,@R0 CLR C SUBB A,R3 JNC SRT3 SETB F0 MOV A,R3 XCH A,@R0 DEC R0 XCH A,@R0 INC R0 SRT3: DJNZ R2,SRT2 JB F0,SRT1 SRT4: RET 2多字节浮点数冒泡排序实例 BBBLPSRT: ADDR EQU 2000H NUMB EQU 0120H TEMP1 EQU 30H TEMP2 EQU 33H EXC BIT 00H TST: MOV DPTR,#ADDR MOV R2,DPH MOV R0,DPL MOV DPTR,#NUMB MOV R2,DPH MOV R3,DPL MOV DPTR,#LIST MOV A,R3 JZ TST1 INC R2 TST1: MOV R4,#3 TEST2: CLR A MOVC A,@A+DPTR MOVX @R0,A INC DPTR INC R0 CJNE R0,#0,TST3 INC R2 TST3: DJNZ R4,TST2 DJNZ R3,TST1 DJNZ R2,TST1 LCALL BUBB BUBB: MOV R6,#HIGH(NUMB) MOV R7,#LOW(NUMB) BUBB1: CLR EXC CJNE R7,#0,BUBB2 DEC R6 BUBB2: DEC R7 MOV A,R6 MOV R4,A MOV A,R7 MOV R5,A ORL A,R6 JZ BUBBE MOV A,R5 JZ BUBB3 INC R4 BUBB3: MOV DPTR,#ADDR BUBB4: MOV R0,#TEMP1 LCALL LOAD PUSH DPH PUSH DPL LCALL LOAD POP DPL POP DPH MOV R0,#TEMP2 MOV R1,#TEMP1 LCALL FCMP JNC BUBB6 SETB EXC MOV R0,#TEMP1 LCALL SAVE MOV A,#0FAH ADD A,DPL MOV DPL,A JC BUBB5 DEC DPH BUBB5: LCALL SAVE BUBB6: DJNZ R5,BUBB4 DJNZ R4,BUBB4 JB EXC,BUBB1 BUBBE: RET LOAD: MOV R3,#3 LOAD1: MOVX A,@DPTR MOV @R0,A INC R0 INC DPTR DJNZ R3,LOAD1 RET SAVE: MOV R3,#3 SAVE1: MOV A,@R0 MOVX @DPTR,A INC R0 INC DPTR DJNZ R3,SAVE1 RET FCMP: MOV A,@R0 XRL A,@R1 JNB ACC.7,CMP2 MOV A,@R0 RLC A MOV A,#0FFH RET CMP2: MOV A,@R1 MOV C,ACC.6 MOV ACC.7,C MOV B,A MOV A,@R0 MOV C,ACC.7 MOV F0,C MOV C,ACC.6 MOV ACC.7,C CLR C SUBB A,B JZ CMP6 RLC A JNB F0,CMP5 CPL C CMP5: MOV A,#0FFH RET CMP6: INC R0 INC R0 INC R1 INC R1 CLR C MOV A,@R0 SUBB A,@R1 MOV B,A DEC R0 DEC R1 MOV A,@R0 SUBB A,@R1 DEC R0 DEC R1 ORL A,B JZ CMP7 JNB F0,CMP7 CPL C CMP7: RET