2014-07-16 19:40:12 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-06-17 19:43:10 +02:00
|
|
|
head dd 0
|
2014-07-16 19:40:12 +02:00
|
|
|
size dd 0
|
2014-06-14 23:01:22 +02:00
|
|
|
|
2014-07-16 19:40:12 +02:00
|
|
|
linkedlist_add:
|
2014-06-17 19:43:10 +02:00
|
|
|
push ebx
|
|
|
|
mov ebx, [head]
|
|
|
|
mov [head], eax
|
|
|
|
mov [eax + node.next], ebx
|
|
|
|
pop ebx
|
|
|
|
ret
|
2014-06-14 23:01:22 +02:00
|
|
|
|
2014-07-16 19:40:12 +02:00
|
|
|
linkedlist_delete:
|
2014-06-17 19:43:10 +02:00
|
|
|
push ebx ecx
|
|
|
|
mov ebx, eax ; eax - pointer to node for delete
|
|
|
|
cmp eax, [head]
|
|
|
|
jz .unlink_head
|
2014-06-14 23:01:22 +02:00
|
|
|
|
|
|
|
.getnext:
|
2014-06-17 19:43:10 +02:00
|
|
|
cmp [ebx+node.next], eax
|
|
|
|
jz .unlink
|
|
|
|
cmp [ebx+node.next], 0
|
|
|
|
jz .invalid_pointer
|
|
|
|
mov ebx, [ebx+node.next]
|
|
|
|
jmp .getnext
|
2014-06-14 23:01:22 +02:00
|
|
|
|
|
|
|
.unlink:
|
2014-06-17 19:43:10 +02:00
|
|
|
mov ecx, [eax+node.next]
|
|
|
|
mov [ebx+node.next], ecx
|
|
|
|
jmp @f
|
2014-07-16 19:40:12 +02:00
|
|
|
|
2014-06-14 23:01:22 +02:00
|
|
|
.unlink_head:
|
2014-06-17 19:43:10 +02:00
|
|
|
mov ebx, [eax+node.next]
|
|
|
|
mov [head], ebx
|
2014-06-14 23:01:22 +02:00
|
|
|
@@:
|
2014-06-17 19:43:10 +02:00
|
|
|
mov ecx, eax
|
|
|
|
call Kfree
|
2014-06-14 23:01:22 +02:00
|
|
|
.invalid_pointer:
|
2014-08-08 20:00:40 +02:00
|
|
|
pop ecx ebx
|
2014-06-17 19:43:10 +02:00
|
|
|
ret
|
2014-07-16 19:40:12 +02:00
|
|
|
|
2014-08-08 20:00:40 +02:00
|
|
|
linkedlist_isvalid: ;eax - pointer to check; returns zero if valid
|
|
|
|
inc ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .valid_pointer ;actually, poiner is not valid
|
2014-07-16 19:40:12 +02:00
|
|
|
push ebx ecx
|
|
|
|
xor ecx, ecx
|
|
|
|
mov ebx, [head]
|
|
|
|
.next_check:
|
|
|
|
cmp eax, ebx
|
|
|
|
jz .valid_pointer
|
|
|
|
mov ebx, [ebx + node.next]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .invalid_pointer
|
|
|
|
jmp .next_check
|
|
|
|
.invalid_pointer:
|
|
|
|
inc ecx
|
|
|
|
.valid_pointer:
|
|
|
|
mov eax, ecx
|
|
|
|
pop ecx ebx
|
|
|
|
ret
|
2014-06-14 23:01:22 +02:00
|
|
|
|
2014-07-16 19:40:12 +02:00
|
|
|
linkedlist_gethead:
|
2014-06-17 19:43:10 +02:00
|
|
|
mov eax, [head]
|
|
|
|
ret
|
2014-06-14 23:01:22 +02:00
|
|
|
|
|
|
|
restore node
|
2014-06-17 19:43:10 +02:00
|
|
|
restore node.next
|