Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | |
2 | push eax |
||
3 | xor eax,eax |
||
4 | sub eax,edi |
||
5 | and eax,3 |
||
6 | xchg ecx,eax |
||
7 | sub eax,ecx |
||
8 | jle .l1 |
||
9 | rep movsb |
||
10 | mov ecx,eax |
||
11 | shr ecx,2 |
||
12 | rep movsd |
||
13 | and eax,3 |
||
14 | .l1: add ecx,eax |
||
15 | rep movsb |
||
16 | pop eax |
||
17 | ret |
||
18 | |||
19 | |||
20 | call malloc |
||
21 | pushad |
||
22 | add ecx,3 |
||
23 | xor eax,eax |
||
24 | shr ecx,2 |
||
25 | rep stosd |
||
26 | popad |
||
27 | ret |
||
28 | |||
29 | |||
30 | xor edi,edi |
||
31 | stc |
||
32 | mresize2: ret |
||
33 | mresize: ; puntero en di ncr retorna nuevo puntero en di |
||
34 | test edi,edi |
||
35 | jz malloc |
||
36 | cmp ecx,[edi-4] |
||
37 | je mresize2 |
||
38 | call free |
||
39 | malloc: |
||
40 | mov edi,ecx |
||
41 | jecxz mresize2 |
||
42 | pushad |
||
43 | mov esi,iniciomemoria+4 |
||
44 | lea ebx,[ecx+3] |
||
45 | and ebx,-4 ;redondeo a 4 |
||
46 | .l1: mov edi,esi |
||
47 | add esi,[esi] |
||
48 | jc mresize1 |
||
49 | lodsd |
||
50 | cmp eax,ebx |
||
51 | jc .l1 |
||
52 | cmp esi,[iniciomemoria+8] |
||
53 | jc .l2 |
||
54 | jne mresize1 |
||
55 | lea edx,[ebx+esi+4] |
||
56 | cmp edx,[iniciomemoria+12] |
||
57 | jnc mresize1 |
||
58 | mov [iniciomemoria+8],edx |
||
59 | .l2: pop dword [esi-4] |
||
60 | push esi |
||
61 | sub eax,ebx |
||
62 | je .l3 |
||
63 | sub eax,4 |
||
64 | mov [esi+ebx],eax |
||
65 | jz .l3 |
||
66 | ;fragmentar |
||
67 | add ebx,4 |
||
68 | add [edi],ebx |
||
69 | mov eax,[esi] |
||
70 | sub eax,ebx |
||
71 | mov [esi+ebx],eax |
||
72 | popad |
||
73 | ret |
||
74 | .l3: lodsd |
||
75 | add eax,4 |
||
76 | add [edi],eax |
||
77 | popad |
||
78 | ret |
||
79 | |||
80 | |||
81 | jz malloc |
||
82 | jecxz free |
||
83 | pushad |
||
84 | pop esi |
||
85 | mov eax,[edi-4] |
||
86 | call malloc |
||
87 | push edi |
||
88 | cmp ecx,eax |
||
89 | jc .l1 |
||
90 | mov ecx,eax |
||
91 | .l1: push esi |
||
92 | call movedata |
||
93 | pop edi |
||
94 | call free |
||
95 | popad |
||
96 | .l2: ret |
||
97 | free: ;puntero en di |
||
98 | ;no se comprueban los punteros |
||
99 | ;retorna di=0 , ncr |
||
100 | test edi,edi |
||
101 | jz realloc.l2 |
||
102 | pushad |
||
103 | pop edi |
||
104 | mov ebp,[edi-4] |
||
105 | dec ebp |
||
106 | and ebp,-4 ;redondeo a 4,dx=dx-4 |
||
107 | xor edx,edx |
||
108 | push edx |
||
109 | mov edx,iniciomemoria+4 |
||
110 | mov esi,edx |
||
111 | ;buscar puntero libre anterior |
||
112 | .l1: mov ebx,esi |
||
113 | lodsd |
||
114 | add esi,eax |
||
115 | cmp esi,edi |
||
116 | jc .l1 |
||
117 | ;enlazar |
||
118 | mov ecx,esi |
||
119 | sub ecx,edi |
||
120 | sub eax,ecx |
||
121 | sub ecx,4 |
||
122 | mov [ebx],eax |
||
123 | ;fusionar con el anterior |
||
124 | cmp eax,[ebx-4] |
||
125 | jne .l2 |
||
126 | cmp ebx,edx |
||
127 | je .l2 ;no fusionar con el primero |
||
128 | mov edi,ebx |
||
129 | add eax,4 |
||
130 | add ecx,eax |
||
131 | add ebp,eax |
||
132 | .l2: mov ebx,ebp ;fusionar con bloques de tama¤o 0 |
||
133 | .l3: add ebx,4 |
||
134 | test dword [edi+ebx],-1 |
||
135 | jz .l3 |
||
136 | cmp ebx,ecx |
||
137 | jne .l4 |
||
138 | ;fusionar con el siguiente |
||
139 | add ebx,[esi-4] |
||
140 | add ecx,[esi] |
||
141 | add ebx,4 |
||
142 | add ecx,4 |
||
143 | cmp esi,[edx+4] |
||
144 | jne .l4 |
||
145 | mov [edx+4],edi |
||
146 | .l4: mov [edi-4],ebx |
||
147 | mov [edi],ecx |
||
148 | popad |
||
149 | ret |
||
150 | |||
151 | |||
152 | cmp ecx,64 |
||
153 | jc .l1 |
||
154 | add ecx,edi |
||
155 | add edi,3 |
||
156 | and edi,-4 |
||
157 | and ecx,-4 |
||
158 | mov eax,ecx |
||
159 | sub ecx,edi ;redondeo |
||
160 | xchg eax,[iniciomemoria+12] |
||
161 | cmp edi,eax |
||
162 | jna .l1 |
||
163 | lea esi,[edi+4] |
||
164 | mov edx,esi |
||
165 | xchg esi,[iniciomemoria+8] |
||
166 | neg edx |
||
167 | mov [edi],edx |
||
168 | mov [edi+4],edx |
||
169 | lea edx,[edi-4] |
||
170 | sub edi,esi |
||
171 | mov [esi],edi |
||
172 | sub eax,4 |
||
173 | sub eax,esi |
||
174 | mov [esi-4],eax |
||
175 | add esi,eax |
||
176 | sub edx,esi |
||
177 | mov [esi],edx |
||
178 | .l1: ret |
||
179 | |||
180 | |||
181 | ;retorna edx nbloques o 0 si error,ecx memoria libre |
||
182 | ;ncr: ebp,ebx,eax |
||
183 | mov edi,iniciomemoria |
||
184 | mov esi,edi |
||
185 | xor edx,edx |
||
186 | mov ecx,[edi] |
||
187 | neg ecx ;el primer bloque no cuenta |
||
188 | .l1: add ecx,[edi] |
||
189 | add edi,4 |
||
190 | add edi,[edi] |
||
191 | .l2: inc edx |
||
192 | add esi,[esi] |
||
193 | jc .l4 |
||
194 | add esi,7 |
||
195 | jc .l3 |
||
196 | and esi,-4 |
||
197 | cmp esi,edi |
||
198 | jc .l2 |
||
199 | je .l1 |
||
200 | jmp .l4 |
||
201 | .l3: test edi,edi |
||
202 | jnz .l4 |
||
203 | add ecx,[iniciomemoria+12] |
||
204 | ret |
||
205 | .l4: xor edx,edx |
||
206 | stc |
||
207 | ret |
||
208 |