第一趟排序

以第一个数-2为标准

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个字节.lcomm nj,4#int为32位,4个字节  .lcomm nsize,4#int为32位,4个字节,数组长度 .lcomm nx,4 .lcomm ncur,4
.section   .text.globl mainmain:movl $gs,%ecxsub $nums,%ecx#得到元素总长度sar  $2,%ecx#带符号右移,不带符号为shr ,格式为:sar 右移位数,目标#xxx.iteye.com    长度/4,得到元素个数dec %ecxmovl  %ecx,nsize#nj初始化movl %ecx,nj#ni初始化movl $0,nimovl $0,ncurmovl ni,%edx#初始化x,取第一个数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为有符号数,jae为无符号数,>=#%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小的数                   spnext: movl %ecx,njmovl nj,%edxcmp ni,%edx  je fnumprint           dec %ecx cmp $0,%ecx             jge prevs#每次循环,%ecx减1,到0循环结束 searchnext:#xxx.iteye.com    由前开始向后搜索 movl ni,%ecx  movl nx,%ebx                   nexts:        inc %ecx#error过界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大的数    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个字节.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 mainmain:movl $gs,%ecxsub $nums,%ecx#得到元素总长度sar  $2,%ecx#带符号右移,不带符号为shr ,格式为:sar 右移位数,目标#xxx.iteye.com    长度/4,得到元素个数dec %ecxmovl  %ecx,nsize#xxx.iteye.com   #nj初始化movl %ecx,nj#ni初始化movl $0,nimovl $0,ncurmovl ni,%edxmovl $1,count#初始化x,取第一个数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为有符号数,jae为无符号数,>=#%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小的数                   spnext: movl %ecx,njmovl nj,%edxcmp ni,%edx  je fnumend           dec %ecx cmp $0,%ecx             jge prevs#每次循环,%ecx减1,到0循环结束searchnext:#xxx.iteye.com    由前开始向后搜索 movl ni,%ecx  movl nx,%ebx                   nexts:        inc %ecx#error过界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大的数    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,左边只有一个元素,已经处理完,不需要递归 #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,右边只有一个元素,已经处理完,不需要递归              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

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

  1. C指针原理(15)-C指针基础

    简单C指针 指向整数的指针,以及指针的指针 myhaspl@myhaspl:~ % vim test1.c#include <stdio.h>int main(void){int x;x= ...

  2. C指针原理(21)-C指针基础-ATT汇编

    helloworld-高级版 .section .data#初始化的变量 output:.ascii "hello,world\n"#要打印的字符串,.data为初始化值的变量.o ...

  3. C指针原理(24)-C指针基础

    取自netbsd中的源码,检查运算溢出,用C语言实现,方法很精妙 /* hide bintime for _STANDALONE because this header is used for hpc ...

  4. C指针原理(17)-C指针基础

    指针本身也是一种变量,支持常用的运算.比如加.减 #include <stdio.h>int main(void){int i;char x[20]="0123456789ABC ...

  5. C指针原理(16)-C指针基础

    2.指向数组的指针 #include <stdio.h>int main(void){int i;char x[20]="0123456789ABCDEFGHIJ";f ...

  6. C指针原理(13)-C指针基础

    规范路径格式,win32(windows环境下,路径之间的各个目录分隔将"\"改为"/",用"/"分隔,这样的好处是在UNIX和WINDOW ...

  7. C指针原理(14)-C指针基础

    make与makefile make是一个工具程序(Utility software),经由读取叫做"makefile"的文件,自动化建构软件.它是一种转化文件形式的工具,转换的目 ...

  8. C指针原理(12)-C指针基础

    tcctok.h定义了C语言的词法分析的基本元素,主要定义了关键字. / keywords /DEF(TOK_INT, "int")DEF(TOK_VOID, "void ...

  9. C指针原理(19)-C指针基础

    不用下标,直接引用多维数组名时,多维数组名代表一个指针变量,这个指针变量指向是最后一维长度的数组的指针,假设x是一个2*5的数组,定义为: int x[2][5] 直接引用x,不使用任何下标,此时x代 ...

最新文章

  1. 2021年大数据HBase(十二):Apache Phoenix 二级索引
  2. python编程面试题
  3. 表的字段中的值需要替换怎么办?【if 函数,case when函数,中间表思路】
  4. es最新的集群选举策略
  5. plsql连接oracle11g怎么配置,怎么使用plsql怎么连接64位Oracle11g数据库?
  6. 那些和闰年相关的 Bug
  7. 小白如何写Python算法-计算模型稳定性评估指标PSI
  8. python卸载_如何为Python程序制作Windows安装包?
  9. 参数编码 完全解决方案 (转)
  10. html 中shadow DOM 的使用
  11. power iso linux启动盘,怎么用poweriso制作u盘启动盘win10_poweriso制作u盘启动盘win10详细步骤...
  12. 用C 程序理解汉字的机内码表示
  13. MATLAB:图像水平、垂直、水平垂直镜像、转置、旋转变换(flipdim、mirror、transp、imrotate函数)...
  14. 支持自动识别快递公司批量查询物流、一键导出
  15. 犀牛云企业云网站:当我们在谈论网站建设的时候,我们在谈论什么?
  16. MBA书籍推荐:打造商业思维,看这一本书就够了
  17. python自动控制程序_使用 Python 自动执行 ANSYS APDL
  18. 互联网巨头常用词汇大全 每一个词都在改变世界
  19. 物联网平台搭建的全过程介绍(五)——基于阿里云物联网平台的Android聊天app源码
  20. Harris角点及Shi-Tomasi角点检测

热门文章

  1. [bzoj3926][Zjoi2015]诸神眷顾的幻想乡
  2. tomcat7.0配置CORS(跨域资源共享)
  3. DNS区域传送、子域授权
  4. JavaScript -- 时光流逝(三):js中的 String 对象的方法
  5. python flask 学习与实战
  6. oracle建job
  7. Python+selenium环境搭建
  8. CTO 比普通程序员强在哪?
  9. Delphi实现类似Android锁屏的密码锁控件
  10. 三行代码实现快速排序