Skip to content

Instantly share code, notes, and snippets.



Created Nov 15, 2015
What would you like to do?
Bubble sort in 16 bytes of x86 assembly language
;; The "worlds smallest" bubble sort (16 bytes)
;; Copyright (c) 1998 by Joergen Ibsen / Jibz
;; All Rights Reserved
bits 32
section .text
; enter: edi -> array
; ecx = #elements - 1
; exit: edi -> array
; ecx = 0
; modify: ecx
pusha ; save edi and ecx
mov esi, edi
cmp eax, [esi] ; do we need to swap?
jge short .order_ok
xchg eax, [esi] ; if so, this is first step
stosd ; second step, or just write back eax
loop .innerloop
popa ; pop edi and ecx
loop .outerloop ; ecx is used for both loops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.