diff options
| author | mithe24 <mithe24@student.sdu.dk> | 2025-09-29 16:53:51 +0200 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | 0cbf11095572ecd2fbeaa7990512f8d671c80523 (patch) | |
| tree | daa4c8d76c86c368f59df02aa986156c6e8e194e | |
| parent | 703af39239b9dbb8a4159cc39fc483e4cc8df1b6 (diff) | |
| download | sorter-0cbf11095572ecd2fbeaa7990512f8d671c80523.tar.gz sorter-0cbf11095572ecd2fbeaa7990512f8d671c80523.zip | |
feat(sorting): Added sorting wrapper function
Sorting wrapper function sorts array a,
with references to arrays a_i, based on the given
key in a_i, address and size of a.
Co-authered: Andreas Kapp Lindquist
<andkaplin05@gmail.com>
Diffstat (limited to '')
| -rw-r--r-- | src/sorting.s | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/sorting.s b/src/sorting.s new file mode 100644 index 0000000..c626b06 --- /dev/null +++ b/src/sorting.s @@ -0,0 +1,38 @@ +# -------------------------------------------- +# FUNCTION: sorter +# 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 = length of a in bytes +# rdx = index of key to sort by +# rcx = address of sorting algorithm +# OUTPUTS : rax = address of sorted a +# CLOBBERS: none +# NOTES : Preserves all registers except eax +# -------------------------------------------- +.section .text +.globl sorter +.type sorter, @function +sorter: + # Save registers + push %rbx + push %rbp + push %r12 + push %r13 + push %r14 + push %r15 + + # rdi is the addres of a + # rsi is the length of a + # rdx is the index of the key + call rcx # Sort the array + + # Restore registers + pop %r15 + pop %r14 + pop %r13 + pop %r12 + pop %rbp + pop %rbx + + ret |