3种排序算法插入排序
Insert proc pChar:BYTE
pushad
xor ebx,ebx
xor ecx,ecx
xor edi,edi
xor esi,esi
xor edx,edx
mov eax,[ebp+8]
push eax
@l1:
mov bl,[eax]
cmp bl,0h
je @tl
inc ecx
inc eax
jmp @l1
@tl:
pop eax
@l2:
inc ebx
cmp ebx,ecx
jge @l5
mov dl,[eax+ebx]
mov esi,ebx
dec esi
@l3:
cmp [eax+esi],dl
jle @l4
push ebx
mov bl,[eax+esi]
mov [eax+esi+1],bl
dec esi
pop ebx
jmp @l3
@l4:
mov [eax+esi+1],dl
jmp @l2
@l5:
popad
ret
Insert endp
选择排序
Choose proc pChar:BYTE
pushad
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
xor edi,edi
xor esi,esi
mov eax,[ebp+8]
push eax
@l1:
mov bl,[eax]
cmp bl,0h
je @tl1
inc eax
inc ecx
jmp @l1
@tl1:
pop eax
@l2:
cmp edx,ecx
jge @exit
mov esi,edx
mov edi,edx
@ll1:
inc edi
cmp edi,ecx
jge @l3
mov bl,[eax+esi]
cmp [eax+edi],bl
jge @ll
xchg edi,esi
inc edi
@ll:
jmp @ll1
@l3:
cmp esi,edx
je @l4
push ebx
mov bl,[eax+edx]
mov bh,[eax+esi]
mov [eax+edx],bh
mov [eax+esi],bl
pop ebx
@l4:
inc edx
jmp @l2
@exit:
popad
ret
Choose endp
冒泡排序
Bubble proc pChar:BYTE
pushad
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
xor edi,edi
xor esi,esi
mov eax,[ebp+8]
push eax
@l1:
mov bl,[eax]
cmp bl,0h
je @tl1
inc eax
inc ecx
jmp @l1
@tl1:
pop eax
dec ecx
@l2:
cmp edx,ecx
jge @exit
xor esi,esi
xor edi,edi
@l3:
push ebx
mov ebx,ecx
sub ebx,edx
cmp edi,ebx
pop ebx
jge @l5
mov bl,[eax+edi+1]
cmp bl,[eax+edi]
jge @l4
mov bh,[eax+edi]
mov [eax+edi+1],bh
mov [eax+edi],bl
mov esi,1h
@l4:
inc edi
jmp @l3
@l5:
cmp esi,0h
jne @l6
jmp @exit
@l6:
inc edx
jmp @l2
@exit:
popad
ret
Bubble endp
END START
用法示范:
.386
.Model Flat, StdCall
Option Casemap :None
Include windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.inc
includelib gdi32.lib
IncludeLib user32.lib
IncludeLib kernel32.lib
include macro.asm
.DATA
lpMsg db "Example",0
.CODE
START:
push 0
call GetModuleHandle
lea eax,lpMsg
push eax
call Bubble
;call Insert
push 0
lea eax,lpMsg
push eax
lea eax,lpMsg
push eax
push 0
call MessageBox
push 0
call ExitProcess
[课程]Linux pwn 探索篇!