Created
November 8, 2015 18:57
-
-
Save xavery/8b533810da28b59533f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bits 64 | |
global bubblesort | |
; void bubblesort(int *data [rdi], size_t size [rsi]) | |
bubblesort: | |
sub rsi, 1 ; make sure we don't overrun (element+1 is accessed inside the loop) | |
.loop1: | |
xor ecx, ecx ; index for .loop2 | |
xor eax, eax ; are we done yet? | |
.loop2: | |
mov edx, [rdi + rcx * 4] | |
mov r8d, [rdi + rcx * 4 + 4] | |
cmp edx, r8d | |
jle .loop2_end ; edx <= r8d -> nothing to do | |
; else swap | |
mov [rdi + rcx * 4 + 4], edx | |
mov [rdi + rcx * 4], r8d | |
mov eax, 1 ; swapped | |
.loop2_end: | |
add rcx, 1 | |
cmp rcx, rsi | |
jl .loop2 | |
.loop1_end: | |
test eax, eax | |
jnz .loop1 | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment