From e36e76bef4b06992f6e0ffe3f76be0877c7e381d Mon Sep 17 00:00:00 2001 From: Navid Samanghoon Date: Tue, 30 Sep 2025 10:58:57 +0200 Subject: feat(coordinateManager): file with functions regarding making a pointer buffer --- src/coordinateManager.s | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/coordinateManager.s diff --git a/src/coordinateManager.s b/src/coordinateManager.s new file mode 100644 index 0000000..4a46c9b --- /dev/null +++ b/src/coordinateManager.s @@ -0,0 +1,51 @@ +# -------------------------------------------- +# 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 + -- cgit v1.2.3-70-g09d2