Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2017 18:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Assembler simulator bubble sort
; Runs on
MOV C, data ; C tracks the address of end
ADD C, 16 ; of the unsorted section of data.
DEC C ; One byte is sorted each pass
MOV D, data ; Start of the data
MOV A, [D]
CMP A, [D+1] ; Compare two adjacent values
JNA noswap ; jump if the don't need swapping
MOV B, [D+1] ; swap the two values
MOV [D+1], A
MOV [D], B
INC D ; Move along the data one byte
JB bubble ; loop if there's more unsorted data
CMP C, data
JNB start ; start again unless we've sorted all values.
DB "_______" ; Align the sorted data nicely.
DB "QWERTYUIOPASDFGH" ; 16 characters to sort.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment