diff options
| author | mithe24 <mithe24@student.sdu.dk> | 2025-10-08 13:35:41 +0200 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | fa03afa46984fbf6eacbd5540e4e318d161cbbe0 (patch) | |
| tree | cd5e2f567a407ee459d94fcfd8ed3088fce3bc96 /snippets/parsing.s | |
| parent | 07816c4c9c257c327bb93a72ed3a9b680816136c (diff) | |
| download | sorter-fa03afa46984fbf6eacbd5540e4e318d161cbbe0.tar.gz sorter-fa03afa46984fbf6eacbd5540e4e318d161cbbe0.zip | |
chore(snippets): move snippetss to src/
Diffstat (limited to 'snippets/parsing.s')
| -rw-r--r-- | snippets/parsing.s | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/snippets/parsing.s b/snippets/parsing.s deleted file mode 100644 index e039be6..0000000 --- a/snippets/parsing.s +++ /dev/null @@ -1,76 +0,0 @@ -# int getLineCount(const char *data, int size) -# -# Returns the number of '\n' characters in the memory pointed to. -# 'data': the address of the first character to look at. -# 'size': the length of the memory area to scan through. -.globl getLineCount -.type getLinecount, @function -getLineCount: - # rdi: 'data' - # rsi: 'size' - addq %rdi, %rsi # make rsi the past-the-end pointer - xorq %rax, %rax # count = 0 -.LgetLineCount_loop: - cmpq %rdi, %rsi - je .LgetLineCount_end # if rdi == rsi: we are done - movb (%rdi), %dl # load the next byte - addq $1, %rdi - cmpb $0xA, %dl # is it a newline char? - jne .LgetLineCount_loop # if not, continue in the buffer - addq $1, %rax # completed a number - jmp .LgetLineCount_loop -.LgetLineCount_end: - ret - - -# void parseData(const char *data, int size, int *result) -# -# Converts the ASCII representation of the coordinates into pairs of numbers. -# 'data': the address of the first character in the ASCII representation. -# 'size': the length of the ASCII representation. -# 'result': the address of a piece of memory big enough to hold the -# coordinates. If there are n coordinates in the input, the 'result' -# memory will be an array of 2n 8-byte integers, with alternating x and y -# coordinates. -# -# Note, this functions only expects unsigned ints in the input and does not -# perform any validity checks at all. -.globl parseData -.type parseData, @function -parseData: - addq %rdi, %rsi # make rsi the past-the-end pointer - push %rsi # and store it as the top element on the stack -.LparseData_coordinateLoop: - cmpq (%rsp), %rdi - je .LparseData_coordinateLoop_end - movq $9, %rsi # '\t' - call parseNumber # increases rdi to point past-the-end of the number - movq %rax, (%rdx) # store the number - addq $8, %rdx # point to the next place for a number - movq $10, %rsi # '\n' - call parseNumber # increases rdi to point past-the-end of the number - movq %rax, (%rdx) # store the number - addq $8, %rdx # point to the next place for a number - jmp .LparseData_coordinateLoop -.LparseData_coordinateLoop_end: - addq $8, %rsp - ret - -# int parseNumber(const char *&data, const char *end) -parseNumber: - xorq %rax, %rax # result -.LparseNumber_loop: - xorq %r10, %r10 # the next digit - movb (%rdi), %r10b # read character - addq $1, %rdi # ++data - cmpq %rsi, %r10 # done with this number? - je .LparseNumber_loop_end - # here we assume that the character is actually a digit - # add this digit to the current number - subq $48, %r10 # convert the ASCII code to the digit it represents - imul $10, %rax # 'make room' for the new digit - addq %r10, %rax # and add the new digit - jmp .LparseNumber_loop -.LparseNumber_loop_end: - # we now have a number in rax - ret |