zoukankan      html  css  js  c++  java
  • 王晓博 2010.05.15-1 汇编 冒泡算法

    作者:2008级嵌入式  王晓博

    #将下面汇编代码保存为 wxb1.s 文件
    #功能:用冒泡算法去实现动一组数据的排列,然后输出

    .section .rodata
        output: .asciz "ni yao de shu shi %d "
                #.asciz是在定义字符串的时侯在字符串结尾加上空字符(即C语言
                #的),这样做的目的是为了让printf能读懂字符串

    .section .data
        msg: .long 55555555,33333,53,56,25,52,56,631,5667    #共有9个数

    .section .text
    .globl _start

    _start:
        movl $9,%ecx
        decl %ecx        #外循环开始
    cp1:
        movl $0,%eax
        pushl %ecx        #保存外循环的ecx值
    cp2:                  #内循环
        movl  msg(,%eax,4),%edx        #冒泡算法的开始 保持小数在前大数在后
        incl %eax
        cmpl %edx,msg(,%eax,4)     
     
        jae  next

        xchg  msg(,%eax,4),%edx         #不符合就进行交换
        decl %eax          
        movl %edx,msg(,%eax,4)
        incl %eax                

    next:
        loop cp2
        popl  %ecx
        loop cp1
        nop
        movl $0,%edi

    loop:                            #用于循环打印共进行9次
        movl msg(,%edi,4),%eax
        pushl %eax
        pushl $output
        call printf
        addl $8 ,%esp
        inc %edi
        cmpl $9,%edi
        jne loop

        movl $0, %ebx        #quit
        mov $1,%eax
        int $0x80


    [root@localhost ~]# as wxb1.s -o wxb1.o
    [root@localhost ~]# ld wxb1.o -lc -dynamic-linker /lib/ld-linux.so.2  -o wxb1
    [root@localhost ~]# ./wxb1
    ni yao de shu shi 25
    ni yao de shu shi 52
    ni yao de shu shi 53
    ni yao de shu shi 56
    ni yao de shu shi 56
    ni yao de shu shi 631
    ni yao de shu shi 5667
    ni yao de shu shi 33333
    ni yao de shu shi 55555555
    [root@localhost ~]#



  • 相关阅读:
    centos 7安装配置vsftpd
    lvs和haproxy机器必须注意的三个参数
    用python 脚本实现zabbix对java端口报警
    git的下载地址
    看的一篇很好的博客
    学习内容
    数组一些用法
    dom
    dom1
    for的基础
  • 原文地址:https://www.cnblogs.com/ztguang/p/12647851.html
Copyright © 2011-2022 走看看