.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
.data
ArrayA dword 3,1,7,5,2
szCaption db 'MessageBox',0
szText db 100 dup(0)
szCharsFormat db 'After Bubble Sort : ArrayA :%d,%d,%d,%d,%d',0
.code
BubbleSort proc uses eax ecx esi,
pArray:ptr dword,
Count:dword
local @exchange:dword
mov ecx,Count
dec ecx
mov @exchange,0
L1:
push ecx
mov esi,pArray
mov @exchange,0
L2:
mov eax,[esi]
cmp [esi+4],eax
jge L3
xchg eax,[esi+4]
mov [esi],eax
mov @exchange,1
L3:
add esi,4
loop L2
cmp @exchange,0
je L4
pop ecx
loop L1
L4:ret
BubbleSort endp
start:
invoke BubbleSort,addr ArrayA,5
invoke wsprintf,addr szText,addr szCharsFormat,ArrayA,ArrayA+4,ArrayA+8,\
ArrayA+12,ArrayA+16
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK
invoke ExitProcess,NULL
end start
D:\programming\assembler>ml /IE:\masm32\include bubbleSort.asm /c
Microsoft (R) Macro Assembler Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: bubbleSort.asm
***********
ASCII build
***********
D:\programming\assembler>link /subsystem:windows bubbleSort.obj
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.