已知8031内部RAM60H~69H单元中,依次存放了FFH,99H,77H,CCH,33H,DDH,88H,BBH,44H,EEH,它们均为无符号数,编程将它们按递减次序排序,即最大数放在60H中,最小数放在69H中。
MOV R0, #9;
LOOP1:
MOV R2, #9;
MOV R1, #60H;
LOOP2:
MOV A, @R1;
INC R1;
CLR C;
SUBB A, @R1;
JC NEXT;
DJNZ R2, LOOP2;
DJNZ R0, LOOP1;
SJMP $;
NEXT:
MOV A, @R1;
DEC R1;
XCH A, @R1;
INC R1;
XCH A, @R1;
DJNZ R2, LOOP2;
DJNZ R0, LOOP1;
SJMP $;
通过内外两个循环,比较相邻两数大小,采取相应操作。