I am implementing Bubble Sort in assembly with the basic pseudocode / outline:
for i in array
if array[i] >= array[i+1]
exchange array[i], array[i+1]
My ASM code:
BubbleSort PROC
mov EBX, LENGTHOF myArr
.REPEAT
mov ESI, 0
mov ECX, LENGTHOF myArr
.REPEAT
mov EAX, [myArr + ESI]
.IF EAX >= [myArr + ESI + TYPE myArr] ; If (myArr[i] < myArr[i + 1])
xchg EAX, [myArr + ESI + TYPE myArr]
mov [myArr + ESI], EAX
.ENDIF
add ESI, TYPE myArr
dec ECX
.UNTIL ECX == 0
dec EBX
.UNTIL EBX == 0
ret
BubbleSort ENDP
When I showed my implementation to my professor, he said that it was "kind of" like bubble sort or a "type of" bubble sort. When telling us about the assignment he said we should start from the back of the array, and move back-to-front. Yet I am starting from the front and moving front-to-back.
I feel that I'm on the right track and the code works but I want to do it correctly.
Does anyone see where I am messing up?