aboutsummaryrefslogtreecommitdiff
path: root/src/main.s
blob: 318bb0281c96041f0b3a1b95397cd0fce25a36a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.section .text
.globl _start
_start:
    # Open file
    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

    # Convert to array
    movq %rax, %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
    movq %r15, %rsi             # Select length of array
    movq $1, %rdx               # Sort by key 1
    call qsort                  # Sort the array
    
    # Print array
    movq %rax, %rdi             # Select the pointer to the array
    movq %r15, %rsi             # Select length of array
    call print_buffer           # Print array

    # Exit
    movq $60, %rax              
    movq $0, %rdi               # Exit code 0
    syscall