Skip to content

Instantly share code, notes, and snippets.

@evantravers
Created April 8, 2010 02:38
Show Gist options
  • Save evantravers/359714 to your computer and use it in GitHub Desktop.
Save evantravers/359714 to your computer and use it in GitHub Desktop.
; Author: E. Travers
; Date: 3/2010
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
thearray DWORD 100 DUP (?)
prompt1 BYTE "Enter a number to add to the sort: ", 0
resultLbl BYTE "123",0
string BYTE 20 DUP (?)
numElemx DWORD 0
painLbl BYTE "freakin asm",0
.CODE
_MainProc PROC
mov eax, 0
mov ebx, 0
mov ecx, 0
mov edx, 0
inputLoop:
; get input, stop when you see a zero
input prompt1, string, 40 ; read ASCII characters
atod string
cmp eax, 0
je outLoopx
; if not zero, then add to the array
mov thearray[4*ecx], eax
inc ecx
cmp ecx,100
jne inputLoop
mov numElemx, ecx
jmp outputLoopx
outLoopx:
; now sort the array
; for every item in the array in reverse order
outerLoopx:
mov edx, 0
innerLoopx:
; take each item, compare it to 0 increasing, stop when you find it bigger than the previous
; take the current item
mov eax, thearray[4*ecx]
; take the next item
mov ebx, thearray+4[4*ecx]
cmp eax, ebx
jnl swapSkipx
; swap
mov thearray+4[4*ecx], eax
mov thearray[4*ecx], ebx
swapSkipx:
inc edx;
sub ecx, edx
jnz innerLoopx
loop outerLoopx
mov ecx, numElemx
outputLoopx:
dtoa string, thearray[(4*ecx)-4]
output resultLbl, string
loop outputLoopx
ret
painintheass:
output painLbl, painLbl
ret
_MainProc ENDP
END ; end of source code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment