aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/coordinateManager.s51
-rw-r--r--src/file_parser.s60
-rw-r--r--src/lib/utils.s214
3 files changed, 0 insertions, 325 deletions
diff --git a/src/coordinateManager.s b/src/coordinateManager.s
deleted file mode 100644
index 4a46c9b..0000000
--- a/src/coordinateManager.s
+++ /dev/null
@@ -1,51 +0,0 @@
-# --------------------------------------------
-# FUNCTION: make_coordinate_buffer
-# PURPOSE : allocate memory for n coordinate tuples (16 bytes each)
-# INPUTS : rdi = number of coordinates
-# OUTPUTS : rax = pointer to allocated coordinate buffer
-# CLOBBERS: rax, rdi, r11
-# --------------------------------------------
-
-.globl make_coordinate_buffer
-.type make_coordinate_buffer, @function
-make_coordinate_buffer:
- imulq $16, %rdi # multiply n by 16
- call allocate # allocate total bytes
- ret
-
-
-# --------------------------------------------
-# FUNCTION: build_pointer_buffer
-# PURPOSE : build a buffer of pointers to coordinate tuples
-# INPUTS : rdi = coordinate buffer, rsi = number of tuples
-# OUTPUTS : rax = pointer buffer
-# CLOBBERS: rax, rcx, rdx, r8, r9
-# --------------------------------------------
-
-.globl build_pointer_buffer
-.type build_pointer_buffer, @function
-build_pointer_buffer:
- movq %rdi, %r8 # save coordinate buffer pointer in r8
- movq %rsi, %rax
- imulq $8, %rax # 1 pointer per coordinate / each pointer 8 bytes
- movq %rax, %rdi # argument for allocate
- call allocate # pointer buffer -> rax
- movq %rax, %r9 # save pointer buffer in r9
-
- movq $0, %rcx # index = 0
-pointer_loop:
- cmpq %rsi, %rcx # # if rcx >= n, done
- jge done
-
- movq %rcx, %rdx
- imulq $16, %rdx # 16 byte jumps / every pair of coordinates = 8 bytes + 8 bytes
- addq %r8, %rdx # rdX = coord_buffer + offset
- movq %rdx, (%r9,%rcx,8) # store pointer in pointer buffer / 8 byte jumps here, every pointer is 8 bytes
-
- incq %rcx
- jmp pointer_loop
-
-done:
- movq %r9, %rax # return pointer buffer
- ret
-
diff --git a/src/file_parser.s b/src/file_parser.s
deleted file mode 100644
index b63708f..0000000
--- a/src/file_parser.s
+++ /dev/null
@@ -1,60 +0,0 @@
-# --------------------------------------------
-# FUNCTION: parse_file
-# PURPOSE : Parses the file into the array format.
-# INPUTS : rdi = File descriptor
-# OUTPUTS : rax = address of array
-# rdx = length of array in 8 byte chunks
-# 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 Number of coordinates
-
- # Restore registers
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %rbp
- pop %rbx
-
- ret
diff --git a/src/lib/utils.s b/src/lib/utils.s
deleted file mode 100644
index f63d3f9..0000000
--- a/src/lib/utils.s
+++ /dev/null
@@ -1,214 +0,0 @@
-# These registers are not neccesarily perserved after a function call:
-# RAX RCX RDX RSI RDI R8 R9 R10 R11
-# Which means that these must be perserved:
-# RBX RBP R12 R13 R14 R15
-# The order of arguments passed to functions is as follows:
-# RDI RSI RDX RCX R8 R9
-# The order of the return registers is as follows:
-# RAX RDX
-
-# Buffer for file data
-.section .data
-myBuffer:
- .space 1
-
-.section .text
-
-
-# Print RDI as an unsigned integer following by a newline.
-# Note: the function does not follow the ordinary calling convention,
-# but restores all registers.
-.type printNum, @function
-.globl printNum
-printNum:
- push %rbp
- movq %rsp, %rbp
-
- # save
- push %rax
- push %rdi
- push %rsi
- push %rdx
- push %rcx
- push %r8
- push %r9
-
- movq %rdi, %rax # arg
-
- movq $1, %r9 # we always print "\n"
- push $10 # '\n'
-.LprintNum_convertLoop:
- movq $0, %rdx
- movq $10, %rcx
- idivq %rcx
- addq $48, %rdx # '0' is 48
- push %rdx
- addq $1, %r9
- cmpq $0, %rax
- jne .LprintNum_convertLoop
-.LprintNum_printLoop:
- movq $1, %rax # sys_write
- movq $1, %rdi # stdout
- movq %rsp, %rsi # buf
- movq $1, %rdx # len
- syscall
- addq $8, %rsp
- addq $-1, %r9
- jne .LprintNum_printLoop
-
- # restore
- pop %r9
- pop %r8
- pop %rcx
- pop %rdx
- pop %rsi
- pop %rdi
- pop %rax
-
- movq %rbp, %rsp
- pop %rbp
- ret
-
-.globl intFromString # int intFromString(char *str)
-# Pre: str != 0
-# Pre: all characters in the string are one of 0123456789.
-.type intFromString, @function
-intFromString:
- xorq %rax, %rax
-.LintFromString_loop:
- movzx (%rdi), %rsi # Move a single character/byte %rbx and zero-extend it.
- cmpq $0, %rsi # A string ends with a 0-byte.
- je .LintFromString_done
- movq $10, %rcx # Shift the number 1 decimal place to the left.
- mulq %rcx
- subq $48, %rsi # Convert from ASCII character to number. ASCII '0' has value 48. '1' is 49, etc.
- addq %rsi, %rax # Add the number.
- addq $1, %rdi
- jmp .LintFromString_loop
-.LintFromString_done:
- ret
-
-
-# The pointer to the string is argument RDI
-# It is required that the string ends with the zero byte
-.type printString, @function
-.globl printString
-printString:
- push %r12 # Save R12
-
- movq %rdi, %r12 # Save copy of string address
- call stringLength # Get length of string in RAX
-
- movq $1, %rdi # Select to write to stdout
- movq %r12, %rsi # Use pointer at start of string
- movq %rax, %rdx # Put string size in rdx
- movq $1, %rax # Select sys_write
- syscall # Call the function
-
- pop %r12 # Restore R12
- ret
-
-
-# Requires that the file is already open, and file descriptor is passed as first
-# argument.
-.type printFile, @function
-.globl printFile
-printFile:
- # The callee-saved registers
- push %rbx
- push %rbp
- push %r12
- push %r13
- push %r14
- push %r15
-
- movq %rdi, %r10 # Save file descriptor in r10
-
-loop:
- movq %r10, %rdi # Select the file discriptor
- movq $0, %rax # Select read syscall
- movq $1, %rdx # Size to read from file
- movq $myBuffer, %rsi # Select the buffer to store input
- syscall # Read from the file
-
- cmp $0, %rax # If rax is zero, end of file
- je endPrintFile # Jump to end of program
-
- movq $1, %rdx # Put string size in RDX
- movq $myBuffer, %rsi # Use pointer at start of string
- movq $1, %rdi # Select to write to stdout
- movq $1, %rax # Select sys_write
- syscall # Call the function
-
- jmp loop
-
-endPrintFile:
- # The callee-saved registers
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %rbp
- pop %rbx
-
- ret
-
-
-.type printStdin, @function
-.globl printStdin
-printStdin:
- # The callee-saved registers
- push %rbx
- push %rbp
- push %r12
- push %r13
- push %r14
- push %r15
-
-printStdinLoop:
- movq $0, %rax # Select read syscall
- movq $1, %rdx # Size to read
- movq $0, %rdi # Select stdin
- movq $myBuffer, %rsi # Select the buffer to store input
- syscall
-
- cmp $0, %rax # Check if there was something to be read.
- je endPrintStdin # If not, jump to end
-
- movq $1, %rdx # Put string size in rdx
- movq $myBuffer, %rsi # Use pointer at start of string
- movq $1, %rdi # Select to write to stdout
- movq $1, %rax # Select sys_write
- syscall # Call the function
-
- jmp printStdinLoop
-
-
-endPrintStdin:
- # The callee-saved registers
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %rbp
- pop %rbx
-
- ret
-
-.type stringLength, @function
-.globl stringLength
-stringLength:
- movq $0, %rcx # CL will keep the current byte
- movq $0, %rax # The length counter
-
-loopStringLength:
- movb (%rdi), %cl # Move the lower byte of the string into CL
- cmp $0, %cl # Compare 0 with the lower byte of register C
- je endStringLength # Go the end
- addq $1, %rax # Add one to length
- addq $1, %rdi # Go one forward in address
- jmp loopStringLength# Go to start of loop
-
-endStringLength:
- ret
-