/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/lib2/free.s
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/lib2/free.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1154 - (show annotations)
Sun Aug 10 18:19:54 2014 UTC (5 years, 3 months ago) by dbug
File size: 2245 byte(s)


1 ; void free(unsigned int *p)
2
3 _free
4 ldy #1 ; (tmp0) wanted=p-heapovh
5 lda (sp),y
6 tax
7 dey
8 lda (sp),y
9
10 _freemc ; machine code entry pt, A=lo(p), X=hi(p)
11 sec
12 sbc _heapovh
13 sta tmp0
14 txa
15 sbc #0
16 sta tmp0+1
17
18 lda (sp),y ; if(!p)return
19 dey
20 ora (sp),y
21 bne free1
22
23 rts
24
25 free1
26 lda #<(_heapdesc) ; (tmp1) desc = &heapdesc
27 sta tmp1
28 lda #>(_heapdesc)
29 sta tmp1+1
30
31 freeloop
32 lda tmp1 ; if(!desc)return
33 ora tmp1+1
34 bne free2
35 rts
36
37 free2
38 ldy #0 ; (tmp2)next=desc->next
39 lda (tmp1),y
40 sta tmp2
41 tax
42 iny
43 lda (tmp1),y
44 sta tmp2+1
45
46 cpx tmp0 ; if(wanted==next)
47 bne freenext
48 cmp tmp0+1
49 bne freenext
50
51 lda (tmp2),y ; desc->next=next->next
52 sta (tmp1),y
53 dey
54 lda (tmp2),y
55 sta (tmp1),y
56
57 dec _nheapdesc ; nheapdesc--
58 bpl free3
59 dec _nheapdesc+1
60
61 free3
62 sec ; nheapbytes-=next->len
63 ldy #2
64 lda _nheapbytes
65 sbc (tmp2),y
66 sta _nheapbytes
67 iny
68 lda _nheapbytes+1
69 sbc (tmp2),y
70 sta _nheapbytes+1
71
72 rts ; return
73
74 freenext
75 lda tmp2 ; desc=next
76 sta tmp1
77 lda tmp2+1
78 sta tmp1+1
79
80 jmp freeloop
81
82
83
84 ;Implementation in C:
85 ;
86 ;void myfree(void *p)
87 ;{
88 ; register memdesc *wanted=(memdesc *)((char *)p-heapovh); /* tmp0 */
89 ; register memdesc *desc=(memdesc *)&heapdesc; /* tmp1 */
90 ; register memdesc *next; /* tmp2 */
91 ;
92 ; if(!p)return;
93 ;
94 ; while(desc){
95 ; next=desc->next;
96 ; if(wanted==next){
97 ; desc->next=next->next;
98 ;
99 ; nheapdesc--;
100 ; nheapbytes-=next->len;
101 ;
102 ; return;
103 ; }
104 ; desc=next;
105 ; }
106 ;}
107

  ViewVC Help
Powered by ViewVC 1.1.26