All pastes #2131878 Raw Edit

Mine

public text v1 · immutable
#2131878 ·published 2012-03-25 00:27 UTC
rendered paste body
sortloop:

        decq    %rdx                    # decrement the main counter
        pop     %rcx                    # pop first element

        movq    %rdx, %r9               # prepare counter for inner loop
        imulq   0x8, %r9                # scale it appropriately


innerloop:

        movq    %r9 , %r8
        movq    %rsp , %r9              # move the pointer to the stack!
        addq    %r8, %r9

        cmpq    %rcx, %r9               # is this element smaller than the current element
        jle     swap                    # yes, swap


doneswap:
        cmpq    %rsp , %r9              # are we out of elements?
        jle     innerloop               # NO! DO IT AGAIN!

                                        # otherwise

        movq    $formatp , %rdi         # print the output
        movq    %rcx , %rsi             # printf("%d\n",rsi);
        movq    $0 , %rax               #
        call    printf                  #

        cmpq    $0 , %rdx               # did we have any more elements?
        je      end                     # no, jump to the end
        jmp     sortloop                # yep, go back to the beginning of the main loop

swap:
        push    %rcx                    # save the current value
        subq    0x8 , %r9               # move the stack pointer forward one element
        movq    %r9 , %rcx              # swap elements
        addq    0x8 , %r9               # move the stack pointer back
        jmp     doneswap                # go back to innerloop