Created
June 3, 2017 18:54
-
-
Save stephenpaulger/d80a423959f27d6c0f9a64af4f3bb46c to your computer and use it in GitHub Desktop.
Assembler simulator bubble sort
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
; Runs on https://schweigi.github.io/assembler-simulator/ | |
; https://en.wikipedia.org/wiki/Bubble_sort | |
MOV C, data ; C tracks the address of end | |
ADD C, 16 ; of the unsorted section of data. | |
start: | |
DEC C ; One byte is sorted each pass | |
MOV D, data ; Start of the data | |
bubble: | |
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 | |
noswap: | |
INC D ; Move along the data one byte | |
CMP D, C | |
JB bubble ; loop if there's more unsorted data | |
CMP C, data | |
JNB start ; start again unless we've sorted all values. | |
HLT | |
DB "_______" ; Align the sorted data nicely. | |
data: | |
DB "QWERTYUIOPASDFGH" ; 16 characters to sort. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment