Rev 5085 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5085 | Rev 5363 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | head dd 0 |
8 | head dd 0 |
9 | 9 | ||
10 | linkedlist_add: |
10 | linkedlist_add: |
11 | push ebx |
11 | push ebx |
12 | mov ebx, [head] |
12 | mov ebx, [head] |
13 | mov [head], eax |
13 | mov [head], eax |
14 | mov [eax + node.next], ebx |
14 | mov [eax + node.next], ebx |
15 | pop ebx |
15 | pop ebx |
16 | ret |
16 | ret |
17 | 17 | ||
18 | linkedlist_unlink: |
18 | linkedlist_unlink: |
19 | push ebx ecx |
19 | push ebx ecx |
20 | test eax, eax |
20 | test eax, eax |
21 | jz .invalid_pointer |
21 | jz .invalid_pointer |
22 | mov ebx, eax ; eax - pointer to node for unlink |
22 | mov ebx, eax ; eax - pointer to node for unlink |
23 | cmp eax, [head] |
23 | cmp eax, [head] |
24 | jz .unlink_head |
24 | jz .unlink_head |
25 | .getnext: |
25 | .getnext: |
26 | cmp [ebx+node.next], eax |
26 | cmp [ebx+node.next], eax |
27 | jz .unlink |
27 | jz .unlink |
28 | cmp [ebx+node.next], 0 |
28 | cmp [ebx+node.next], 0 |
29 | jz .invalid_pointer |
29 | jz .invalid_pointer |
30 | mov ebx, [ebx+node.next] |
30 | mov ebx, [ebx+node.next] |
31 | jmp .getnext |
31 | jmp .getnext |
32 | .unlink: |
32 | .unlink: |
33 | mov ecx, [eax+node.next] |
33 | mov ecx, [eax+node.next] |
34 | mov [ebx+node.next], ecx |
34 | mov [ebx+node.next], ecx |
35 | jmp @f |
35 | jmp @f |
36 | .unlink_head: |
36 | .unlink_head: |
37 | mov ebx, [eax+node.next] |
37 | mov ebx, [eax+node.next] |
38 | mov [head], ebx |
38 | mov [head], ebx |
39 | @@: |
39 | @@: |
40 | .invalid_pointer: |
40 | .invalid_pointer: |
41 | pop ecx ebx |
41 | pop ecx ebx |
42 | ret |
42 | ret |
43 | 43 | ||
44 | linkedlist_isvalid: ;eax - pointer to check; returns zero if valid |
44 | linkedlist_isvalid: ;eax - pointer to check; returns zero if valid |
45 | push ebx ecx |
45 | push ebx ecx |
46 | xor ecx, ecx |
46 | xor ecx, ecx |
47 | test eax, eax |
47 | test eax, eax |
48 | jz .invalid_pointer |
48 | jz .invalid_pointer |
49 | mov ebx, [head] |
49 | mov ebx, [head] |
50 | .next_check: |
50 | .next_check: |
51 | cmp eax, ebx |
51 | cmp eax, ebx |
52 | jz .valid_pointer |
52 | jz .valid_pointer |
53 | mov ebx, [ebx + node.next] |
53 | mov ebx, [ebx + node.next] |
54 | test ebx, ebx |
54 | test ebx, ebx |
55 | jz .invalid_pointer |
55 | jz .invalid_pointer |
56 | jmp .next_check |
56 | jmp .next_check |
57 | .invalid_pointer: |
57 | .invalid_pointer: |
58 | inc ecx |
58 | inc ecx |
59 | .valid_pointer: |
59 | .valid_pointer: |
60 | mov eax, ecx |
60 | mov eax, ecx |
61 | pop ecx ebx |
61 | pop ecx ebx |
62 | ret |
62 | ret |
63 | 63 | ||
64 | linkedlist_gethead: |
64 | linkedlist_gethead: |
65 | mov eax, [head] |
65 | mov eax, [head] |
66 | ret |
66 | ret |
67 | 67 | ||
68 | restore node |
68 | restore node |
69 | restore node.next |
69 | restore node.next |