第一趟排序
以第一个数-2为标准
deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o testpx1 testpx1.s
deepfuture@deepfuture-laptop:~/private/mytest$ ./testpx1
-90
-2
4
5
432
3
deepfuture@deepfuture-laptop:~/private/mytest$
####################################### #program: liuxing 2010.09.25 # # deepfuture.iteye.com # ####################################### .section .data nums: .int -2,3,4,5,432,-90 gs: .ascii "%d\n" .section .bss .lcomm ni,4#int为32位,4个字节 .lcomm nj,4#int为32位,4个字节 .lcomm nsize,4#int为32位,4个字节,数组长度 .lcomm nx,4 .lcomm ncur,4 .section .text .globl main main: movl $gs,%ecx sub $nums,%ecx#得到元素总长度 sar $2,%ecx#带符号右移,不带符号为shr ,格式为:sar 右移位数,目标 #deepfuture.iteye.com 长度/4,得到元素个数 dec %ecx movl %ecx,nsize #nj初始化 movl %ecx,nj #ni初始化 movl $0,ni movl $0,ncur movl ni,%edx #初始化x,取第一个数 movl nums(,%edx,4),%ebx movl %ebx,nx ##################################################################### searchprev: movl nj,%ecx movl nx,%ebx #deepfuture.iteye.com 由后开始向前搜索 prevs: movl nums(,%ecx,4),%eax #快速排序 deepfuture.iteye.com cmp %ebx,%eax#%eax与%ebx比较,比如%eax比%ebx大 jge spnext#jge为有符号数,jae为无符号数,>= #%eax比%ebx小 xchg %ebx,%eax#交换值 movl %eax,nums(,%ecx,4) movl ncur,%edx movl %ebx,nums(,%edx,4) movl %ecx,ncur movl %ecx,nj movl nj,%edx cmp ni,%edx je fnumprint jmp searchnext #找到比x小的数 spnext: movl %ecx,nj movl nj,%edx cmp ni,%edx je fnumprint dec %ecx cmp $0,%ecx jge prevs#每次循环,%ecx减1,到0循环结束 searchnext: #deepfuture.iteye.com 由前开始向后搜索 movl ni,%ecx movl nx,%ebx nexts: inc %ecx#error过界 movl nums(,%ecx,4),%eax cmp %ebx,%eax jle snnext#jle,<= #%eax比%ebx大 xchg %ebx,%eax#交换值 movl %eax,nums(,%ecx,4) movl ncur,%edx movl %ebx,nums(,%edx,4) movl %ecx,ncur movl %ecx,ni movl nj,%edx cmp ni,%edx je fnumprint jmp searchprev #找到比x大的数 snnext: movl %ecx,ni movl nj,%edx cmp ni,%edx je fnumprint cmp nsize,%ecx jle nexts ################################################################################ fnumprint: movl $0,ncur loopnext: movl ncur,%edi movl nums(,%edi,4),%edx push %edx push $gs call printf movl ncur,%edi inc %edi movl %edi,ncur cmp nsize,%edi jle loopnext push $0 call exit