Skip to content

Instantly share code, notes, and snippets.

@aldoea
Created July 11, 2019 03:19
Show Gist options
  • Save aldoea/9faed2dcebf0bad8bc9ec3c78bf4e0cb to your computer and use it in GitHub Desktop.
Save aldoea/9faed2dcebf0bad8bc9ec3c78bf4e0cb to your computer and use it in GitHub Desktop.
Bubble sort macro assembly
MPRINTARR MACRO
mov ecx, lengthArr
mov esi, OFFSET milista
PRINTLOOP:
mov eax, [esi]
call WriteDec
mWrite " "
add esi,4
LOOP PRINTLOOP
Call Crlf
ENDM
Mburbuja MACRO
.data
milista DWORD 100, 10, 1, 20, 50 ,23, 62, 5, 2, 7, 11, 27, 66
lengthArr DWORD ?
.code
mov lengthArr, LENGTHOF milista
mov ecx, lengthArr
dec ecx
.WHILE ecx > 0
push ecx
mov esi, OFFSET milista
.WHILE ecx > 0
mov eax, [esi]
mov ebx, [esi+4]
.IF ebx < eax
xchg eax,[esi+4] ; intercambia el par
xchg ebx,[esi]
mov [esi+4], ebx
mov [esi],eax
.ENDIF
add esi,4
dec ecx
.ENDW
pop ecx
dec ecx
.ENDW
MPRINTARR
WAITUSER
ENDM
WAITUSER MACRO
Call Waitmsg
ENDM
CLEAR MACRO
Call Clrscr
ENDM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment