Since _partition is only used locally, it could be given a non-mangled name and parameters passed directly in the registers, rather than using the stack.
#EMU8086 QUICKSORT FULL#
This will make the second call work on the wrong bounds, resulting in either a longer execution (by sorting a larger area than necessary) or incorrect results (if the full area isn't sorted). Which leads to my next point: when you make your recursive _quickSort calls, you assume that the value in EAX will not change during the first call, but it can since you're not saving and restoring the value during the call. So just use ECX as the count, and EAX to cycle temporary values thru. You're using EAX as a count, but you start it off by copying the value from ECX. In your "swap" code, this would normally use EAX instead of ECX.
EAX is typically used as a temporary register or accumulator (so much so that some operations on it have shorter encodings than if those same operations are done with other registers). Your use of some of the registers is a bit atypical. This is just a review of the code I have not verified that the assembly code correctly implements the algorithm in the pseudocode. I took the advice given to me on my last post and loaded all function parameters into registers instead of reading and writing to memory over and over. This was the pseudocode I used: Partition(A, p, r) r ebp + 16 integer index to end of set up stack, save regs Entry: A ebp + 8 pointer to array to being sorted
Mov eax, ecx j (loop count) initialized to p Load function parameters into registers and initialize local variables Exit: the index of the pivot stored in set up stack, save regs
r ebp + 16 integer index to end of sub-array p ebp + 12 integer index to start of sub-array Entry: A ebp + 8 pointer to array being sorted An array of 25 random integers to be sorted This program implements the Quick Sort algorithm and sorts an array My task was to implement Quick Sort in assembly from pseudocode.