From 5b0f04f0c5d406def1acbcdbcc114e9b4bf5c7da Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sun, 14 Jul 2024 10:52:51 -0700 Subject: Double Linked List --- linked_list.inc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'linked_list.inc') diff --git a/linked_list.inc b/linked_list.inc index 4fbb923..0e5042b 100644 --- a/linked_list.inc +++ b/linked_list.inc @@ -20,19 +20,62 @@ endstruc mov qword [rax + ll_next], 0 %endmacro -%macro dlln_alloc 0 +%macro dll_alloc 0 alloc DoublyLinkedListNode_size mov qword [rax + dll_next], 0 + mov qword [rax + dll_prev], 0 %endmacro %macro lln_free 0-1 rax free %1, LinkedListNode_size %endmacro -%macro dlln_free 0-1 rax +%macro dll_free 0-1 rax free %1, DoublyLinkedListNode_size %endmacro +%macro ll_seek 0-1 rax + mov rax, [%1 + ll_next] +%endm + +_dll_seek_backward: + mov rax, [rax + dll_prev] + ret + +_dll_seek_forward: + mov rax, [rax + dll_next] + ret + +%macro dll_seek 0-2 rax,"forward" +%if "%1" != "%rax" + mov rax, %1 +%endif +%if %2 == "forward" + call _dll_seek_forward +%elif %2 == "backward" + call _dll_seek_backward +%else + %error "Direction not specified!" +%endif +%endm + +_dll_end: +.loop: + mov rcx, [rax + dll_next] + cmp rcx, 0 + je .end + call _dll_seek_forward + jmp .loop +.end: + ret + +%macro dll_end 0-1 rax +%if "%1" != "rax" + mov rax, %1 +%endif + call _dll_end +%endm + %macro ll_push 2 ;; %1 = Current Linked List Node ;; %2 = Value to push (Must fit in a register, larger must be pushed as pointer to the underlying structure) @@ -41,4 +84,19 @@ endstruc mov qword [rax + ll_value], %2 %endm +%macro dll_push 2 + ;; %1 = Current Doubly Linked List Node + ;; %2 = Value to push (Must fit in a register, larger must be pushed as pointer to the underlying structure) + dll_alloc + mov rcx, [%1 + dll_next] + cmp rcx, 0 + je %%skip + mov qword [rcx + dll_prev], rax +%%skip: + mov qword [%1 + dll_next], rax + mov qword [rax + dll_next], rcx + mov qword [rax + dll_value], %2 + mov qword [rax + dll_prev], %1 +%endm + %endif -- cgit v1.2.1