-
-
[旧帖]
[原创]一个快速排序的汇编语言实现
0.00雪花
-
发表于:
2012-6-7 21:08
1453
-
[旧帖] [原创]一个快速排序的汇编语言实现
0.00雪花
为了准备找工作,最近开始复习一些基础算法,昨天实现了堆排序,分别给出了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解题方法汇总!