没事情。。把今天实验搞定的冒泡法排序汇编程序晒晒好了

;对string字符串中的字符进行冒泡法排序
;BY 方剑冰 2009-5-9

data segment      
    
 string db "ecdab$"
 length equ $-string
 infor db "result:$"

data ends
 
code segment
 main proc far
 ASSUME CS:CODE,DS:DATA
START:
 PUSH DS
 sub ax,ax
 sub cx,cx
 push ax
 mov ax,data
 MOV DS,AX
 mov SI,00H
 MOV cl,LENGTH  
 
 ;打印排列前结果
 lea dx,string         
 mov ah,09h
 int 21h       
 call crlf
   
              
 dec cl
 cmp cl,0
 JE EXIT 
 
 dec cl
 
;=======================
;第一层循环 
ACTION1:
 CMP cl,0    
 JE exit               
 mov ch,0
 mov SI,00h
 
    ;=======================     
    ;第二层循环     
    ACTION2:
       ;mov ch,0
       CMP ch,cl  
    JE  NEXT  
   
    
       mov bl,string[SI]
       INC SI
       cmp bl,string[SI]
       jg  swap
    return:         
       INC ch
       jmp action2
    ;=======================          
   
NEXT:
 DEC cl
 jmp action1   
;=======================
 
swap:
    mov bh,string[SI]
    mov string[SI],bl    
    DEC SI
    mov string[SI],bh
    INC SI
    jmp return

EXIT:
    ;打印提示信息
 lea dx,infor
 mov ah,09h
 int 21h                           
 call crlf    
        
 ;打印出排列后的结果
 lea dx,string   
 mov ah,09h
 int 21h
 call crlf
    ;将控制权交还操作系统
 mov ah,4ch 
 int 21h
 
main endp    
 
crlf proc near 
 ;回车换行
 
 mov dl,0dh
 mov ah,02h
 int 21h
 
 mov dl,0ah
 mov ah,02h
 int 21h
 ret
crlf endp
code ends
 end start
                                                 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值