.text .p2align 4 .global combsort .type combsort,@function combsort: # Offset from BP of arguments (+) and temporaries (-) .lLength = +12 .lArray = +8 .lGap = -4 # Setup stack frame pushl %ebp movl %esp,%ebp # Make space for temporaries subl $4,%esp # Save registers pushl %ebx pushl %esi pushl %edi # bx = address of array movl .lArray(%ebp),%ebx # gap = length movl .lLength(%ebp),%eax movl %eax,.lGap(%ebp) # top of outer loop .l100: # eax = (gap * 10) / 13 movl .lGap(%ebp),%eax movl $10,%ecx imul %ecx movl $13,%ecx idiv %ecx # if gap == 9 or gap == 10 then gap = 11 cmpl $9,%eax je .l300 #returns to .l120 cmpl $10,%eax je .l300 #returns to .l120 # if gap == 0 then gap = 1 cmpl $1,%eax adcl $0,%eax .l120: # gap = eax movl %eax,.lGap(%ebp) # edi = length movl .lLength(%ebp),%edi # esi = length - gap movl %edi,%esi subl .lGap(%ebp),%esi # swapped = false mov $0,%ecx # top of inner loop .l140: # esi--, edi-- # if ran off the beginning of the array, we're done with the inner loop decl %esi decl %edi cmpl $0,%esi jl .l200 # if array[esi] > array[edi]... movl (%ebx,%esi,4),%eax movl (%ebx,%edi,4),%edx cmpl %eax,%edx jnle .l140 # then swap array[esi] and array[edi] mov %eax,(%ebx,%edi,4) mov %edx,(%ebx,%esi,4) # swapped = true mov $1,%ecx # bottom of inner loop jmp .l140 .l200: # bottom of outer loop: done if !swapped and gap == 1 orl %ecx,%ecx jnz .l100 cmpl $1,.lGap(%ebp) jne .l100 # Restore registers popl %edi popl %esi popl %ebx # Break down stack frame & return leave ret .l300: movl $11,%eax jmp .l120