diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2014-02-14 03:23:14 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2014-02-14 03:24:56 +0100 |
commit | d4ddec9e127160ea498d8364d8c060882c035175 (patch) | |
tree | d8111b924aa55f7392f489a8ae9d430e53a03199 /list.asm | |
parent | 7a20f366cde4717d0decc6228eb844af1f5ef2a0 (diff) |
add a function which clears a list
list_clear(&plist)
the function will run through every elements and clear them.
the prehead is updated (first and size are set to 0)
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 |