# -------------------------------------------- # FUNCTION: parse_file # PURPOSE : Parses the file into the array format. # INPUTS : rdi = File descriptor # OUTPUTS : rax = address of array # rdx = length of array # CLOBBERS: none # NOTES : Preserves all registers. # -------------------------------------------- .section .text .globl parse_file .type parse_file, @function parse_file: # Save registers push %rbx push %rbp push %r12 push %r13 push %r14 push %r15 movq %rdi, %r15 # Save file descriptor in r15 movq %r15, %rdi # Select file descriptor call getFileSize # Get the file size movq %rax, %r14 # Save file size in r14 movq %r14, %rdi # Select file size call allocate # Allocate memory for file contents movq %rax, %r13 # Save file buffer in r13 movq %r15, %rdi # Select the file discriptor movq %r13, %rsi # Select the buffer to store input movq %r14, %rdx # Size to read from file movq $0, %rax # Select read syscall syscall # Read from the file movq %r13, %rdi # Select buffer for file contents movq %r14, %rsi # Select file size call getLineCount # Count lines movq %rax, %r12 # Save line count in r12 movq %r12, %rdi # Select number of coordinates call make_coordinate_buffer # Create buffer movq %rax, %r13 # Override file buffer with coordinate buffer movq %r13, %rdi # Select coordinate buffer movq %r12, %rsi # Select number of coordinates call build_pointer_buffer # Create final array of pointers movq %rax, %rax # Return pointer to array movq %r12, %rdx # Return line count # Restore registers pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret