汇编选择排序

 1 dseg segment
 2         source_data dw ?,-1,3,6,1,5
 3         count equ $-source_data
 4 dseg ends
 5 cseg segment
 6         assume cs:cseg , ds:dseg
 7 start:       
 8         mov ax , dseg
 9         mov ds , ax
10 
11         mov bx , count     ;外循环指针
12         sub bx ,2
13 
14 next_loop:
15         mov ax , [bx]
16         mov di , bx        ;mark
17         mov si , bx        ;内循环指针
18         sub si , 2
19         jz  next_label
20 find_next:
21         mov dx , [si]
22         cmp dx , ax
23         jge next
24         mov ax , [si]
25         mov di , si
26 next:   sub si , 2
27         jnz find_next 
28         cmp di , bx
29         je  next_label
30         mov ax , [bx]
31         mov dx , [di]
32         xchg ax , dx
33         mov [bx] , ax
34         mov [di] , dx
35 next_label:
36         sub bx , 2
37         jnz next_loop
38         
39         mov ax , 4c00h                  
40         int 21h 
41 
42 cseg ends
43 end  start

 

posted on 2015-01-01 14:27  Karma_wjc  阅读(661)  评论(0编辑  收藏  举报