From 597022b22e0e499a567d29c7248e90b7726e0770 Mon Sep 17 00:00:00 2001 From: mithe24 Date: Thu, 30 Oct 2025 10:28:24 +0100 Subject: consistent names --- src/array_maker.s | 159 ------------------------------------------------------ 1 file changed, 159 deletions(-) delete mode 100644 src/array_maker.s (limited to 'src/array_maker.s') diff --git a/src/array_maker.s b/src/array_maker.s deleted file mode 100644 index 94bd4ea..0000000 --- a/src/array_maker.s +++ /dev/null @@ -1,159 +0,0 @@ -# -------------------------------------------- -# FUNCTION: make_array_from_file -# PURPOSE : Take a file descriptor, and convert it to the array data structure -# INPUTS : rdi = File descriptor -# OUTPUTS : rax = Pointer to start of array in memory -# rdx = Length of array in 8 byte chunks (the number of elements) -# CLOBBERS: rax, rdx, rdi, rsi -# -------------------------------------------- -.globl make_array_from_file -.type make_array_from_file, @function - make_array_from_file: - - # save - push %r15 - push %r14 - push %r13 - push %r12 - - # The file descriptor is in rdi - call create_file_buffer - movq %rax, %rdi # Select pointer to file data - movq %rdx, %rsi # Select length of file data - - call make_pairwise_data # Make the pairwise data - movq %rax, %r15 # Save pointer to pairwise data in r15 - movq %rdx, %r14 # Save the number of pairs in r14 - - # Allocate space for the array - movq %r14, %rdi # Select the number of coordinates - imulq $8, %rdi # 8 byte elements in array. Space for pointers - call allocate - movq %rax, %r13 # Save array pointer in r13 - - # Add pointers in array that point to pairwise array. Pointer 0 - # points to pair 0 and so on. - movq $0, %r12 # Counter for displacing pointers in array -loop: - cmp %r14, %r12 # Compare number of pairs with the counter - je end - - movq %r15, (%r13, %r12, 8) # Save pointer to pair_i in position_i in array - - addq $1, %r12 # Go to next spot in array - addq $16, %r15 # Go to next pair - - jmp loop -end: - movq %r13, %rax # Return pointer to array - movq %r14, %rdx # Return the number of elements in the array - - # retrieve - pop %r12 - pop %r13 - pop %r14 - pop %r15 - - ret - -# -------------------------------------------- -# FUNCTION: make_pairwise_data -# PURPOSE : Take the raw data from the file, and convert it to an array of x,y -# coordinates side by side: [x_1,y_1,x_2,y_2,...] -# INPUTS : rdi = Pointer to start of file data in memory -# rsi = Size of file -# OUTPUTS : rax = Pointer to start of pairwise data in memory -# rdx = The number of pairs -# CLOBBERS: rax, rdx, rdi, rsi -# -------------------------------------------- -.globl make_pairwise_data -.type make_pairwise_data, @function - make_pairwise_data: - # save - push %r15 - push %r14 - push %r13 - push %r12 - - movq %rdi, %r15 # Save file pointer in r15 - movq %rsi, %r14 # Save file size in r14 - - # Count number of lines - movq %r15, %rdi # Select the file pointer - movq %r14, %rsi # Select the file size - call getLineCount - movq %rax, %r13 # Save number of lines (coordinates) in r13 - - # Allocate space for the pairwise coordinates after parseData - # The space allocated = 2*(#coordinates)*8 bytes - imulq $16, %r13 # Multiply number of coordinates with 2*8 - movq %r13, %rdi # Select the number of coordinates - call allocate - movq %rax, %r12 # Save pointer to where pairwise data will be placed - - # Parse the data from the file into the pairwise data, and place it into the - # allocated space - movq %r15, %rdi # Select the pointer to the file data - movq %r14, %rsi # Select size of file - movq %r12, %rdx # Select memory location for where to put data - call parseData - - # Divide r13 with 16, this is to go from total length of array to the number - # of coordinates - movq %r13, %rax # Use r13 as dividend - movq $16, %rdi # Use 16 as divisor - cqo # Sign extend rax into rdx - idivq %rdi # r13/16 -> quotient in rax - - movq %rax, %rdx # Return number of pairs (the quotient of division) - movq %r12, %rax # Return pointer to pairwise data - - # retrieve - pop %r12 - pop %r13 - pop %r14 - pop %r15 - - ret - -# -------------------------------------------- -# FUNCTION: create_file_buffer -# PURPOSE : Take a file descriptor and create a memory location and put the -# data of the file in that location. -# INPUTS : rdi = File descriptor -# OUTPUTS : rax = Pointer to start of file in memory -# rdx = Length of file in bytes -# CLOBBERS: rax, rdx, rdi, rsi -# -------------------------------------------- -.globl create_file_buffer -.type create_file_buffer, @function -create_file_buffer: - # save - push %r15 - push %r14 - push %r13 - - 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, %rax # Return pointer to start of file - movq %r14, %rdx # Return length of file - - # retrieve - pop %r13 - pop %r14 - pop %r15 - - ret -- cgit v1.2.3-70-g09d2