diff options
Diffstat (limited to 'list.asm')
-rw-r--r-- | list.asm | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -21,6 +21,7 @@ ;; THE SOFTWARE. extern malloc +extern free ;; initializes the list stored at address $rdi with default values global list_init:function @@ -32,6 +33,10 @@ global list_new_raw:function ;; same as list_new_raw, unless the list is initialized with default values global list_new:function +;; remove every element of the list pointed to by $rip. +;; the elements are freed using free() from the libc +global list_clear:function + ;; create a new element (using dynamic allocation) at the end of the list ;; stored at address $rdi. the created element will contain the value of $rsi ;; if, unlikely, the allocation fails, $rax will contain -1. @@ -87,6 +92,41 @@ list_new_raw: ;; {{{ ret ;; }}} +list_clear: ;; {{{ + + enter 0, 0 + + mov ecx, [rdi + list_t.size] ; load the size of the list into the counter + + test ecx, ecx + je .end + + mov rsi, QWORD [rdi + list_t.first] + + ; the list is reset to its initial state + mov DWORD [rdi + list_t.size], 0 + mov QWORD [rdi + list_t.first], 0 + + .loop: + push QWORD [rsi + elem_t.next] + push rcx + + mov rdi, rsi + call free + + pop rcx + pop rsi + + dec ecx + + test ecx, ecx + jne .loop + + .end + leave + ret + +;; }}} list_append: ;; {{{ enter 0x18, 0 |