diff options
| author | Andreas Kapp Lindquist <andkaplin05@gmail.com> | 2025-10-28 10:58:47 +0100 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | fe3b403d5788c3ead9391d02a95c4684daab0272 (patch) | |
| tree | 9a01fdc8d0966b031121aa41cac5d27613d987d6 | |
| parent | c9e74c0f7ddcc9b53a857ebca331998b1470ba7c (diff) | |
| download | sorter-fe3b403d5788c3ead9391d02a95c4684daab0272.tar.gz sorter-fe3b403d5788c3ead9391d02a95c4684daab0272.zip | |
refactor(quicksort): renamed to qsort to quicksort and added helper function for better interface
| -rwxr-xr-x | src/quicksort.s (renamed from src/qsort.s) | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/qsort.s b/src/quicksort.s index 564a25e..78b9eea 100755 --- a/src/qsort.s +++ b/src/quicksort.s @@ -1,5 +1,23 @@ # -------------------------------------------- -# FUNCTION: qsort +# 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 +# NOTES : preserves rdi, rdx +# -------------------------------------------- +.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. @@ -11,9 +29,9 @@ # NOTES : preserves rdi, rdx # -------------------------------------------- .section .text -.globl qsort -.type qsort, @function -qsort: +# .globl _quicksort +.type _quicksort, @function +_quicksort: pushq %r12 pushq %r13 pushq %r14 @@ -34,12 +52,12 @@ qsort: # --- left recursion --- movq %r12, %rsi # low movq %r14, %rcx # high = p - call qsort + call _quicksort # --- right recursion --- leaq 1(%r14), %rsi # low = p + 1 movq %r13, %rcx # high - call qsort + call _quicksort .qsort_exit: movq %rdi, %rax |