From 597022b22e0e499a567d29c7248e90b7726e0770 Mon Sep 17 00:00:00 2001 From: mithe24 Date: Thu, 30 Oct 2025 10:28:24 +0100 Subject: consistent names --- src/arrayMaker.s | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/array_maker.s | 159 --------------------------------------------------- src/insertionSort.s | 70 +++++++++++++++++++++++ src/insertion_sort.s | 70 ----------------------- src/lib/strcmp.s | 4 +- src/main.s | 24 ++++---- src/quickSort.s | 136 +++++++++++++++++++++++++++++++++++++++++++ src/quicksort.s | 136 ------------------------------------------- 8 files changed, 379 insertions(+), 379 deletions(-) create mode 100644 src/arrayMaker.s delete mode 100644 src/array_maker.s create mode 100644 src/insertionSort.s delete mode 100644 src/insertion_sort.s create mode 100644 src/quickSort.s delete mode 100755 src/quicksort.s diff --git a/src/arrayMaker.s b/src/arrayMaker.s new file mode 100644 index 0000000..94bd4ea --- /dev/null +++ b/src/arrayMaker.s @@ -0,0 +1,159 @@ +# -------------------------------------------- +# FUNCTION: make_array_from_file +# PURPOSE : Take a file descriptor, and convert it to the array data structure +# INPUTS : rdi = File descriptor +# OUTPUTS : rax = Pointer to start of array in memory +# rdx = Length of array in 8 byte chunks (the number of elements) +# CLOBBERS: rax, rdx, rdi, rsi +# -------------------------------------------- +.globl make_array_from_file +.type make_array_from_file, @function + make_array_from_file: + + # save + push %r15 + push %r14 + push %r13 + push %r12 + + # The file descriptor is in rdi + call create_file_buffer + movq %rax, %rdi # Select pointer to file data + movq %rdx, %rsi # Select length of file data + + call make_pairwise_data # Make the pairwise data + movq %rax, %r15 # Save pointer to pairwise data in r15 + movq %rdx, %r14 # Save the number of pairs in r14 + + # Allocate space for the array + movq %r14, %rdi # Select the number of coordinates + imulq $8, %rdi # 8 byte elements in array. Space for pointers + call allocate + movq %rax, %r13 # Save array pointer in r13 + + # Add pointers in array that point to pairwise array. Pointer 0 + # points to pair 0 and so on. + movq $0, %r12 # Counter for displacing pointers in array +loop: + cmp %r14, %r12 # Compare number of pairs with the counter + je end + + movq %r15, (%r13, %r12, 8) # Save pointer to pair_i in position_i in array + + addq $1, %r12 # Go to next spot in array + addq $16, %r15 # Go to next pair + + jmp loop +end: + movq %r13, %rax # Return pointer to array + movq %r14, %rdx # Return the number of elements in the array + + # retrieve + pop %r12 + pop %r13 + pop %r14 + pop %r15 + + ret + +# -------------------------------------------- +# FUNCTION: make_pairwise_data +# PURPOSE : Take the raw data from the file, and convert it to an array of x,y +# coordinates side by side: [x_1,y_1,x_2,y_2,...] +# INPUTS : rdi = Pointer to start of file data in memory +# rsi = Size of file +# OUTPUTS : rax = Pointer to start of pairwise data in memory +# rdx = The number of pairs +# CLOBBERS: rax, rdx, rdi, rsi +# -------------------------------------------- +.globl make_pairwise_data +.type make_pairwise_data, @function + make_pairwise_data: + # save + push %r15 + push %r14 + push %r13 + push %r12 + + movq %rdi, %r15 # Save file pointer in r15 + movq %rsi, %r14 # Save file size in r14 + + # Count number of lines + movq %r15, %rdi # Select the file pointer + movq %r14, %rsi # Select the file size + call getLineCount + movq %rax, %r13 # Save number of lines (coordinates) in r13 + + # Allocate space for the pairwise coordinates after parseData + # The space allocated = 2*(#coordinates)*8 bytes + imulq $16, %r13 # Multiply number of coordinates with 2*8 + movq %r13, %rdi # Select the number of coordinates + call allocate + movq %rax, %r12 # Save pointer to where pairwise data will be placed + + # Parse the data from the file into the pairwise data, and place it into the + # allocated space + movq %r15, %rdi # Select the pointer to the file data + movq %r14, %rsi # Select size of file + movq %r12, %rdx # Select memory location for where to put data + call parseData + + # Divide r13 with 16, this is to go from total length of array to the number + # of coordinates + movq %r13, %rax # Use r13 as dividend + movq $16, %rdi # Use 16 as divisor + cqo # Sign extend rax into rdx + idivq %rdi # r13/16 -> quotient in rax + + movq %rax, %rdx # Return number of pairs (the quotient of division) + movq %r12, %rax # Return pointer to pairwise data + + # retrieve + pop %r12 + pop %r13 + pop %r14 + pop %r15 + + ret + +# -------------------------------------------- +# FUNCTION: create_file_buffer +# PURPOSE : Take a file descriptor and create a memory location and put the +# data of the file in that location. +# INPUTS : rdi = File descriptor +# OUTPUTS : rax = Pointer to start of file in memory +# rdx = Length of file in bytes +# CLOBBERS: rax, rdx, rdi, rsi +# -------------------------------------------- +.globl create_file_buffer +.type create_file_buffer, @function +create_file_buffer: + # save + push %r15 + push %r14 + push %r13 + + movq %rdi, %r15 # Save file descriptor in r15 + movq %r15, %rdi # Select file descriptor + call getFileSize # Get the file size + movq %rax, %r14 # Save file size in r14 + + movq %r14, %rdi # Select file size + call allocate # Allocate memory for file contents + movq %rax, %r13 # Save file buffer in r13 + + movq %r15, %rdi # Select the file discriptor + movq %r13, %rsi # Select the buffer to store input + movq %r14, %rdx # Size to read from file + movq $0, %rax # Select read syscall + syscall # Read from the file + + movq %r13, %rax # Return pointer to start of file + movq %r14, %rdx # Return length of file + + # retrieve + pop %r13 + pop %r14 + pop %r15 + + ret diff --git a/src/array_maker.s b/src/array_maker.s deleted file mode 100644 index 94bd4ea..0000000 --- a/src/array_maker.s +++ /dev/null @@ -1,159 +0,0 @@ -# -------------------------------------------- -# FUNCTION: make_array_from_file -# PURPOSE : Take a file descriptor, and convert it to the array data structure -# INPUTS : rdi = File descriptor -# OUTPUTS : rax = Pointer to start of array in memory -# rdx = Length of array in 8 byte chunks (the number of elements) -# CLOBBERS: rax, rdx, rdi, rsi -# -------------------------------------------- -.globl make_array_from_file -.type make_array_from_file, @function - make_array_from_file: - - # save - push %r15 - push %r14 - push %r13 - push %r12 - - # The file descriptor is in rdi - call create_file_buffer - movq %rax, %rdi # Select pointer to file data - movq %rdx, %rsi # Select length of file data - - call make_pairwise_data # Make the pairwise data - movq %rax, %r15 # Save pointer to pairwise data in r15 - movq %rdx, %r14 # Save the number of pairs in r14 - - # Allocate space for the array - movq %r14, %rdi # Select the number of coordinates - imulq $8, %rdi # 8 byte elements in array. Space for pointers - call allocate - movq %rax, %r13 # Save array pointer in r13 - - # Add pointers in array that point to pairwise array. Pointer 0 - # points to pair 0 and so on. - movq $0, %r12 # Counter for displacing pointers in array -loop: - cmp %r14, %r12 # Compare number of pairs with the counter - je end - - movq %r15, (%r13, %r12, 8) # Save pointer to pair_i in position_i in array - - addq $1, %r12 # Go to next spot in array - addq $16, %r15 # Go to next pair - - jmp loop -end: - movq %r13, %rax # Return pointer to array - movq %r14, %rdx # Return the number of elements in the array - - # retrieve - pop %r12 - pop %r13 - pop %r14 - pop %r15 - - ret - -# -------------------------------------------- -# FUNCTION: make_pairwise_data -# PURPOSE : Take the raw data from the file, and convert it to an array of x,y -# coordinates side by side: [x_1,y_1,x_2,y_2,...] -# INPUTS : rdi = Pointer to start of file data in memory -# rsi = Size of file -# OUTPUTS : rax = Pointer to start of pairwise data in memory -# rdx = The number of pairs -# CLOBBERS: rax, rdx, rdi, rsi -# -------------------------------------------- -.globl make_pairwise_data -.type make_pairwise_data, @function - make_pairwise_data: - # save - push %r15 - push %r14 - push %r13 - push %r12 - - movq %rdi, %r15 # Save file pointer in r15 - movq %rsi, %r14 # Save file size in r14 - - # Count number of lines - movq %r15, %rdi # Select the file pointer - movq %r14, %rsi # Select the file size - call getLineCount - movq %rax, %r13 # Save number of lines (coordinates) in r13 - - # Allocate space for the pairwise coordinates after parseData - # The space allocated = 2*(#coordinates)*8 bytes - imulq $16, %r13 # Multiply number of coordinates with 2*8 - movq %r13, %rdi # Select the number of coordinates - call allocate - movq %rax, %r12 # Save pointer to where pairwise data will be placed - - # Parse the data from the file into the pairwise data, and place it into the - # allocated space - movq %r15, %rdi # Select the pointer to the file data - movq %r14, %rsi # Select size of file - movq %r12, %rdx # Select memory location for where to put data - call parseData - - # Divide r13 with 16, this is to go from total length of array to the number - # of coordinates - movq %r13, %rax # Use r13 as dividend - movq $16, %rdi # Use 16 as divisor - cqo # Sign extend rax into rdx - idivq %rdi # r13/16 -> quotient in rax - - movq %rax, %rdx # Return number of pairs (the quotient of division) - movq %r12, %rax # Return pointer to pairwise data - - # retrieve - pop %r12 - pop %r13 - pop %r14 - pop %r15 - - ret - -# -------------------------------------------- -# FUNCTION: create_file_buffer -# PURPOSE : Take a file descriptor and create a memory location and put the -# data of the file in that location. -# INPUTS : rdi = File descriptor -# OUTPUTS : rax = Pointer to start of file in memory -# rdx = Length of file in bytes -# CLOBBERS: rax, rdx, rdi, rsi -# -------------------------------------------- -.globl create_file_buffer -.type create_file_buffer, @function -create_file_buffer: - # save - push %r15 - push %r14 - push %r13 - - movq %rdi, %r15 # Save file descriptor in r15 - movq %r15, %rdi # Select file descriptor - call getFileSize # Get the file size - movq %rax, %r14 # Save file size in r14 - - movq %r14, %rdi # Select file size - call allocate # Allocate memory for file contents - movq %rax, %r13 # Save file buffer in r13 - - movq %r15, %rdi # Select the file discriptor - movq %r13, %rsi # Select the buffer to store input - movq %r14, %rdx # Size to read from file - movq $0, %rax # Select read syscall - syscall # Read from the file - - movq %r13, %rax # Return pointer to start of file - movq %r14, %rdx # Return length of file - - # retrieve - pop %r13 - pop %r14 - pop %r15 - - ret diff --git a/src/insertionSort.s b/src/insertionSort.s new file mode 100644 index 0000000..7badac0 --- /dev/null +++ b/src/insertionSort.s @@ -0,0 +1,70 @@ +# -------------------------------------------- +# FUNCTION: insertion_sort +# PURPOSE : Sorts array A, with references to arrays A_i, based on the given +# key in A_i, address and size of A. +# INPUTS : rdi = address for A +# rsi = number of coordinates n +# rdx = index of key to sort by +# OUTPUTS : rax = address for sorted A +# CLOBBERS: rax, rdx, rdi, rsi, r8, r9, r10, r11 +# -------------------------------------------- +.section .text +.globl insertion_sort +.type insertion_sort, @function +insertion_sort: + # save + push %r14 + push %r15 + + + cmp $1, %rsi # if n <= 1 jmp done + jle .insertion_sort_done + + # set up i + movq $1, %r15 # i , start with 2nd element + +.insertion_sort_loop: + # load A[i] + movq (%rdi,%r15,8), %r8 # pointer to key -> r8 + movq (%r8,%rdx,8), %r9 # key -> r9 + + # set up j + movq %r15, %r14 # j -> r14 + decq %r14 + +.insertion_sort_inner_loop: + cmpq $0, %r14 # if j < 0 stop and insert the key + jl .insertion_sort_insert_key + + # load A[j] + movq (%rdi, %r14, 8), %r10 # pointer to key -> r10 + movq (%r10, %rdx, 8), %r11 # key -> r11 + + + # compare A[i] with A[j] + cmpq %r11, %r9 + jge .insertion_sort_insert_key # if A[i] >= A[j] stop + + # if A[i] < A[j] + movq %r10, 8(%rdi, %r14, 8) # pointer to key of j -> A[j+1] + + decq %r14 # move to j - 1 + jmp .insertion_sort_inner_loop + + +.insertion_sort_insert_key: + movq %r8, 8(%rdi,%r14,8) + + # take the next number + incq %r15 # i++ + cmpq %rsi, %r15 # if i < n there are still numbers left to be sorted + jl .insertion_sort_loop + jmp .insertion_sort_done + +.insertion_sort_done: + movq %rdi, %rax + + # retrieve + pop %r15 + pop %r14 + ret diff --git a/src/insertion_sort.s b/src/insertion_sort.s deleted file mode 100644 index 3048a89..0000000 --- a/src/insertion_sort.s +++ /dev/null @@ -1,70 +0,0 @@ -# -------------------------------------------- -# FUNCTION: insertion_sort -# PURPOSE : Sorts array A, with references to arrays A_i, based on the given -# key in A_i, address and size of A. -# INPUTS : rdi = address for A -# rsi = number of coordinates n -# rdx = index of key to sort by -# OUTPUTS : rax = address for sorted A -# CLOBBERS: rax, rdx, rdi, rsi, r8, r9, r10, r11 -# -------------------------------------------- -.section .text -.globl insertion_sort -.type insertion_sort, @function -insertion_sort: - # save - push %r14 - push %r15 - - - cmp $1, %rsi # if n <= 1 jmp done - jle done - - # set up i - movq $1, %r15 # i , start with 2nd element - -loop: - # load A[i] - movq (%rdi,%r15,8), %r8 # pointer to key -> r8 - movq (%r8,%rdx,8), %r9 # key -> r9 - - # set up j - movq %r15, %r14 # j -> r14 - decq %r14 - -inner_loop: - cmpq $0, %r14 # if j < 0 stop and insert the key - jl insert_key - - # load A[j] - movq (%rdi, %r14, 8), %r10 # pointer to key -> r10 - movq (%r10, %rdx, 8), %r11 # key -> r11 - - - # compare A[i] with A[j] - cmpq %r11, %r9 - jge insert_key # if A[i] >= A[j] stop - - # if A[i] < A[j] - movq %r10, 8(%rdi, %r14, 8) # pointer to key of j -> A[j+1] - - decq %r14 # move to j - 1 - jmp inner_loop - - -insert_key: - movq %r8, 8(%rdi,%r14,8) - - # take the next number - incq %r15 # i++ - cmpq %rsi, %r15 # if i < n there are still numbers left to be sorted - jl loop - jmp done - -done: - movq %rdi, %rax - - # retrieve - pop %r15 - pop %r14 - ret diff --git a/src/lib/strcmp.s b/src/lib/strcmp.s index d495a91..e8f4334 100644 --- a/src/lib/strcmp.s +++ b/src/lib/strcmp.s @@ -13,7 +13,7 @@ strcmp: xorq %rax, %rax # i = 0 -loop: +.strcmp_loop: movb (%rdi, %rax, 1), %r8b movb (%rsi, %rax, 1), %r9b @@ -25,7 +25,7 @@ loop: incq %rax - jmp loop + jmp .strcmp_loop .strcmp_fail: xorq %rax, %rax diff --git a/src/main.s b/src/main.s index b628d29..036671e 100644 --- a/src/main.s +++ b/src/main.s @@ -10,18 +10,18 @@ _start: cmpq $2, (%rsp) # Check if there are only two arguments - jne algorithm_selected # If not, go to algorithm_selected + jne .algorithm_selected # If not, go to algorithm_selected -default: +.default: movq 16(%rsp), %rdi # Select first argument as file name movq $0, %rsi # Select read only movq $0, %rdx # Unused mode for read only movq $2, %rax # Select open syscall syscall # Open file, file descriptor returned in rax movq %rax, %r13 # Save file descriptor in r13 - jmp select_quicksort # Select quicksort + jmp .select_quicksort # Select quicksort -algorithm_selected: +.algorithm_selected: movq 32(%rsp), %rdi # Select third argument as file name movq $0, %rsi # Select read only movq $0, %rdx # Unused mode for read only @@ -34,29 +34,29 @@ algorithm_selected: movq $isort, %rsi # Select "isort" to compare with call strcmp # Compare cmp $1, %rax # If the strings where equal - je select_insertionsort # Select insertionsort + je .select_insertionsort # Select insertionsort .check_quicksort: movq 24(%rsp), %rdi # Select algorithm string movq $qsort, %rsi # Select "qsort" to compare with call strcmp # Compare cmp $1, %rax # If the strings where equal - je select_quicksort # Go to selection_done + je .select_quicksort # Go to selection_done .else_invalid_algorithm: movq $60, %rax # Select exit syscall movq $1, %rdi # Exit code 1 syscall # Exit -select_insertionsort: +.select_insertionsort: movq $insertion_sort, %r14 # Select insertion_sort in r14 - jmp the_rest + jmp .the_rest -select_quicksort: - movq $quicksort, %r14 # Select quicksort in r14 - jmp the_rest +.select_quicksort: + movq $quick_sort, %r14 # Select quicksort in r14 + jmp .the_rest -the_rest: +.the_rest: # Convert to array movq %r13, %rdi # Select file descriptor call make_array_from_file # Convert file to array format diff --git a/src/quickSort.s b/src/quickSort.s new file mode 100644 index 0000000..af38a65 --- /dev/null +++ b/src/quickSort.s @@ -0,0 +1,136 @@ +# -------------------------------------------- +# FUNCTION: quicksort +# PURPOSE : Calls the _quicksort function with the right parameters +# INPUTS : rdi = address for A +# rsi = number of coordinates n +# rdx = index of key to sort by +# OUTPUTS : rax = address for sorted A +# -------------------------------------------- +.section .text +.globl quick_sort +.type quick_sort, @function +quick_sort: + leaq -1(%rsi), %rcx + xorq %rsi, %rsi + call _quicksort + ret + +# -------------------------------------------- +# FUNCTION: _quicksort +# PURPOSE : Sorts array A, with references to arrays A_i, +# based on the given key in A_i, +# address and size of A. +# INPUTS : rdi = address for A +# rsi = low +# rdx = index of key to sort by +# rcx = high +# OUTPUTS : rax = address for sorted A +# NOTES : preserves rdi, rdx +# -------------------------------------------- +.section .text +# .globl _quicksort +.type _quicksort, @function +_quicksort: + pushq %r12 + pushq %r13 + pushq %r14 + + cmpq $0, %rsi # if 0 < low + jl .qsort_exit + cmpq $0, %rcx # if 0 < high + jl .qsort_exit + cmpq %rcx, %rsi # if high < low + jge .qsort_exit + + call hoare_part # rax = p + + movq %rsi, %r12 # save low + movq %rcx, %r13 # save high + movq %rax, %r14 # save p + +# --- left recursion --- + movq %r12, %rsi # low + movq %r14, %rcx # high = p + call _quicksort + +# --- right recursion --- + leaq 1(%r14), %rsi # low = p + 1 + movq %r13, %rcx # high + call _quicksort + +.qsort_exit: + movq %rdi, %rax + + popq %r14 + popq %r13 + popq %r12 + ret + +# -------------------------------------------- +# FUNCTION: hoare_part +# PURPOSE : Sorts array A, with references to arrays A_i, +# based on the given key in A_i, +# address and size of A. +# INPUTS : rdi = address for A +# rsi = low +# rdx = index of key to sort by +# rcx = high +# OUTPUTS : rax = address for sorted A +# NOTES : preserves rdi, rdx +# -------------------------------------------- +.section .text +.globl hoare_part +.type hoare_part, @function +hoare_part: + pushq %rbx + pushq %r12 + pushq %r13 + pushq %r14 + + leaq -1(%rsi), %rax # i = low - 1 + leaq 1(%rcx), %rbx # j = high + 1 + + # r12 = pivot + movq (%rdi, %rsi, 8), %r12 # &A[low] + movq (%r12, %rdx, 8), %r12 # A[low][idx] + +# left index +.hoare_part_left: + incq %rax + + movq (%rdi, %rax, 8), %r13 # &A[i] + movq (%r13, %rdx, 8), %r13 # A[i][idx] + + cmpq %r12, %r13 # while pivot < A[i][idx] + jl .hoare_part_left + +# right index +.hoare_part_right: + decq %rbx + + movq (%rdi, %rbx, 8), %r13 # &A[j] + movq (%r13, %rdx, 8), %r13 # A[j][idx] + + cmpq %r12, %r13 # while pivot > A[j][idx] + jg .hoare_part_right + +# check crossing + cmpq %rbx, %rax # i >= j + jge .hoare_part_done + +# swap A[i] and A[j] + movq (%rdi, %rax, 8), %r13 + movq (%rdi, %rbx, 8), %r14 + movq %r14, (%rdi, %rax, 8) + movq %r13, (%rdi, %rbx, 8) + + jmp .hoare_part_left + +.hoare_part_done: + movq %rbx, %rax # return j as partion index + + popq %r14 + popq %r13 + popq %r12 + popq %rbx + ret diff --git a/src/quicksort.s b/src/quicksort.s deleted file mode 100755 index 54720bf..0000000 --- a/src/quicksort.s +++ /dev/null @@ -1,136 +0,0 @@ -# -------------------------------------------- -# FUNCTION: quicksort -# PURPOSE : Calls the _quicksort function with the right parameters -# INPUTS : rdi = address for A -# rsi = number of coordinates n -# rdx = index of key to sort by -# OUTPUTS : rax = address for sorted A -# -------------------------------------------- -.section .text -.globl quicksort -.type quicksort, @function -quicksort: - leaq -1(%rsi), %rcx - xorq %rsi, %rsi - call _quicksort - ret - -# -------------------------------------------- -# FUNCTION: _quicksort -# PURPOSE : Sorts array A, with references to arrays A_i, -# based on the given key in A_i, -# address and size of A. -# INPUTS : rdi = address for A -# rsi = low -# rdx = index of key to sort by -# rcx = high -# OUTPUTS : rax = address for sorted A -# NOTES : preserves rdi, rdx -# -------------------------------------------- -.section .text -# .globl _quicksort -.type _quicksort, @function -_quicksort: - pushq %r12 - pushq %r13 - pushq %r14 - - cmpq $0, %rsi # if 0 < low - jl .qsort_exit - cmpq $0, %rcx # if 0 < high - jl .qsort_exit - cmpq %rcx, %rsi # if high < low - jge .qsort_exit - - call hoare_part # rax = p - - movq %rsi, %r12 # save low - movq %rcx, %r13 # save high - movq %rax, %r14 # save p - -# --- left recursion --- - movq %r12, %rsi # low - movq %r14, %rcx # high = p - call _quicksort - -# --- right recursion --- - leaq 1(%r14), %rsi # low = p + 1 - movq %r13, %rcx # high - call _quicksort - -.qsort_exit: - movq %rdi, %rax - - popq %r14 - popq %r13 - popq %r12 - ret - -# -------------------------------------------- -# FUNCTION: hoare_part -# PURPOSE : Sorts array A, with references to arrays A_i, -# based on the given key in A_i, -# address and size of A. -# INPUTS : rdi = address for A -# rsi = low -# rdx = index of key to sort by -# rcx = high -# OUTPUTS : rax = address for sorted A -# NOTES : preserves rdi, rdx -# -------------------------------------------- -.section .text -.globl hoare_part -.type hoare_part, @function -hoare_part: - pushq %rbx - pushq %r12 - pushq %r13 - pushq %r14 - - leaq -1(%rsi), %rax # i = low - 1 - leaq 1(%rcx), %rbx # j = high + 1 - - # r12 = pivot - movq (%rdi, %rsi, 8), %r12 # &A[low] - movq (%r12, %rdx, 8), %r12 # A[low][idx] - -# left index -.hoare_part_left: - incq %rax - - movq (%rdi, %rax, 8), %r13 # &A[i] - movq (%r13, %rdx, 8), %r13 # A[i][idx] - - cmpq %r12, %r13 # while pivot < A[i][idx] - jl .hoare_part_left - -# right index -.hoare_part_right: - decq %rbx - - movq (%rdi, %rbx, 8), %r13 # &A[j] - movq (%r13, %rdx, 8), %r13 # A[j][idx] - - cmpq %r12, %r13 # while pivot > A[j][idx] - jg .hoare_part_right - -# check crossing - cmpq %rbx, %rax # i >= j - jge .hoare_part_done - -# swap A[i] and A[j] - movq (%rdi, %rax, 8), %r13 - movq (%rdi, %rbx, 8), %r14 - movq %r14, (%rdi, %rax, 8) - movq %r13, (%rdi, %rbx, 8) - - jmp .hoare_part_left - -.hoare_part_done: - movq %rbx, %rax # return j as partion index - - popq %r14 - popq %r13 - popq %r12 - popq %rbx - ret -- cgit v1.2.3-70-g09d2