rendered paste body/* quicksortA.s
* quick sort in pentium assembly
*
* void quicksortA(int a[], int first, int last)
*
* NAME: David Bell
* ebx = pivot
* ecx = tmp1
* edx = tmp2
* eax = a
* edi = i
* esi = pivotpos
*/
.globl quicksortA
quicksortA:
pushl %ebp /* create stack frame */
movl %esp, %ebp
pushl %ebx /* save callee-saved regs */
pushl %esi
pushl %edi
movl 8(%ebp), %eax /* move a to eax */
movl 12(%ebp), %esi /* move first to pivotpos */
movl 12(%ebp), %edi /* move first to i */
movl (%eax,%edi,4), %ebx /* move the first elt into pivot */
cmpl 16(%ebp), %esi /* if first >= last */
jge end /* if they're equal, end */
ploop:
incl %edi /* i++ */
cmpl 16(%ebp),%edi /* if i > last */
jg recend /* if > recursively sort */
cmpl (%eax,%edi,4),%ebx /* if pivot <= a[i] */
jle ploop /* skip switch */
incl %esi /* pivotpos++ */
movl (%eax,%esi,4),%ecx /* tmp1 = a[pivotpos] */
movl (%eax,%edi,4),%edx /* tmp2 = a[i] */
movl %ecx,(%eax,%edi,4) /* a[i] = tmp1 */
movl %edx,(%eax,%esi,4) /* a[pivotpos] = tmp2 */
jmp ploop /* loop back */
recend:
movl 12(%ebp),%edi /* set i = first */
movl (%eax,%esi,4),%ecx /* tmp1 = a[pivotpos] */
movl (%eax,%edi,4),%edx /* tmp2 = a[i] */
movl %ecx,(%eax,%edi,4) /* a[i] = tmp1 */
movl %edx,(%eax,%esi,4) /* a[pivotpos] = tmp2 */
decl %esi
pushl %esi
pushl %edi
pushl %eax
call quicksortA
pushl 16(%ebp) /* push last */
incl %esi
incl %esi
pushl %esi /* push pivotpos+1 */
pushl %eax /* push a */
call quicksortA
end:
popl %edi
popl %esi
popl %ebx
leave
ret