- 冒泡排序
- 结果存在RAM的0x46~0x55,由大到小
- 16个数无符号号数
- R2,R3遍历计数,R4存放左边的数,R1存放右边的数,R0暂存R4或R1的地址
一、代码
;this is max sort,no optimizing
;the data is unsigned num
;the num is from 46h~55h
ORG 0000h
Table:DB 64,118,66,78,79,86,36,20,42,123,28,114,16,14,43,9
MOV DPTR,#Table
ORG 0010h
MOV SP,#45h
MOV R4,#00h
MOV R3,#00h ;left num
MOV R2,#00h ;bianli
MOV R1,#00h ;right num
MOV R0,#00h
LOOP:
MOV A,R2
MOVC A,@A+DPTR
PUSH ACC
INC R2
CJNE R2,#10h,LOOP
MOV R2,#00h
MOV SP,#45h
LOOP1: ;R4->left,R1->right
MOV A,R2
ADD A,#46h
MOV R0,A
MOV A,@R0 ;must through R0
MOV R4,A
INC R2
MOV A,R2
ADD A,#46h
MOV R0,A
MOV A,@R0
MOV R1,A
SUBB A,R4
JNC LOOP2;CY=0,jump R1>R4(right>left)
CJNE R2,#10h,LOOP1
CJNE R3,#0fh,LOOP3
LOOP2: ;exchange
DEC R0
DEC R0
MOV SP,R0 ;sp->R4-1,
MOV A,R1
PUSH ACC
MOV A,R4
PUSH ACC
CJNE R2,#0fh,LOOP1
SJMP LOOP3
LOOP3:
MOV R2,#00h
INC R3
CJNE R3,#0fh,LOOP1
END
二、运行结果
需要排序的16个数:
排序后结果: