linux-アセンブリ-クイックソート(2)

5460 ワード

#######################################
#program:  liuxing     2010.09.27     # 
#          deepfuture.iteye.com     #
#               -              # 
#######################################
.section .data
   nums:
     .int 2,2,3,4,1,3,1,-11,98,-22,22
   gs:
   .ascii "%d
" .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 .lcomm oldni,4#int 32 ,4 .lcomm oldnj,4#int 32 ,4 .lcomm oldnsize,4#int 32 ,4 , .lcomm count,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 #deepfuture.iteye.com #nj movl %ecx,nj #ni movl $0,ni movl $0,ncur movl ni,%edx movl $1,count # x, movl nums(,%edx,4),%ebx movl %ebx,nx push ncur push ni push nj push nx ###################### beginsearch: pop nx pop nj pop ni pop ncur #deepfuture.iteye.com movl ni,%eax movl %eax,oldni movl nj,%eax movl %eax,oldnj #deepfuture.iteye.com subl $1,count ##################################################################### 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 #deepfuture.iteye.com movl nj,%edx cmp ni,%edx je fnumend jmp searchnext # x spnext: movl %ecx,nj movl nj,%edx cmp ni,%edx je fnumend 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 fnumend #deepfuture.iteye.com jmp searchprev # x snnext: movl %ecx,ni movl nj,%edx cmp ni,%edx je fnumend cmp oldnj,%ecx jle nexts ################################################################################ fnumend:# ################### #right rights: movl ncur,%ebx movl oldnj,%eax subl %ebx,%eax#(oldnj-ncur)->%eax cmp $1,%eax jle lefts#(oldnj-ncur)<=1, , , #deepfuture.iteye.com movl ncur,%eax inc %eax push %eax#ncur push %eax#ni movl %eax,%edx push oldnj#nj #deepfuture.iteye.com movl nums(,%edx,4),%eax push %eax#nx addl $1,count ################### #left lefts: movl ncur,%eax movl oldni,%ebx subl %ebx,%eax#(ncur-oldni)->%eax cmp $1,%eax jle nextsearch#(ncur-oldni)<=1, , , push oldni#ncur push oldni#ni #deepfuture.iteye.com movl ncur,%eax dec %eax push %eax#nj movl oldni,%edx movl nums(,%edx,4),%eax push %eax#nx addl $1,count ################### nextsearch: cmp $0,count jg beginsearch ################################################################################ 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

 deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o testpx testpx.sdeepfuture@deepfuture-laptop:~/private/mytest$ ./testpx-22-1111223342298deepfuture@deepfuture-laptop:~/private/mytest$