首页
社区
课程
招聘
[旧帖] [原创]一个快速排序的汇编语言实现 0.00雪花
发表于: 2012-6-7 21:08 1453

[旧帖] [原创]一个快速排序的汇编语言实现 0.00雪花

2012-6-7 21:08
1453
为了准备找工作,最近开始复习一些基础算法,昨天实现了堆排序,分别给出了c语言和汇编的实现(大家可以翻看这几天的新人交流投稿)

今天放出的是快速排序的汇编语言实现,具体原理 网上到处都是,我也不献丑解释了,直接上代码

.386
.model flat, stdcall

include windows.inc
include user32.inc
include kernel32.inc

includelib kernel32.lib
includelib user32.lib
includelib msvcrt.lib

printf PROTO C :VARARG
getchar proto C

.data
array                        dd  4,1,3,2,16,9,10,14,8,7
szMessage                db "%d ",0

.code

start:
       
        mov eax, 10
        dec eax
       
        push eax
        push 0
        call QuickSort
       
        mov ebx, 0

        .while (ebx < 10)
                push array[ebx*4]
                push offset szMessage
                call printf
               
                inc ebx
        .endw
       
        call getchar
       
        invoke ExitProcess,0
       
        QuickSort proc i:SDWORD, len:SDWORD
        LOCAL j:SDWORD
       
        mov eax, i
        mov j, eax   ;j point to left
       
        dec eax
        mov i, eax  ;i point to left-1
       
        mov eax, len
        mov ecx, array[eax*4]  ; ecx point to last
       
       
        mov edi, len
       
        mov eax, len
        mov ebx, i
        inc ebx
       
        .if (ebx >= eax)
                ret
        .endif
       
        .while (j < edi)
       
                mov eax, j

                .if (array[eax*4] <= ecx)
                        mov ebx, array[eax*4]
                       
                        mov edx, i
                        inc edx
                       
                        mov esi, array[edx*4]
                       
                        mov array[edx*4], ebx
                        mov array[eax*4], esi
                       
                        inc i
                        inc j
                        .continue
                                       
                .endif
               
                .if        (array[eax*4] > ecx)
                        inc j
                        .continue
                       
                .endif
                       
        .endw
       
        inc i
        mov eax, i
       
        mov ebx, array[eax*4]
        mov array[eax*4], ecx
       
        mov eax, len
        mov array[eax*4], ebx
       
        dec i
       
       
                push i
                push 0
                call QuickSort

                mov ebx, i
                add ebx, 2
                push len
                push ebx
                call QuickSort
       
        ret
       

QuickSort endp

end start

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 2307
活跃值: (983)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
2
这个...
BubbleSort.asm
InsertSort.asm
QuickSort.asm
SelectionSort.asm
ShellSort.asm

arr_1.rar
上传的附件:
2012-6-7 21:29
0
雪    币: 61
活跃值: (70)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
3
多谢分享,我会对照,查找自己的不足,不过依旧会按照自己的理解,重现一遍所有排序,加强理解
2012-6-7 22:53
0
游客
登录 | 注册 方可回帖
返回
//