日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

C指针原理(22)-C指针基础-att汇编-快速排序

發(fā)布時(shí)間:2025/3/12 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C指针原理(22)-C指针基础-att汇编-快速排序 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

第一趟排序

以第一個(gè)數(shù)-2為標(biāo)準(zhǔn)

xxx@xxx-laptop:~/private/mytest$ gcc -o testpx1 testpx1.s

xxx@xxx-laptop:~/private/mytest$ ./testpx1

-90

-2

4

5

432

3

xxx@xxx-laptop:~/private/mytest$

####################################### #program: 2010.09.25 # # # ####################################### .section .datanums:.int -2,3,4,5,432,-90gs:.ascii "%d\n" .section .bss.lcomm ni,4#int為32位,4個(gè)字節(jié).lcomm nj,4#int為32位,4個(gè)字節(jié) .lcomm nsize,4#int為32位,4個(gè)字節(jié),數(shù)組長(zhǎng)度 .lcomm nx,4 .lcomm ncur,4 .section .text.globl mainmain:movl $gs,%ecxsub $nums,%ecx#得到元素總長(zhǎng)度sar $2,%ecx#帶符號(hào)右移,不帶符號(hào)為shr ,格式為:sar 右移位數(shù),目標(biāo)#xxx.iteye.com 長(zhǎng)度/4,得到元素個(gè)數(shù)dec %ecxmovl %ecx,nsize#nj初始化movl %ecx,nj#ni初始化movl $0,nimovl $0,ncurmovl ni,%edx#初始化x,取第一個(gè)數(shù)movl nums(,%edx,4),%ebx movl %ebx,nx#####################################################################searchprev:movl nj,%ecxmovl nx,%ebx #xxx.iteye.com 由后開始向前搜索 prevs:movl nums(,%ecx,4),%eax#快速排序 xxx.iteye.com cmp %ebx,%eax#%eax與%ebx比較,比如%eax比%ebx大jge spnext#jge為有符號(hào)數(shù),jae為無(wú)符號(hào)數(shù),>=#%eax比%ebx小xchg %ebx,%eax#交換值movl %eax,nums(,%ecx,4)movl ncur,%edx movl %ebx,nums(,%edx,4)movl %ecx,ncurmovl %ecx,njmovl nj,%edxcmp ni,%edx je fnumprint jmp searchnext #找到比x小的數(shù) spnext: movl %ecx,njmovl nj,%edxcmp ni,%edx je fnumprint dec %ecx cmp $0,%ecx jge prevs#每次循環(huán),%ecx減1,到0循環(huán)結(jié)束 searchnext:#xxx.iteye.com 由前開始向后搜索 movl ni,%ecx movl nx,%ebx nexts: inc %ecx#error過(guò)界movl nums(,%ecx,4),%eaxcmp %ebx,%eaxjle 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,%edxcmp ni,%edx je fnumprintjmp searchprev #找到比x大的數(shù) snnext: movl %ecx,ni movl nj,%edxcmp ni,%edx je fnumprintcmp nsize,%ecxjle nexts################################################################################ fnumprint:movl $0,ncur loopnext: movl ncur,%edi movl nums(,%edi,4),%edx push %edxpush $gs call printfmovl ncur,%ediinc %edimovl %edi,ncur cmp nsize,%edi jle loopnext push $0call exit####################################### #program: 2010.09.27 # # # # 快速排序-匯編 # ####################################### .section .datanums:.int 2,2,3,4,1,3,1,-11,98,-22,22gs:.ascii "%d\n" .section .bss.lcomm ni,4#int為32位,4個(gè)字節(jié).lcomm nj,4#int為32位,4個(gè)字節(jié) .lcomm nsize,4#int為32位,4個(gè)字節(jié),數(shù)組長(zhǎng)度 .lcomm nx,4 .lcomm ncur,4 .lcomm oldni,4#int為32位,4個(gè)字節(jié).lcomm oldnj,4#int為32位,4個(gè)字節(jié) .lcomm oldnsize,4#int為32位,4個(gè)字節(jié),數(shù)組長(zhǎng)度.lcomm count,4 .section .text.globl mainmain:movl $gs,%ecxsub $nums,%ecx#得到元素總長(zhǎng)度sar $2,%ecx#帶符號(hào)右移,不帶符號(hào)為shr ,格式為:sar 右移位數(shù),目標(biāo)#xxx.iteye.com 長(zhǎng)度/4,得到元素個(gè)數(shù)dec %ecxmovl %ecx,nsize#xxx.iteye.com #nj初始化movl %ecx,nj#ni初始化movl $0,nimovl $0,ncurmovl ni,%edxmovl $1,count#初始化x,取第一個(gè)數(shù)movl nums(,%edx,4),%ebxmovl %ebx,nxpush ncurpush nipush njpush nx######################beginsearch: pop nx pop njpop nipop ncur#xxx.iteye.com movl ni,%eaxmovl %eax,oldnimovl nj,%eaxmovl %eax,oldnj#xxx.iteye.com subl $1,count#####################################################################searchprev:movl nj,%ecxmovl nx,%ebx #xxx.iteye.com 由后開始向前搜索 prevs:movl nums(,%ecx,4),%eax#快速排序 xxx.iteye.com cmp %ebx,%eax#%eax與%ebx比較,比如%eax比%ebx大jge spnext#jge為有符號(hào)數(shù),jae為無(wú)符號(hào)數(shù),>=#%eax比%ebx小xchg %ebx,%eax#交換值movl %eax,nums(,%ecx,4)movl ncur,%edx movl %ebx,nums(,%edx,4)movl %ecx,ncurmovl %ecx,nj#xxx.iteye.com movl nj,%edxcmp ni,%edx je fnumend jmp searchnext #找到比x小的數(shù) spnext: movl %ecx,njmovl nj,%edxcmp ni,%edx je fnumend dec %ecx cmp $0,%ecx jge prevs#每次循環(huán),%ecx減1,到0循環(huán)結(jié)束searchnext:#xxx.iteye.com 由前開始向后搜索 movl ni,%ecx movl nx,%ebx nexts: inc %ecx#error過(guò)界movl nums(,%ecx,4),%eaxcmp %ebx,%eaxjle 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,%edxcmp ni,%edx je fnumend#xxx.iteye.com jmp searchprev #找到比x大的數(shù) snnext: movl %ecx,ni movl nj,%edxcmp ni,%edx je fnumendcmp oldnj,%ecxjle nexts################################################################################ fnumend:#遞歸搜索####################rightrights:movl ncur,%ebxmovl oldnj,%eaxsubl %ebx,%eax#(oldnj-ncur)->%eaxcmp $1,%eaxjle lefts#(oldnj-ncur)<=1,左邊只有一個(gè)元素,已經(jīng)處理完,不需要遞歸 #xxx.iteye.com movl ncur,%eax inc %eax push %eax#ncurpush %eax#nimovl %eax,%edx push oldnj#nj#xxx.iteye.com movl nums(,%edx,4),%eaxpush %eax#nxaddl $1,count####################leftlefts:movl ncur,%eaxmovl oldni,%ebxsubl %ebx,%eax#(ncur-oldni)->%eaxcmp $1,%eaxjle nextsearch#(ncur-oldni)<=1,右邊只有一個(gè)元素,已經(jīng)處理完,不需要遞歸 push oldni#ncurpush oldni#ni#xxx.iteye.com movl ncur,%eaxdec %eaxpush %eax#njmovl oldni,%edxmovl nums(,%edx,4),%eaxpush %eax#nxaddl $1,count ###################nextsearch:cmp $0,countjg beginsearch ################################################################################ fnumprint:movl $0,ncur loopnext: movl ncur,%edi movl nums(,%edi,4),%edx push %edxpush $gs call printfmovl ncur,%ediinc %edimovl %edi,ncur cmp nsize,%edi jle loopnext push $0call exitxxx@xxx-laptop:~/private/mytest$ gcc -o testpx testpx.sbr/>xxx@xxx-laptop:~/private/mytest$ ./testpx

-22
-11
1
1
2
2
3
3
4
22
98

總結(jié)

以上是生活随笔為你收集整理的C指针原理(22)-C指针基础-att汇编-快速排序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。