diff options
| author | Andreas Kapp Lindquist <andkaplin05@gmail.com> | 2025-10-28 10:59:28 +0100 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | 3bc255f9677175e8a701ea365ffcc97080160ff9 (patch) | |
| tree | 3043de20e5e5e0a5b97a4690b6e19c5941b146b5 /src/main.s | |
| parent | fe3b403d5788c3ead9391d02a95c4684daab0272 (diff) | |
| download | sorter-3bc255f9677175e8a701ea365ffcc97080160ff9.tar.gz sorter-3bc255f9677175e8a701ea365ffcc97080160ff9.zip | |
feat(main): Support for choosing algorithm as argument
Diffstat (limited to '')
| -rw-r--r-- | src/main.s | 57 |
1 files changed, 52 insertions, 5 deletions
@@ -1,24 +1,70 @@ +.section .data + isort: + .string "isort" + qsort: + .string "qsort" + .section .text .globl _start _start: - # Open file + cmpq $2, (%rsp) # Check if there are only two arguments + jne algorithm_selected # If not, go to algorithm_selected + +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 + +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 + movq $2, %rax # Select open syscall + syscall # Open file, file descriptor returned in rax + movq %rax, %r13 # Save file descriptor in r13 + +.check_insertion_sort: + movq 24(%rsp), %rdi # Select algorithm string + movq $isort, %rsi # Select "isort" to compare with + call strcmp # Compare + cmp $1, %rax # If the strings where equal + 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 + +.else_invalid_algorithm: + movq $60, %rax # Select exit syscall + movq $1, %rdi # Exit code 1 + syscall # Exit + +select_insertionsort: + movq $insertion_sort, %r14 # Select insertion_sort in r14 + jmp the_rest + +select_quicksort: + movq $quicksort, %r14 # Select quicksort in r14 + jmp the_rest +the_rest: # Convert to array - movq %rax, %rdi # Select file descriptor + movq %r13, %rdi # Select file descriptor call make_array_from_file # Convert file to array format movq %rdx, %r15 # Save length of array in r15 # Sort movq %rax, %rdi # Select address of array - leaq -1(%r15), %rcx # Select length of array -1 as high - xorq %rsi, %rsi # low = 0 + movq %r15, %rsi # Select number of coordinates movq $1, %rdx # Sort by key 1 - call qsort # Sort the array + call *%r14 # Sort the array # Convert array to string # in tsv format @@ -32,6 +78,7 @@ _start: movq $1, %rdi syscall +end: # Exit movq $60, %rax movq $0, %rdi # Exit code 0 |