Rev 2664 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | |
2 | ; Copyright (c) 1999-2012, Tomasz Grysztar. |
||
2664 | dunkaist | 3 | ; All rights reserved. |
31 | halyavin | 4 | |
5 | |||
6 | mov eax,[memory_end] |
||
157 | heavyiron | 7 | mov [labels_list],eax |
8 | mov eax,[additional_memory] |
||
9 | mov [free_additional_memory],eax |
||
10 | xor eax,eax |
||
11 | mov [current_locals_prefix],eax |
||
12 | mov [anonymous_reverse],eax |
||
13 | mov [anonymous_forward],eax |
||
14 | mov [hash_tree],eax |
||
15 | mov [blocks_stack],eax |
||
16 | mov [parsed_lines],eax |
||
242 | heavyiron | 17 | mov esi,[memory_start] |
157 | heavyiron | 18 | mov edi,[source_start] |
19 | parser_loop: |
||
31 | halyavin | 20 | mov [current_line],esi |
157 | heavyiron | 21 | lea eax,[edi+100h] |
22 | cmp eax,[labels_list] |
||
23 | jae out_of_memory |
||
24 | cmp byte [esi+16],0 |
||
25 | je empty_line |
||
26 | cmp byte [esi+16],3Bh |
||
992 | heavyiron | 27 | je empty_line |
28 | mov al,0Fh |
||
157 | heavyiron | 29 | stos byte [edi] |
30 | mov eax,esi |
||
31 | stos dword [edi] |
||
32 | inc [parsed_lines] |
||
242 | heavyiron | 33 | add esi,16 |
157 | heavyiron | 34 | parse_line: |
109 | heavyiron | 35 | mov [formatter_symbols_allowed],0 |
2287 | heavyiron | 36 | cmp byte [esi],1Ah |
157 | heavyiron | 37 | jne empty_instruction |
38 | push edi |
||
39 | add esi,2 |
||
40 | movzx ecx,byte [esi-1] |
||
41 | cmp byte [esi+ecx],':' |
||
42 | je simple_label |
||
43 | cmp byte [esi+ecx],'=' |
||
44 | je constant_label |
||
45 | call get_instruction |
||
46 | jnc main_instruction_identified |
||
47 | cmp byte [esi+ecx],1Ah |
||
48 | jne no_data_label |
||
49 | push esi ecx |
||
50 | lea esi,[esi+ecx+2] |
||
51 | movzx ecx,byte [esi-1] |
||
52 | call get_data_directive |
||
53 | jnc data_label |
||
54 | pop ecx esi |
||
55 | no_data_label: |
||
109 | heavyiron | 56 | call get_data_directive |
157 | heavyiron | 57 | jnc main_instruction_identified |
58 | pop edi |
||
59 | sub esi,2 |
||
60 | xor bx,bx |
||
61 | call parse_line_contents |
||
62 | jmp parse_next_line |
||
63 | simple_label: |
||
109 | heavyiron | 64 | pop edi |
157 | heavyiron | 65 | call identify_label |
66 | mov byte [edi],2 |
||
67 | inc edi |
||
68 | stos dword [edi] |
||
69 | inc esi |
||
70 | xor al,al |
||
71 | stos byte [edi] |
||
72 | jmp parse_line |
||
73 | constant_label: |
||
109 | heavyiron | 74 | pop edi |
157 | heavyiron | 75 | call get_label_id |
76 | mov byte [edi],3 |
||
77 | inc edi |
||
78 | stos dword [edi] |
||
79 | xor al,al |
||
80 | stos byte [edi] |
||
81 | inc esi |
||
82 | xor bx,bx |
||
83 | call parse_line_contents |
||
84 | jmp parse_next_line |
||
85 | data_label: |
||
109 | heavyiron | 86 | pop ecx edx |
157 | heavyiron | 87 | pop edi |
88 | push eax ebx esi |
||
89 | mov esi,edx |
||
90 | movzx ecx,byte [esi-1] |
||
91 | call identify_label |
||
92 | mov byte [edi],2 |
||
93 | inc edi |
||
94 | stos dword [edi] |
||
95 | pop esi ebx eax |
||
96 | stos byte [edi] |
||
97 | push edi |
||
98 | main_instruction_identified: |
||
109 | heavyiron | 99 | pop edi |
157 | heavyiron | 100 | mov dl,al |
101 | mov al,1 |
||
102 | stos byte [edi] |
||
103 | mov ax,bx |
||
104 | stos word [edi] |
||
105 | mov al,dl |
||
106 | stos byte [edi] |
||
107 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 108 | je parse_block |
157 | heavyiron | 109 | cmp bx,repeat_directive-instruction_handler |
1189 | heavyiron | 110 | je parse_block |
157 | heavyiron | 111 | cmp bx,while_directive-instruction_handler |
1189 | heavyiron | 112 | je parse_block |
157 | heavyiron | 113 | cmp bx,end_directive-instruction_handler |
1189 | heavyiron | 114 | je parse_end_directive |
157 | heavyiron | 115 | cmp bx,else_directive-instruction_handler |
1189 | heavyiron | 116 | je parse_else |
157 | heavyiron | 117 | cmp bx,assert_directive-instruction_handler |
2664 | dunkaist | 118 | je parse_assert |
119 | common_parse: |
||
109 | heavyiron | 120 | call parse_line_contents |
157 | heavyiron | 121 | jmp parse_next_line |
122 | empty_instruction: |
||
109 | heavyiron | 123 | lods byte [esi] |
157 | heavyiron | 124 | or al,al |
125 | jz parse_next_line |
||
126 | cmp al,':' |
||
127 | je invalid_name |
||
128 | dec esi |
||
992 | heavyiron | 129 | cmp al,3Bh |
157 | heavyiron | 130 | je skip_rest_of_line |
992 | heavyiron | 131 | mov [parenthesis_stack],0 |
1242 | heavyiron | 132 | call parse_argument |
157 | heavyiron | 133 | jmp parse_next_line |
134 | empty_line: |
||
109 | heavyiron | 135 | add esi,16 |
992 | heavyiron | 136 | skip_rest_of_line: |
137 | call skip_foreign_line |
||
138 | parse_next_line: |
||
31 | halyavin | 139 | cmp esi,[source_start] |
157 | heavyiron | 140 | jb parser_loop |
141 | source_parsed: |
||
109 | heavyiron | 142 | cmp [blocks_stack],0 |
157 | heavyiron | 143 | je blocks_stack_ok |
144 | pop eax |
||
145 | pop [current_line] |
||
146 | jmp missing_end_directive |
||
147 | blocks_stack_ok: |
||
109 | heavyiron | 148 | xor al,al |
157 | heavyiron | 149 | stos byte [edi] |
150 | add edi,0Fh |
||
151 | and edi,not 0Fh |
||
152 | mov [code_start],edi |
||
153 | ret |
||
154 | parse_block: |
||
109 | heavyiron | 155 | mov eax,esp |
157 | heavyiron | 156 | sub eax,100h |
157 | jc stack_overflow |
||
158 | cmp eax,[stack_limit] |
||
159 | jb stack_overflow |
||
160 | push [current_line] |
||
161 | mov ax,bx |
||
162 | shl eax,16 |
||
163 | push eax |
||
164 | inc [blocks_stack] |
||
165 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 166 | je parse_if |
157 | heavyiron | 167 | cmp bx,while_directive-instruction_handler |
1189 | heavyiron | 168 | je parse_while |
157 | heavyiron | 169 | call parse_line_contents |
170 | jmp parse_next_line |
||
171 | parse_end_directive: |
||
109 | heavyiron | 172 | cmp byte [esi],1Ah |
157 | heavyiron | 173 | jne common_parse |
174 | push edi |
||
175 | inc esi |
||
176 | movzx ecx,byte [esi] |
||
177 | inc esi |
||
178 | call get_instruction |
||
179 | pop edi |
||
180 | jnc parse_end_block |
||
181 | sub esi,2 |
||
182 | jmp common_parse |
||
183 | parse_end_block: |
||
109 | heavyiron | 184 | mov dl,al |
157 | heavyiron | 185 | mov al,1 |
186 | stos byte [edi] |
||
187 | mov ax,bx |
||
188 | stos word [edi] |
||
189 | mov al,dl |
||
190 | stos byte [edi] |
||
191 | lods byte [esi] |
||
192 | or al,al |
||
193 | jnz extra_characters_on_line |
||
194 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 195 | je close_parsing_block |
157 | heavyiron | 196 | cmp bx,repeat_directive-instruction_handler |
1189 | heavyiron | 197 | je close_parsing_block |
157 | heavyiron | 198 | cmp bx,while_directive-instruction_handler |
1189 | heavyiron | 199 | je close_parsing_block |
157 | heavyiron | 200 | jmp parse_next_line |
201 | close_parsing_block: |
||
109 | heavyiron | 202 | cmp [blocks_stack],0 |
157 | heavyiron | 203 | je unexpected_instruction |
204 | cmp bx,[esp+2] |
||
205 | jne unexpected_instruction |
||
206 | dec [blocks_stack] |
||
207 | pop eax edx |
||
208 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 209 | jne parse_next_line |
157 | heavyiron | 210 | test al,1100b |
211 | jz parse_next_line |
||
212 | test al,10000b |
||
213 | jnz parse_next_line |
||
214 | sub edi,8 |
||
215 | jmp parse_next_line |
||
216 | parse_if: |
||
109 | heavyiron | 217 | push edi |
157 | heavyiron | 218 | call parse_line_contents |
219 | xor al,al |
||
220 | stos byte [edi] |
||
221 | xchg esi,[esp] |
||
222 | mov edi,esi |
||
223 | call preevaluate_logical_expression |
||
224 | pop esi |
||
225 | cmp al,'0' |
||
226 | je parse_false_condition_block |
||
227 | cmp al,'1' |
||
228 | je parse_true_condition_block |
||
229 | or byte [esp],10000b |
||
230 | jmp parse_next_line |
||
231 | parse_while: |
||
109 | heavyiron | 232 | push edi |
157 | heavyiron | 233 | call parse_line_contents |
234 | xor al,al |
||
235 | stos byte [edi] |
||
236 | xchg esi,[esp] |
||
237 | mov edi,esi |
||
238 | call preevaluate_logical_expression |
||
239 | pop esi |
||
240 | cmp al,'0' |
||
241 | je parse_false_condition_block |
||
242 | cmp al,'1' |
||
243 | jne parse_next_line |
||
244 | stos byte [edi] |
||
245 | jmp parse_next_line |
||
246 | parse_false_condition_block: |
||
109 | heavyiron | 247 | or byte [esp],1 |
157 | heavyiron | 248 | sub edi,4 |
249 | jmp skip_parsing |
||
250 | parse_true_condition_block: |
||
109 | heavyiron | 251 | or byte [esp],100b |
157 | heavyiron | 252 | sub edi,4 |
253 | jmp parse_next_line |
||
254 | parse_else: |
||
109 | heavyiron | 255 | cmp [blocks_stack],0 |
157 | heavyiron | 256 | je unexpected_instruction |
257 | cmp word [esp+2],if_directive-instruction_handler |
||
1189 | heavyiron | 258 | jne unexpected_instruction |
157 | heavyiron | 259 | lods byte [esi] |
260 | or al,al |
||
261 | jz parse_pure_else |
||
262 | cmp al,1Ah |
||
263 | jne extra_characters_on_line |
||
264 | push edi |
||
265 | movzx ecx,byte [esi] |
||
266 | inc esi |
||
267 | call get_instruction |
||
268 | jc extra_characters_on_line |
||
269 | pop edi |
||
270 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 271 | jne extra_characters_on_line |
157 | heavyiron | 272 | test byte [esp],100b |
273 | jnz skip_true_condition_else |
||
274 | mov dl,al |
||
275 | mov al,1 |
||
276 | stos byte [edi] |
||
277 | mov ax,bx |
||
278 | stos word [edi] |
||
279 | mov al,dl |
||
280 | stos byte [edi] |
||
281 | jmp parse_if |
||
282 | parse_assert: |
||
2664 | dunkaist | 283 | push edi |
284 | call parse_line_contents |
||
285 | xor al,al |
||
286 | stos byte [edi] |
||
287 | xchg esi,[esp] |
||
288 | mov edi,esi |
||
289 | call preevaluate_logical_expression |
||
290 | pop esi |
||
291 | or al,al |
||
292 | jz parse_next_line |
||
293 | stos byte [edi] |
||
294 | jmp parse_next_line |
||
295 | skip_true_condition_else: |
||
109 | heavyiron | 296 | sub edi,4 |
157 | heavyiron | 297 | or byte [esp],1 |
298 | jmp skip_parsing_contents |
||
299 | parse_pure_else: |
||
109 | heavyiron | 300 | bts dword [esp],1 |
157 | heavyiron | 301 | jc unexpected_instruction |
302 | test byte [esp],100b |
||
303 | jz parse_next_line |
||
304 | sub edi,4 |
||
305 | or byte [esp],1 |
||
306 | jmp skip_parsing |
||
307 | skip_parsing: |
||
109 | heavyiron | 308 | cmp esi,[source_start] |
157 | heavyiron | 309 | jae source_parsed |
310 | mov [current_line],esi |
||
311 | add esi,16 |
||
312 | skip_parsing_line: |
||
109 | heavyiron | 313 | cmp byte [esi],1Ah |
157 | heavyiron | 314 | jne skip_parsing_contents |
315 | inc esi |
||
316 | movzx ecx,byte [esi] |
||
317 | inc esi |
||
318 | cmp byte [esi+ecx],':' |
||
319 | je skip_parsing_label |
||
320 | push edi |
||
321 | call get_instruction |
||
322 | pop edi |
||
323 | jnc skip_parsing_instruction |
||
324 | add esi,ecx |
||
325 | jmp skip_parsing_contents |
||
326 | skip_parsing_label: |
||
109 | heavyiron | 327 | lea esi,[esi+ecx+1] |
157 | heavyiron | 328 | jmp skip_parsing_line |
329 | skip_parsing_instruction: |
||
109 | heavyiron | 330 | cmp bx,if_directive-instruction_handler |
1189 | heavyiron | 331 | je skip_parsing_block |
157 | heavyiron | 332 | cmp bx,repeat_directive-instruction_handler |
1189 | heavyiron | 333 | je skip_parsing_block |
157 | heavyiron | 334 | cmp bx,while_directive-instruction_handler |
1189 | heavyiron | 335 | je skip_parsing_block |
157 | heavyiron | 336 | cmp bx,end_directive-instruction_handler |
1189 | heavyiron | 337 | je skip_parsing_end_directive |
157 | heavyiron | 338 | cmp bx,else_directive-instruction_handler |
1189 | heavyiron | 339 | je skip_parsing_else |
157 | heavyiron | 340 | skip_parsing_contents: |
109 | heavyiron | 341 | lods byte [esi] |
157 | heavyiron | 342 | or al,al |
343 | jz skip_parsing |
||
344 | cmp al,1Ah |
||
345 | je skip_parsing_symbol |
||
346 | cmp al,3Bh |
||
347 | je skip_parsing_symbol |
||
348 | cmp al,22h |
||
349 | je skip_parsing_string |
||
350 | jmp skip_parsing_contents |
||
351 | skip_parsing_symbol: |
||
109 | heavyiron | 352 | lods byte [esi] |
157 | heavyiron | 353 | movzx eax,al |
354 | add esi,eax |
||
355 | jmp skip_parsing_contents |
||
356 | skip_parsing_string: |
||
109 | heavyiron | 357 | lods dword [esi] |
157 | heavyiron | 358 | add esi,eax |
359 | jmp skip_parsing_contents |
||
360 | skip_parsing_block: |
||
109 | heavyiron | 361 | mov eax,esp |
157 | heavyiron | 362 | sub eax,100h |
363 | jc stack_overflow |
||
364 | cmp eax,[stack_limit] |
||
365 | jb stack_overflow |
||
366 | push [current_line] |
||
367 | mov ax,bx |
||
368 | shl eax,16 |
||
369 | push eax |
||
370 | inc [blocks_stack] |
||
371 | jmp skip_parsing_contents |
||
372 | skip_parsing_end_directive: |
||
109 | heavyiron | 373 | cmp byte [esi],1Ah |
157 | heavyiron | 374 | jne skip_parsing_contents |
375 | push edi |
||
376 | inc esi |
||
377 | movzx ecx,byte [esi] |
||
378 | inc esi |
||
379 | call get_instruction |
||
380 | pop edi |
||
381 | jnc skip_parsing_end_block |
||
382 | add esi,ecx |
||
383 | jmp skip_parsing_contents |
||
384 | skip_parsing_end_block: |
||
109 | heavyiron | 385 | lods byte [esi] |
157 | heavyiron | 386 | or al,al |
387 | jnz extra_characters_on_line |
||
388 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 389 | je close_skip_parsing_block |
157 | heavyiron | 390 | cmp bx,repeat_directive-instruction_handler |
1189 | heavyiron | 391 | je close_skip_parsing_block |
157 | heavyiron | 392 | cmp bx,while_directive-instruction_handler |
1189 | heavyiron | 393 | je close_skip_parsing_block |
157 | heavyiron | 394 | jmp skip_parsing |
395 | close_skip_parsing_block: |
||
109 | heavyiron | 396 | cmp [blocks_stack],0 |
157 | heavyiron | 397 | je unexpected_instruction |
398 | cmp bx,[esp+2] |
||
399 | jne unexpected_instruction |
||
400 | dec [blocks_stack] |
||
401 | pop eax edx |
||
402 | test al,1 |
||
403 | jz skip_parsing |
||
404 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 405 | jne parse_next_line |
157 | heavyiron | 406 | test al,10000b |
407 | jz parse_next_line |
||
408 | mov al,0Fh |
||
409 | stos byte [edi] |
||
410 | mov eax,[current_line] |
||
411 | stos dword [edi] |
||
412 | inc [parsed_lines] |
||
242 | heavyiron | 413 | mov eax,1 + (end_directive-instruction_handler) shl 8 |
1189 | heavyiron | 414 | stos dword [edi] |
157 | heavyiron | 415 | mov eax,1 + (if_directive-instruction_handler) shl 8 |
1189 | heavyiron | 416 | stos dword [edi] |
157 | heavyiron | 417 | jmp parse_next_line |
418 | skip_parsing_else: |
||
109 | heavyiron | 419 | cmp [blocks_stack],0 |
157 | heavyiron | 420 | je unexpected_instruction |
421 | cmp word [esp+2],if_directive-instruction_handler |
||
1189 | heavyiron | 422 | jne unexpected_instruction |
157 | heavyiron | 423 | lods byte [esi] |
424 | or al,al |
||
425 | jz skip_parsing_pure_else |
||
426 | cmp al,1Ah |
||
427 | jne extra_characters_on_line |
||
428 | push edi |
||
429 | movzx ecx,byte [esi] |
||
430 | inc esi |
||
431 | call get_instruction |
||
432 | jc extra_characters_on_line |
||
433 | pop edi |
||
434 | cmp bx,if_directive-instruction_handler |
||
1189 | heavyiron | 435 | jne extra_characters_on_line |
157 | heavyiron | 436 | mov al,[esp] |
437 | test al,1 |
||
438 | jz skip_parsing_contents |
||
439 | test al,100b |
||
440 | jnz skip_parsing_contents |
||
441 | test al,10000b |
||
442 | jnz parse_else_if |
||
443 | xor al,al |
||
444 | mov [esp],al |
||
445 | mov al,0Fh |
||
446 | stos byte [edi] |
||
447 | mov eax,[current_line] |
||
448 | stos dword [edi] |
||
449 | inc [parsed_lines] |
||
242 | heavyiron | 450 | parse_else_if: |
109 | heavyiron | 451 | mov eax,1 + (if_directive-instruction_handler) shl 8 |
1189 | heavyiron | 452 | stos dword [edi] |
157 | heavyiron | 453 | jmp parse_if |
454 | skip_parsing_pure_else: |
||
109 | heavyiron | 455 | bts dword [esp],1 |
157 | heavyiron | 456 | jc unexpected_instruction |
457 | mov al,[esp] |
||
458 | test al,1 |
||
459 | jz skip_parsing |
||
460 | test al,100b |
||
461 | jnz skip_parsing |
||
462 | and al,not 1 |
||
463 | or al,1000b |
||
464 | mov [esp],al |
||
465 | jmp parse_next_line |
||
466 | |||
31 | halyavin | 467 | |
109 | heavyiron | 468 | mov [parenthesis_stack],0 |
157 | heavyiron | 469 | parse_instruction_arguments: |
109 | heavyiron | 470 | cmp bx,prefix_instruction-instruction_handler |
1189 | heavyiron | 471 | je allow_embedded_instruction |
157 | heavyiron | 472 | cmp bx,times_directive-instruction_handler |
1189 | heavyiron | 473 | je parse_times_directive |
157 | heavyiron | 474 | cmp bx,end_directive-instruction_handler |
1189 | heavyiron | 475 | je allow_embedded_instruction |
157 | heavyiron | 476 | cmp bx,label_directive-instruction_handler |
1189 | heavyiron | 477 | je parse_label_directive |
157 | heavyiron | 478 | cmp bx,segment_directive-instruction_handler |
1189 | heavyiron | 479 | je parse_segment_directive |
2287 | heavyiron | 480 | cmp bx,load_directive-instruction_handler |
1189 | heavyiron | 481 | je parse_load_directive |
157 | heavyiron | 482 | cmp bx,extrn_directive-instruction_handler |
1189 | heavyiron | 483 | je parse_extrn_directive |
157 | heavyiron | 484 | cmp bx,public_directive-instruction_handler |
1189 | heavyiron | 485 | je parse_public_directive |
157 | heavyiron | 486 | cmp bx,section_directive-instruction_handler |
2287 | heavyiron | 487 | je parse_formatter_argument |
488 | cmp bx,format_directive-instruction_handler |
||
489 | je parse_formatter_argument |
||
490 | cmp bx,data_directive-instruction_handler |
||
491 | je parse_formatter_argument |
||
492 | jmp parse_argument |
||
493 | parse_formatter_argument: |
||
494 | or [formatter_symbols_allowed],-1 |
||
495 | parse_argument: |
||
109 | heavyiron | 496 | lea eax,[edi+100h] |
157 | heavyiron | 497 | cmp eax,[labels_list] |
498 | jae out_of_memory |
||
499 | lods byte [esi] |
||
500 | cmp al,':' |
||
501 | je instruction_separator |
||
502 | cmp al,',' |
||
503 | je separator |
||
504 | cmp al,'=' |
||
505 | je expression_comparator |
||
2665 | dunkaist | 506 | cmp al,'|' |
157 | heavyiron | 507 | je separator |
508 | cmp al,'&' |
||
509 | je separator |
||
510 | cmp al,'~' |
||
511 | je separator |
||
512 | cmp al,'>' |
||
513 | je greater |
||
514 | cmp al,'<' |
||
515 | je less |
||
516 | cmp al,')' |
||
517 | je close_parenthesis |
||
518 | or al,al |
||
519 | jz contents_parsed |
||
520 | cmp al,'[' |
||
521 | je address_argument |
||
522 | cmp al,']' |
||
523 | je separator |
||
524 | cmp al,'{' |
||
525 | je unallowed_character |
||
526 | cmp al,'}' |
||
527 | je unallowed_character |
||
528 | cmp al,'#' |
||
529 | je unallowed_character |
||
530 | cmp al,'`' |
||
531 | je unallowed_character |
||
532 | dec esi |
||
533 | cmp al,1Ah |
||
534 | jne expression_argument |
||
535 | push edi |
||
536 | mov edi,directive_operators |
||
537 | call get_operator |
||
538 | or al,al |
||
539 | jnz operator_argument |
||
540 | inc esi |
||
541 | movzx ecx,byte [esi] |
||
542 | inc esi |
||
543 | call get_symbol |
||
544 | jnc symbol_argument |
||
545 | cmp ecx,1 |
||
546 | jne check_argument |
||
547 | cmp byte [esi],'?' |
||
548 | jne check_argument |
||
549 | pop edi |
||
550 | movs byte [edi],[esi] |
||
551 | jmp argument_parsed |
||
552 | symbol_argument: |
||
109 | heavyiron | 553 | pop edi |
157 | heavyiron | 554 | stos word [edi] |
555 | jmp argument_parsed |
||
556 | operator_argument: |
||
109 | heavyiron | 557 | pop edi |
157 | heavyiron | 558 | cmp al,85h |
559 | je ptr_argument |
||
560 | stos byte [edi] |
||
561 | cmp al,80h |
||
562 | je forced_expression |
||
563 | cmp al,8Ch |
||
2287 | heavyiron | 564 | je forced_expression |
565 | cmp al,81h |
||
157 | heavyiron | 566 | je forced_parenthesis |
567 | cmp al,82h |
||
568 | je parse_from_operator |
||
569 | cmp al,89h |
||
570 | je parse_label_operator |
||
571 | cmp al,0F8h |
||
2665 | dunkaist | 572 | je forced_expression |
573 | jmp argument_parsed |
||
157 | heavyiron | 574 | instruction_separator: |
2665 | dunkaist | 575 | stos byte [edi] |
576 | allow_embedded_instruction: |
||
109 | heavyiron | 577 | cmp byte [esi],1Ah |
157 | heavyiron | 578 | jne parse_argument |
579 | push edi |
||
580 | inc esi |
||
581 | movzx ecx,byte [esi] |
||
582 | inc esi |
||
583 | call get_instruction |
||
584 | jnc embedded_instruction |
||
585 | call get_data_directive |
||
586 | jnc embedded_instruction |
||
587 | pop edi |
||
588 | sub esi,2 |
||
589 | jmp parse_argument |
||
590 | embedded_instruction: |
||
109 | heavyiron | 591 | pop edi |
157 | heavyiron | 592 | mov dl,al |
593 | mov al,1 |
||
594 | stos byte [edi] |
||
595 | mov ax,bx |
||
596 | stos word [edi] |
||
597 | mov al,dl |
||
598 | stos byte [edi] |
||
599 | jmp parse_instruction_arguments |
||
600 | parse_times_directive: |
||
109 | heavyiron | 601 | mov al,'(' |
157 | heavyiron | 602 | stos byte [edi] |
603 | call convert_expression |
||
604 | mov al,')' |
||
605 | stos byte [edi] |
||
606 | cmp byte [esi],':' |
||
607 | jne allow_embedded_instruction |
||
608 | movs byte [edi],[esi] |
||
609 | jmp allow_embedded_instruction |
||
610 | parse_segment_directive: |
||
2287 | heavyiron | 611 | or [formatter_symbols_allowed],-1 |
612 | parse_label_directive: |
||
31 | halyavin | 613 | cmp byte [esi],1Ah |
157 | heavyiron | 614 | jne argument_parsed |
615 | push esi |
||
616 | inc esi |
||
617 | movzx ecx,byte [esi] |
||
618 | inc esi |
||
619 | call identify_label |
||
620 | pop ebx |
||
621 | cmp eax,0Fh |
||
622 | je non_label_identified |
||
623 | mov byte [edi],2 |
||
624 | inc edi |
||
625 | stos dword [edi] |
||
626 | xor al,al |
||
627 | stos byte [edi] |
||
628 | jmp argument_parsed |
||
629 | non_label_identified: |
||
109 | heavyiron | 630 | mov esi,ebx |
157 | heavyiron | 631 | jmp argument_parsed |
632 | parse_load_directive: |
||
31 | halyavin | 633 | cmp byte [esi],1Ah |
157 | heavyiron | 634 | jne argument_parsed |
635 | push esi |
||
636 | inc esi |
||
637 | movzx ecx,byte [esi] |
||
638 | inc esi |
||
639 | call get_label_id |
||
640 | pop ebx |
||
641 | cmp eax,0Fh |
||
642 | je non_label_identified |
||
643 | mov byte [edi],2 |
||
644 | inc edi |
||
645 | stos dword [edi] |
||
646 | xor al,al |
||
647 | stos byte [edi] |
||
648 | jmp argument_parsed |
||
649 | parse_public_directive: |
||
31 | halyavin | 650 | cmp byte [esi],1Ah |
157 | heavyiron | 651 | jne parse_argument |
652 | inc esi |
||
653 | push esi |
||
654 | movzx ecx,byte [esi] |
||
655 | inc esi |
||
656 | push esi ecx |
||
624 | heavyiron | 657 | push edi |
658 | or [formatter_symbols_allowed],-1 |
||
2287 | heavyiron | 659 | call get_symbol |
624 | heavyiron | 660 | mov [formatter_symbols_allowed],0 |
2287 | heavyiron | 661 | pop edi |
624 | heavyiron | 662 | jc parse_public_label |
663 | cmp al,1Dh |
||
664 | jne parse_public_label |
||
665 | add esp,12 |
||
666 | stos word [edi] |
||
667 | jmp parse_public_directive |
||
668 | parse_public_label: |
||
669 | pop ecx esi |
||
670 | mov al,2 |
||
157 | heavyiron | 671 | stos byte [edi] |
672 | call get_label_id |
||
673 | stos dword [edi] |
||
674 | mov ax,8600h |
||
675 | stos word [edi] |
||
676 | pop ebx |
||
677 | push ebx esi edi |
||
678 | mov edi,directive_operators |
||
679 | call get_operator |
||
680 | pop edi edx ebx |
||
681 | cmp al,86h |
||
682 | je argument_parsed |
||
683 | mov esi,edx |
||
684 | xchg esi,ebx |
||
685 | movzx ecx,byte [esi] |
||
686 | inc esi |
||
687 | mov ax,'(' |
||
688 | stos word [edi] |
||
689 | mov eax,ecx |
||
690 | stos dword [edi] |
||
691 | rep movs byte [edi],[esi] |
||
692 | xor al,al |
||
693 | stos byte [edi] |
||
694 | xchg esi,ebx |
||
695 | jmp argument_parsed |
||
696 | parse_extrn_directive: |
||
31 | halyavin | 697 | cmp byte [esi],22h |
157 | heavyiron | 698 | je parse_quoted_extrn |
699 | cmp byte [esi],1Ah |
||
700 | jne parse_argument |
||
701 | push esi |
||
702 | movzx ecx,byte [esi+1] |
||
703 | add esi,2 |
||
704 | mov ax,'(' |
||
705 | stos word [edi] |
||
706 | mov eax,ecx |
||
707 | stos dword [edi] |
||
708 | rep movs byte [edi],[esi] |
||
709 | mov ax,8600h |
||
710 | stos word [edi] |
||
711 | pop esi |
||
712 | parse_label_operator: |
||
31 | halyavin | 713 | cmp byte [esi],1Ah |
157 | heavyiron | 714 | jne argument_parsed |
715 | inc esi |
||
716 | movzx ecx,byte [esi] |
||
717 | inc esi |
||
718 | mov al,2 |
||
719 | stos byte [edi] |
||
720 | call get_label_id |
||
721 | stos dword [edi] |
||
722 | xor al,al |
||
723 | stos byte [edi] |
||
724 | jmp argument_parsed |
||
725 | parse_from_operator: |
||
31 | halyavin | 726 | cmp byte [esi],22h |
157 | heavyiron | 727 | jne forced_expression |
728 | jmp argument_parsed |
||
729 | parse_quoted_extrn: |
||
31 | halyavin | 730 | inc esi |
157 | heavyiron | 731 | mov ax,'(' |
732 | stos word [edi] |
||
733 | lods dword [esi] |
||
734 | mov ecx,eax |
||
735 | stos dword [edi] |
||
736 | rep movs byte [edi],[esi] |
||
737 | xor al,al |
||
738 | stos byte [edi] |
||
739 | push esi edi |
||
740 | mov edi,directive_operators |
||
741 | call get_operator |
||
742 | mov edx,esi |
||
743 | pop edi esi |
||
744 | cmp al,86h |
||
745 | jne argument_parsed |
||
746 | stos byte [edi] |
||
747 | mov esi,edx |
||
748 | jmp parse_label_operator |
||
749 | ptr_argument: |
||
31 | halyavin | 750 | call parse_address |
157 | heavyiron | 751 | jmp address_parsed |
752 | check_argument: |
||
31 | halyavin | 753 | push esi ecx |
157 | heavyiron | 754 | sub esi,2 |
755 | mov edi,single_operand_operators |
||
756 | call get_operator |
||
757 | pop ecx esi |
||
758 | or al,al |
||
759 | jnz not_instruction |
||
760 | call get_instruction |
||
761 | jnc embedded_instruction |
||
762 | call get_data_directive |
||
763 | jnc embedded_instruction |
||
764 | not_instruction: |
||
31 | halyavin | 765 | pop edi |
157 | heavyiron | 766 | sub esi,2 |
767 | expression_argument: |
||
31 | halyavin | 768 | cmp byte [esi],22h |
157 | heavyiron | 769 | jne not_string |
770 | mov eax,[esi+1] |
||
771 | lea ebx,[esi+5+eax] |
||
772 | push ebx ecx esi edi |
||
773 | mov al,'(' |
||
774 | stos byte [edi] |
||
775 | call convert_expression |
||
776 | mov al,')' |
||
777 | stos byte [edi] |
||
778 | pop eax edx ecx ebx |
||
779 | cmp esi,ebx |
||
780 | jne expression_parsed |
||
781 | mov edi,eax |
||
782 | mov esi,edx |
||
783 | string_argument: |
||
31 | halyavin | 784 | inc esi |
157 | heavyiron | 785 | mov ax,'(' |
786 | stos word [edi] |
||
787 | lods dword [esi] |
||
788 | mov ecx,eax |
||
789 | stos dword [edi] |
||
790 | shr ecx,1 |
||
791 | jnc string_movsb_ok |
||
792 | movs byte [edi],[esi] |
||
793 | string_movsb_ok: |
||
31 | halyavin | 794 | shr ecx,1 |
157 | heavyiron | 795 | jnc string_movsw_ok |
796 | movs word [edi],[esi] |
||
797 | string_movsw_ok: |
||
31 | halyavin | 798 | rep movs dword [edi],[esi] |
157 | heavyiron | 799 | xor al,al |
800 | stos byte [edi] |
||
801 | jmp expression_parsed |
||
802 | not_string: |
||
31 | halyavin | 803 | cmp byte [esi],'(' |
157 | heavyiron | 804 | jne expression |
805 | mov eax,esp |
||
806 | sub eax,100h |
||
807 | jc stack_overflow |
||
808 | cmp eax,[stack_limit] |
||
809 | jb stack_overflow |
||
810 | push esi edi |
||
811 | inc esi |
||
812 | mov al,'{' |
||
813 | stos byte [edi] |
||
814 | inc [parenthesis_stack] |
||
815 | jmp parse_argument |
||
816 | expression_comparator: |
||
2665 | dunkaist | 817 | stos byte [edi] |
818 | jmp forced_expression |
||
819 | greater: |
||
820 | cmp byte [esi],'=' |
||
821 | jne separator |
||
822 | inc esi |
||
823 | mov al,0F2h |
||
824 | jmp separator |
||
825 | less: |
||
826 | cmp byte [edi-1],0F6h |
||
827 | je separator |
||
828 | cmp byte [esi],'>' |
||
829 | je not_equal |
||
830 | cmp byte [esi],'=' |
||
831 | jne separator |
||
832 | inc esi |
||
833 | mov al,0F3h |
||
834 | jmp separator |
||
835 | not_equal: |
||
836 | inc esi |
||
837 | mov al,0F1h |
||
838 | jmp expression_comparator |
||
839 | expression: |
||
31 | halyavin | 840 | mov al,'(' |
157 | heavyiron | 841 | stos byte [edi] |
842 | call convert_expression |
||
843 | mov al,')' |
||
844 | stos byte [edi] |
||
845 | jmp expression_parsed |
||
846 | forced_expression: |
||
31 | halyavin | 847 | xor al,al |
2287 | heavyiron | 848 | xchg al,[formatter_symbols_allowed] |
849 | push eax |
||
850 | mov al,'(' |
||
157 | heavyiron | 851 | stos byte [edi] |
852 | call convert_expression |
||
853 | mov al,')' |
||
854 | stos byte [edi] |
||
855 | pop eax |
||
2287 | heavyiron | 856 | mov [formatter_symbols_allowed],al |
857 | jmp argument_parsed |
||
157 | heavyiron | 858 | address_argument: |
31 | halyavin | 859 | call parse_address |
157 | heavyiron | 860 | lods byte [esi] |
861 | cmp al,']' |
||
862 | je address_parsed |
||
863 | dec esi |
||
864 | mov al,')' |
||
865 | stos byte [edi] |
||
866 | jmp argument_parsed |
||
867 | address_parsed: |
||
31 | halyavin | 868 | mov al,']' |
157 | heavyiron | 869 | stos byte [edi] |
870 | jmp argument_parsed |
||
871 | parse_address: |
||
31 | halyavin | 872 | mov al,'[' |
157 | heavyiron | 873 | stos byte [edi] |
874 | cmp word [esi],021Ah |
||
875 | jne convert_address |
||
876 | push esi |
||
877 | add esi,4 |
||
878 | lea ebx,[esi+1] |
||
879 | cmp byte [esi],':' |
||
880 | pop esi |
||
881 | jne convert_address |
||
882 | add esi,2 |
||
883 | mov ecx,2 |
||
884 | push ebx edi |
||
885 | call get_symbol |
||
886 | pop edi esi |
||
887 | jc unknown_segment_prefix |
||
888 | cmp al,10h |
||
889 | jne unknown_segment_prefix |
||
890 | mov al,ah |
||
891 | and ah,11110000b |
||
892 | cmp ah,60h |
||
893 | jne unknown_segment_prefix |
||
894 | stos byte [edi] |
||
895 | jmp convert_address |
||
896 | unknown_segment_prefix: |
||
109 | heavyiron | 897 | sub esi,5 |
157 | heavyiron | 898 | convert_address: |
31 | halyavin | 899 | push edi |
157 | heavyiron | 900 | mov edi,address_sizes |
901 | call get_operator |
||
902 | pop edi |
||
903 | or al,al |
||
904 | jz convert_expression |
||
905 | add al,70h |
||
906 | stos byte [edi] |
||
907 | jmp convert_expression |
||
908 | forced_parenthesis: |
||
31 | halyavin | 909 | cmp byte [esi],'(' |
157 | heavyiron | 910 | jne argument_parsed |
911 | inc esi |
||
912 | mov al,'{' |
||
913 | jmp separator |
||
914 | unallowed_character: |
||
31 | halyavin | 915 | mov al,0FFh |
157 | heavyiron | 916 | jmp separator |
917 | close_parenthesis: |
||
31 | halyavin | 918 | mov al,'}' |
157 | heavyiron | 919 | separator: |
31 | halyavin | 920 | stos byte [edi] |
157 | heavyiron | 921 | argument_parsed: |
31 | halyavin | 922 | cmp [parenthesis_stack],0 |
157 | heavyiron | 923 | je parse_argument |
924 | dec [parenthesis_stack] |
||
925 | add esp,8 |
||
926 | jmp argument_parsed |
||
927 | expression_parsed: |
||
31 | halyavin | 928 | cmp [parenthesis_stack],0 |
157 | heavyiron | 929 | je parse_argument |
930 | cmp byte [esi],')' |
||
931 | jne argument_parsed |
||
932 | dec [parenthesis_stack] |
||
933 | pop edi esi |
||
934 | jmp expression |
||
935 | contents_parsed: |
||
109 | heavyiron | 936 | cmp [parenthesis_stack],0 |
157 | heavyiron | 937 | je contents_ok |
242 | heavyiron | 938 | dec [parenthesis_stack] |
939 | add esp,8 |
||
940 | jmp contents_parsed |
||
941 | contents_ok: |
||
942 | ret |
||
157 | heavyiron | 943 | |
31 | halyavin | 944 | |
109 | heavyiron | 945 | cmp byte [esi],'.' |
157 | heavyiron | 946 | je local_label_name |
947 | call get_label_id |
||
948 | cmp eax,10h |
||
949 | jb label_identified |
||
950 | or ebx,ebx |
||
951 | jz anonymous_label_name |
||
952 | dec ebx |
||
953 | mov [current_locals_prefix],ebx |
||
954 | label_identified: |
||
109 | heavyiron | 955 | ret |
157 | heavyiron | 956 | anonymous_label_name: |
109 | heavyiron | 957 | cmp byte [esi-1],'@' |
157 | heavyiron | 958 | je anonymous_label_name_ok |
959 | mov eax,0Fh |
||
960 | anonymous_label_name_ok: |
||
109 | heavyiron | 961 | ret |
157 | heavyiron | 962 | local_label_name: |
109 | heavyiron | 963 | call get_label_id |
157 | heavyiron | 964 | ret |
965 | |||
109 | heavyiron | 966 | |
31 | halyavin | 967 | cmp byte [esi],1Ah |
157 | heavyiron | 968 | jne get_simple_operator |
969 | mov edx,esi |
||
970 | push ebp |
||
971 | inc esi |
||
972 | lods byte [esi] |
||
973 | movzx ebp,al |
||
974 | push edi |
||
975 | mov ecx,ebp |
||
976 | call lower_case |
||
977 | pop edi |
||
978 | check_operator: |
||
31 | halyavin | 979 | mov esi,converted |
157 | heavyiron | 980 | movzx ecx,byte [edi] |
981 | jecxz no_operator |
||
982 | inc edi |
||
983 | mov ebx,edi |
||
984 | add ebx,ecx |
||
985 | cmp ecx,ebp |
||
986 | jne next_operator |
||
987 | repe cmps byte [esi],[edi] |
||
988 | je operator_found |
||
989 | jb no_operator |
||
2665 | dunkaist | 990 | next_operator: |
31 | halyavin | 991 | mov edi,ebx |
157 | heavyiron | 992 | inc edi |
993 | jmp check_operator |
||
994 | no_operator: |
||
31 | halyavin | 995 | mov esi,edx |
157 | heavyiron | 996 | mov ecx,ebp |
997 | pop ebp |
||
998 | no_simple_operator: |
||
31 | halyavin | 999 | xor al,al |
157 | heavyiron | 1000 | ret |
1001 | operator_found: |
||
31 | halyavin | 1002 | lea esi,[edx+2+ebp] |
157 | heavyiron | 1003 | mov ecx,ebp |
1004 | pop ebp |
||
1005 | mov al,[edi] |
||
1006 | ret |
||
1007 | get_simple_operator: |
||
31 | halyavin | 1008 | mov al,[esi] |
157 | heavyiron | 1009 | cmp al,22h |
1010 | je no_simple_operator |
||
1011 | simple_operator: |
||
31 | halyavin | 1012 | cmp byte [edi],1 |
157 | heavyiron | 1013 | jb no_simple_operator |
1014 | ja simple_next_operator |
||
1015 | cmp al,[edi+1] |
||
1016 | je simple_operator_found |
||
1017 | simple_next_operator: |
||
31 | halyavin | 1018 | movzx ecx,byte [edi] |
157 | heavyiron | 1019 | lea edi,[edi+1+ecx+1] |
1020 | jmp simple_operator |
||
1021 | simple_operator_found: |
||
31 | halyavin | 1022 | inc esi |
157 | heavyiron | 1023 | mov al,[edi+2] |
1024 | ret |
||
1025 | |||
31 | halyavin | 1026 | |
1027 | push esi |
||
157 | heavyiron | 1028 | mov ebp,ecx |
1029 | call lower_case |
||
1030 | mov ecx,ebp |
||
1031 | cmp cl,11 |
||
1032 | ja no_symbol |
||
1033 | sub cl,2 |
||
1034 | jc no_symbol |
||
1035 | movzx ebx,word [symbols+ecx*4] |
||
1036 | add ebx,symbols |
||
1037 | movzx edx,word [symbols+ecx*4+2] |
||
1038 | scan_symbols: |
||
31 | halyavin | 1039 | or edx,edx |
157 | heavyiron | 1040 | jz no_symbol |
1041 | mov eax,edx |
||
1042 | shr eax,1 |
||
1043 | lea edi,[ebp+2] |
||
1044 | imul eax,edi |
||
1045 | lea edi,[ebx+eax] |
||
1046 | mov esi,converted |
||
1047 | mov ecx,ebp |
||
1048 | repe cmps byte [esi],[edi] |
||
1049 | ja symbols_up |
||
1050 | jb symbols_down |
||
1051 | mov ax,[edi] |
||
2287 | heavyiron | 1052 | cmp al,18h |
1053 | jb symbol_ok |
||
1054 | cmp [formatter_symbols_allowed],0 |
||
1055 | je no_symbol |
||
1056 | symbol_ok: |
||
1057 | pop esi |
||
157 | heavyiron | 1058 | add esi,ebp |
1059 | clc |
||
1060 | ret |
||
1061 | no_symbol: |
||
31 | halyavin | 1062 | pop esi |
157 | heavyiron | 1063 | mov ecx,ebp |
1064 | stc |
||
1065 | ret |
||
1066 | symbols_down: |
||
109 | heavyiron | 1067 | shr edx,1 |
157 | heavyiron | 1068 | jmp scan_symbols |
1069 | symbols_up: |
||
109 | heavyiron | 1070 | lea ebx,[edi+ecx+2] |
157 | heavyiron | 1071 | shr edx,1 |
1072 | adc edx,-1 |
||
1073 | jmp scan_symbols |
||
1074 | |||
31 | halyavin | 1075 | |
109 | heavyiron | 1076 | push esi |
157 | heavyiron | 1077 | mov ebp,ecx |
1078 | call lower_case |
||
1079 | mov ecx,ebp |
||
1080 | cmp cl,4 |
||
1081 | ja no_instruction |
||
1082 | sub cl,2 |
||
1083 | jc no_instruction |
||
1084 | movzx ebx,word [data_directives+ecx*4] |
||
1085 | add ebx,data_directives |
||
1086 | movzx edx,word [data_directives+ecx*4+2] |
||
1087 | jmp scan_instructions |
||
1088 | |||
109 | heavyiron | 1089 | |
31 | halyavin | 1090 | push esi |
157 | heavyiron | 1091 | mov ebp,ecx |
1092 | call lower_case |
||
1093 | mov ecx,ebp |
||
1094 | cmp cl,16 |
||
2287 | heavyiron | 1095 | ja no_instruction |
157 | heavyiron | 1096 | sub cl,2 |
1097 | jc no_instruction |
||
1098 | movzx ebx,word [instructions+ecx*4] |
||
1099 | add ebx,instructions |
||
1100 | movzx edx,word [instructions+ecx*4+2] |
||
1101 | scan_instructions: |
||
31 | halyavin | 1102 | or edx,edx |
157 | heavyiron | 1103 | jz no_instruction |
1104 | mov eax,edx |
||
1105 | shr eax,1 |
||
1106 | lea edi,[ebp+3] |
||
1107 | imul eax,edi |
||
1108 | lea edi,[ebx+eax] |
||
1109 | mov esi,converted |
||
1110 | mov ecx,ebp |
||
1111 | repe cmps byte [esi],[edi] |
||
1112 | ja instructions_up |
||
1113 | jb instructions_down |
||
1114 | pop esi |
||
1115 | add esi,ebp |
||
1116 | mov al,[edi] |
||
1117 | mov bx,[edi+1] |
||
1118 | clc |
||
1119 | ret |
||
1120 | no_instruction: |
||
31 | halyavin | 1121 | pop esi |
157 | heavyiron | 1122 | mov ecx,ebp |
1123 | stc |
||
1124 | ret |
||
1125 | instructions_down: |
||
109 | heavyiron | 1126 | shr edx,1 |
157 | heavyiron | 1127 | jmp scan_instructions |
1128 | instructions_up: |
||
109 | heavyiron | 1129 | lea ebx,[edi+ecx+3] |
157 | heavyiron | 1130 | shr edx,1 |
1131 | adc edx,-1 |
||
1132 | jmp scan_instructions |
||
1133 | |||
31 | halyavin | 1134 | |
1135 | cmp ecx,100h |
||
157 | heavyiron | 1136 | jae name_too_long |
1137 | cmp byte [esi],'@' |
||
1138 | je anonymous_label |
||
1139 | cmp byte [esi],'.' |
||
1140 | jne standard_label |
||
1141 | cmp byte [esi+1],'.' |
||
1142 | je standard_label |
||
1143 | cmp [current_locals_prefix],0 |
||
1144 | je standard_label |
||
1145 | push edi |
||
1146 | mov edi,[additional_memory_end] |
||
1147 | sub edi,2 |
||
1148 | sub edi,ecx |
||
1149 | push ecx esi |
||
1150 | mov esi,[current_locals_prefix] |
||
1151 | lods byte [esi] |
||
1152 | movzx ecx,al |
||
1153 | sub edi,ecx |
||
1154 | cmp edi,[free_additional_memory] |
||
1155 | jb out_of_memory |
||
1156 | mov word [edi],0 |
||
1157 | add edi,2 |
||
1158 | mov ebx,edi |
||
1159 | rep movs byte [edi],[esi] |
||
1160 | pop esi ecx |
||
1161 | add al,cl |
||
1162 | jc name_too_long |
||
1163 | rep movs byte [edi],[esi] |
||
1164 | pop edi |
||
1165 | push ebx esi |
||
1166 | movzx ecx,al |
||
1167 | mov byte [ebx-1],al |
||
1168 | mov esi,ebx |
||
1169 | call get_label_id |
||
1170 | pop esi ebx |
||
1171 | cmp ebx,[eax+24] |
||
1172 | jne composed_label_id_ok |
||
1173 | lea edx,[ebx-2] |
||
1174 | mov [additional_memory_end],edx |
||
1175 | composed_label_id_ok: |
||
109 | heavyiron | 1176 | ret |
157 | heavyiron | 1177 | anonymous_label: |
31 | halyavin | 1178 | cmp ecx,2 |
157 | heavyiron | 1179 | jne standard_label |
1180 | mov al,[esi+1] |
||
1181 | mov ebx,characters |
||
1182 | xlat byte [ebx] |
||
1183 | cmp al,'@' |
||
1184 | je new_anonymous |
||
1185 | cmp al,'b' |
||
1186 | je anonymous_back |
||
1187 | cmp al,'r' |
||
1188 | je anonymous_back |
||
1189 | cmp al,'f' |
||
1190 | jne standard_label |
||
1191 | add esi,2 |
||
1192 | mov eax,[anonymous_forward] |
||
1193 | or eax,eax |
||
1194 | jnz anonymous_ok |
||
1195 | mov eax,[current_line] |
||
1196 | mov [error_line],eax |
||
1197 | call allocate_label |
||
1198 | mov [anonymous_forward],eax |
||
1199 | anonymous_ok: |
||
31 | halyavin | 1200 | xor ebx,ebx |
157 | heavyiron | 1201 | ret |
1202 | anonymous_back: |
||
31 | halyavin | 1203 | mov eax,[anonymous_reverse] |
157 | heavyiron | 1204 | add esi,2 |
2287 | heavyiron | 1205 | or eax,eax |
157 | heavyiron | 1206 | jz bogus_anonymous |
2287 | heavyiron | 1207 | jmp anonymous_ok |
157 | heavyiron | 1208 | bogus_anonymous: |
2287 | heavyiron | 1209 | call allocate_label |
1210 | mov [anonymous_reverse],eax |
||
1211 | jmp anonymous_ok |
||
1212 | new_anonymous: |
||
31 | halyavin | 1213 | add esi,2 |
157 | heavyiron | 1214 | mov eax,[anonymous_forward] |
1215 | or eax,eax |
||
1216 | jnz new_anonymous_ok |
||
1217 | call allocate_label |
||
1218 | new_anonymous_ok: |
||
31 | halyavin | 1219 | mov [anonymous_reverse],eax |
157 | heavyiron | 1220 | mov [anonymous_forward],0 |
1221 | jmp anonymous_ok |
||
1222 | standard_label: |
||
31 | halyavin | 1223 | cmp byte [esi],'%' |
157 | heavyiron | 1224 | je get_predefined_id |
1225 | cmp byte [esi],'$' |
||
1226 | je current_address_label |
||
2287 | heavyiron | 1227 | cmp byte [esi],'?' |
1228 | jne find_label |
||
157 | heavyiron | 1229 | cmp ecx,1 |
2287 | heavyiron | 1230 | jne find_label |
1231 | inc esi |
||
1232 | mov eax,0Fh |
||
1233 | ret |
||
1234 | current_address_label: |
||
1235 | cmp ecx,2 |
||
157 | heavyiron | 1236 | ja find_label |
1237 | inc esi |
||
1238 | jb get_current_offset_id |
||
1239 | inc esi |
||
1240 | cmp byte [esi-1],'$' |
||
1241 | je get_org_origin_id |
||
1242 | sub esi,ecx |
||
1243 | jmp find_label |
||
1244 | get_current_offset_id: |
||
31 | halyavin | 1245 | xor eax,eax |
157 | heavyiron | 1246 | ret |
1247 | get_counter_id: |
||
31 | halyavin | 1248 | mov eax,1 |
157 | heavyiron | 1249 | ret |
1250 | get_timestamp_id: |
||
31 | halyavin | 1251 | mov eax,2 |
157 | heavyiron | 1252 | ret |
1253 | get_org_origin_id: |
||
31 | halyavin | 1254 | mov eax,3 |
157 | heavyiron | 1255 | ret |
1256 | get_predefined_id: |
||
31 | halyavin | 1257 | cmp ecx,2 |
157 | heavyiron | 1258 | ja find_label |
1259 | inc esi |
||
1260 | cmp cl,1 |
||
1261 | je get_counter_id |
||
1262 | lods byte [esi] |
||
1263 | mov ebx,characters |
||
1264 | xlat [ebx] |
||
1265 | cmp al,'t' |
||
1266 | je get_timestamp_id |
||
1267 | sub esi,2 |
||
1268 | find_label: |
||
31 | halyavin | 1269 | xor ebx,ebx |
157 | heavyiron | 1270 | mov eax,2166136261 |
1271 | mov ebp,16777619 |
||
1272 | hash_label: |
||
31 | halyavin | 1273 | xor al,[esi+ebx] |
157 | heavyiron | 1274 | mul ebp |
1275 | inc bl |
||
1276 | cmp bl,cl |
||
1277 | jb hash_label |
||
1278 | mov ebp,eax |
||
1279 | shl eax,8 |
||
1280 | and ebp,0FFh shl 24 |
||
1281 | xor ebp,eax |
||
1282 | or ebp,ebx |
||
1283 | mov [label_hash],ebp |
||
1284 | push edi esi |
||
1285 | push ecx |
||
1286 | mov ecx,32 |
||
1287 | mov ebx,hash_tree |
||
1288 | follow_tree: |
||
31 | halyavin | 1289 | mov edx,[ebx] |
157 | heavyiron | 1290 | or edx,edx |
1291 | jz extend_tree |
||
1292 | xor eax,eax |
||
1293 | shl ebp,1 |
||
1294 | adc eax,0 |
||
1295 | lea ebx,[edx+eax*4] |
||
1296 | dec ecx |
||
1297 | jnz follow_tree |
||
1298 | mov [label_leaf],ebx |
||
1299 | pop edx |
||
1300 | mov eax,[ebx] |
||
1301 | or eax,eax |
||
1302 | jz add_label |
||
1303 | mov ebx,esi |
||
1304 | mov ebp,[label_hash] |
||
1305 | compare_labels: |
||
31 | halyavin | 1306 | mov esi,ebx |
157 | heavyiron | 1307 | mov ecx,edx |
1308 | mov edi,[eax+4] |
||
1309 | mov edi,[edi+24] |
||
1310 | repe cmps byte [esi],[edi] |
||
1311 | je label_found |
||
1312 | mov eax,[eax] |
||
1313 | or eax,eax |
||
1314 | jnz compare_labels |
||
1315 | jmp add_label |
||
1316 | label_found: |
||
31 | halyavin | 1317 | add esp,4 |
157 | heavyiron | 1318 | pop edi |
1319 | mov eax,[eax+4] |
||
1320 | ret |
||
1321 | extend_tree: |
||
31 | halyavin | 1322 | mov edx,[free_additional_memory] |
157 | heavyiron | 1323 | lea eax,[edx+8] |
1324 | cmp eax,[additional_memory_end] |
||
1325 | ja out_of_memory |
||
1326 | mov [free_additional_memory],eax |
||
1327 | xor eax,eax |
||
1328 | mov [edx],eax |
||
1329 | mov [edx+4],eax |
||
1330 | shl ebp,1 |
||
1331 | adc eax,0 |
||
1332 | mov [ebx],edx |
||
1333 | lea ebx,[edx+eax*4] |
||
1334 | dec ecx |
||
1335 | jnz extend_tree |
||
1336 | mov [label_leaf],ebx |
||
1337 | pop edx |
||
1338 | add_label: |
||
31 | halyavin | 1339 | mov ecx,edx |
157 | heavyiron | 1340 | pop esi |
1341 | cmp byte [esi-2],0 |
||
1342 | je label_name_ok |
||
1343 | mov al,[esi] |
||
1344 | cmp al,30h |
||
1345 | jb name_first_char_ok |
||
1346 | cmp al,39h |
||
1347 | jbe invalid_name |
||
1348 | name_first_char_ok: |
||
31 | halyavin | 1349 | cmp al,'$' |
340 | heavyiron | 1350 | jne check_for_reserved_word |
1351 | cmp ecx,1 |
||
157 | heavyiron | 1352 | jne invalid_name |
340 | heavyiron | 1353 | reserved_word: |
1354 | mov eax,0Fh |
||
1355 | pop edi |
||
1356 | ret |
||
1357 | check_for_reserved_word: |
||
31 | halyavin | 1358 | call get_instruction |
157 | heavyiron | 1359 | jnc reserved_word |
1360 | call get_data_directive |
||
1361 | jnc reserved_word |
||
1362 | call get_symbol |
||
1363 | jnc reserved_word |
||
1364 | sub esi,2 |
||
1365 | mov edi,operators |
||
1366 | call get_operator |
||
1367 | or al,al |
||
1368 | jnz reserved_word |
||
1369 | mov edi,single_operand_operators |
||
1370 | call get_operator |
||
1371 | or al,al |
||
1372 | jnz reserved_word |
||
1373 | mov edi,directive_operators |
||
1374 | call get_operator |
||
1375 | or al,al |
||
1376 | jnz reserved_word |
||
1377 | inc esi |
||
1378 | movzx ecx,byte [esi] |
||
1379 | inc esi |
||
1380 | label_name_ok: |
||
31 | halyavin | 1381 | mov edx,[free_additional_memory] |
157 | heavyiron | 1382 | lea eax,[edx+8] |
1383 | cmp eax,[additional_memory_end] |
||
1384 | ja out_of_memory |
||
1385 | mov [free_additional_memory],eax |
||
1386 | mov ebx,esi |
||
1387 | add esi,ecx |
||
1388 | mov eax,[label_leaf] |
||
1389 | mov edi,[eax] |
||
1390 | mov [edx],edi |
||
1391 | mov [eax],edx |
||
1392 | call allocate_label |
||
1393 | mov [edx+4],eax |
||
1394 | mov [eax+24],ebx |
||
1395 | pop edi |
||
1396 | ret |
||
1397 | allocate_label: |
||
109 | heavyiron | 1398 | mov eax,[labels_list] |
157 | heavyiron | 1399 | mov ecx,LABEL_STRUCTURE_SIZE shr 2 |
1400 | initialize_label: |
||
109 | heavyiron | 1401 | sub eax,4 |
157 | heavyiron | 1402 | mov dword [eax],0 |
1403 | loop initialize_label |
||
1404 | mov [labels_list],eax |
||
1405 | ret |
||
1406 | |||
31 | halyavin | 1407 | |
109 | heavyiron | 1408 | > |