diff options
| author | Andreas Kapp Lindquist <alind24@student.sdu.dk> | 2025-09-29 22:13:50 +0200 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | 245ab12e7e9cb8c333312e2f1f5588d6a903febf (patch) | |
| tree | c48490d4b8368578599313ce21e0399cfb0ee603 /src | |
| parent | 0e18088e24992f1f8b848472a510a92eb65094ea (diff) | |
| download | sorter-245ab12e7e9cb8c333312e2f1f5588d6a903febf.tar.gz sorter-245ab12e7e9cb8c333312e2f1f5588d6a903febf.zip | |
fix(insertionsort.s): Wrong syntax for accessing elements
Diffstat (limited to 'src')
| -rw-r--r-- | src/insertionsort.s | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/insertionsort.s b/src/insertionsort.s index af75a2a..66f0323 100644 --- a/src/insertionsort.s +++ b/src/insertionsort.s @@ -3,7 +3,7 @@ # 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 +# rsi = length of A in 64 bit chunks # rdx = index of key to sort by # OUTPUTS : rax = address for sorted A # CLOBBERS: none @@ -29,23 +29,26 @@ insertion_sort: call insertion_sort # Sort recursively pop %rsi # Restore array size - movq ((%rdi, %rsi, 1), %rdx), %rbx # Save value of A[n] in rbx + movq (%rdi, %rsi, 8), %rbp # Save address at A[n] in rbp + movq (%rbp, %rdx), %rbx # Save value of A[n] in rbx - movq $rsi, %r15 # Save copy of n in r15 + movq %rsi, %r15 # Save copy of n in r15 subq $1, %r15 # Make r15 = n-1 = j while: - cmp %r15, $0 # Compare j with 0 + cmp $0, %r15 # Compare j with 0 jl end # Go to end if less than - movq ((%rdi, %r15, 1), %rdx), %r12 # Move A[j] into r12 + movq (%rdi, %r15, 8), %rbp # Save address at A[j] to rbp + movq (%rbp, %rdx), %r12 # Move value at A[j] into r12 cmp %r12, %rbx # Compare A[j] with A[n] jge end # Go to end if greater than or equal movq %r15, %r14 # Duplicate r15 into r14 addq $1, %r14 # And add 1: j+1 - movq %r12, ((%rdi, %r14, 1), %rdx) # Move A[j] into A[j+1] + movq (%rdi, %r14, 8), %rbp # Save address of A[j+1] in rbp + movq %r12, (%rbp, %rdx) # Move value at A[j] into value at A[j+1] subq $1, %r15 # j = j - 1 @@ -53,7 +56,8 @@ while: end_while: addq $1, %r15 # j = j + 1 - movq %rbx, ((%rdi, %r15, 1), %rdx) # A[j+1] = x + movq (%rdi, %r15, 8), %rbp # Move address at A[j] into rbp + movq %rbx, (%rbp, %rdx) # A[j] = x end: # Restore registers |