flat assembler
Message board for the users of flat assembler.
Index
> Windows > bubble sort in fasm |
Author |
|
david botero 10 Feb 2005, 22:03
Does anybody have the code for the bubble sort in fasm?
|
|||
10 Feb 2005, 22:03 |
|
Matrix 13 Feb 2005, 17:37
Hello,
i think someone may find this useful, it whould be a little more complicated to make this little mod with a quicksort Code: org 100h arraysize=10 ;mov edi,a mov ecx,arraysize ;call bubblesort ;call seebubblesort mov edi,a2 call bubblesort64 ; dd index, dd pointer mov cx,arraysize*2 mov si,a2 call writea int 20h; ;You end up with {1,1,2,3,3,3,4,5,5,5,6,7,8,9,9,9} in a writea: ; si=dword string cx=elements dec cx .loop: lodsd mov ah,$e add al,'0' int 10h mov al,',' int 10h loop .loop lodsd mov ah,$e add al,'0' int 10h bendline: mov ax,$e0d int 10h mov ax,$e0a int 10h ;ret ret ; ; bubble sort ; input: edi = pointer to array, ecx = number of indexes ; output: edi = pointer to sorted array ; destroys: eax, edx, eflags ; seebubblesort: pusha mov cx,arraysize mov si,a call writea popa lea ebx,[edi+ecx*4] mov eax,[edi] .cmploop:sub ebx,4 cmp eax,[ebx] jae .again xchg eax,[ebx] .again: cmp ebx,edi jnz .cmploop stosd loop seebubblesort ret bubblesort: lea ebx,[edi+ecx*4] mov eax,[edi] .cmploop:sub ebx,4 cmp eax,[ebx] jle .again xchg eax,[ebx] .again: cmp ebx,edi jnz .cmploop stosd loop bubblesort ret bubblesort64: ; dd index, dd pointer pusha mov cx,arraysize*2 mov si,a2 call writea popa lea ebx,[edi+ecx*8] mov eax,[edi] .cmploop:sub ebx,8 cmp eax,[ebx] jle .again xchg eax,[ebx] push dword [ebx+4] dword [edi+4] pop dword [ebx+4] dword [edi+4] .again: cmp ebx,edi jnz .cmploop stosd add edi,4 loop bubblesort64 ret a dd 9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0 ;20 a2 dd 9,0,8,1,7,2,6,3,5,4,4,5,3,6,2,7,1,8,0,9, 9,0,8,1,7,2,6,3,5,4,4,5,3,6,2,7,1,8,0,9 ;20 ( the array sorter drags the idexes with the pointers, pointers to anything, hint: filenames ) |
|||
13 Feb 2005, 17:37 |
|
Nikolay Petrov 17 Mar 2005, 19:14
but qsort is better
|
|||||||||||
17 Mar 2005, 19:14 |
|
mike.dld 17 Mar 2005, 22:27
|
|||
17 Mar 2005, 22:27 |
|
at0mic 18 Mar 2005, 14:27
when the sortengine input values have the same size or lenght its not so hard to code something but
if you will code engine that can sort zero terminated string(different data size) or data with specified data size which is not multiple dd but multiple bits size then the isue will be more complicated. the curious task is to build an array with strings null terminated when all chars are packet to 5 bits size so the next font has 3 bits in the same byte just like the previous font. Zero mark is also 5 bit lenght. So there is no byte alignment or any other alignment. Yes, I hear you think: This is easy because we can unpack the array to another one with byte alignment.So do it and test yourself. best regards _________________ at0mic! |
|||
18 Mar 2005, 14:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.