Rev 2287 | 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 separator |
||
506 | cmp al,'|' |
||
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 | jmp argument_parsed |
||
572 | allow_embedded_instruction: |
||
109 | heavyiron | 573 | cmp byte [esi],1Ah |
157 | heavyiron | 574 | jne parse_argument |
575 | push edi |
||
576 | inc esi |
||
577 | movzx ecx,byte [esi] |
||
578 | inc esi |
||
579 | call get_instruction |
||
580 | jnc embedded_instruction |
||
581 | call get_data_directive |
||
582 | jnc embedded_instruction |
||
583 | pop edi |
||
584 | sub esi,2 |
||
585 | jmp parse_argument |
||
586 | embedded_instruction: |
||
109 | heavyiron | 587 | pop edi |
157 | heavyiron | 588 | mov dl,al |
589 | mov al,1 |
||
590 | stos byte [edi] |
||
591 | mov ax,bx |
||
592 | stos word [edi] |
||
593 | mov al,dl |
||
594 | stos byte [edi] |
||
595 | jmp parse_instruction_arguments |
||
596 | parse_times_directive: |
||
109 | heavyiron | 597 | mov al,'(' |
157 | heavyiron | 598 | stos byte [edi] |
599 | call convert_expression |
||
600 | mov al,')' |
||
601 | stos byte [edi] |
||
602 | cmp byte [esi],':' |
||
603 | jne allow_embedded_instruction |
||
604 | movs byte [edi],[esi] |
||
605 | jmp allow_embedded_instruction |
||
606 | parse_segment_directive: |
||
2287 | heavyiron | 607 | or [formatter_symbols_allowed],-1 |
608 | parse_label_directive: |
||
31 | halyavin | 609 | cmp byte [esi],1Ah |
157 | heavyiron | 610 | jne argument_parsed |
611 | push esi |
||
612 | inc esi |
||
613 | movzx ecx,byte [esi] |
||
614 | inc esi |
||
615 | call identify_label |
||
616 | pop ebx |
||
617 | cmp eax,0Fh |
||
618 | je non_label_identified |
||
619 | mov byte [edi],2 |
||
620 | inc edi |
||
621 | stos dword [edi] |
||
622 | xor al,al |
||
623 | stos byte [edi] |
||
624 | jmp argument_parsed |
||
625 | non_label_identified: |
||
109 | heavyiron | 626 | mov esi,ebx |
157 | heavyiron | 627 | jmp argument_parsed |
628 | parse_load_directive: |
||
31 | halyavin | 629 | cmp byte [esi],1Ah |
157 | heavyiron | 630 | jne argument_parsed |
631 | push esi |
||
632 | inc esi |
||
633 | movzx ecx,byte [esi] |
||
634 | inc esi |
||
635 | call get_label_id |
||
636 | pop ebx |
||
637 | cmp eax,0Fh |
||
638 | je non_label_identified |
||
639 | mov byte [edi],2 |
||
640 | inc edi |
||
641 | stos dword [edi] |
||
642 | xor al,al |
||
643 | stos byte [edi] |
||
644 | jmp argument_parsed |
||
645 | parse_public_directive: |
||
31 | halyavin | 646 | cmp byte [esi],1Ah |
157 | heavyiron | 647 | jne parse_argument |
648 | inc esi |
||
649 | push esi |
||
650 | movzx ecx,byte [esi] |
||
651 | inc esi |
||
652 | push esi ecx |
||
624 | heavyiron | 653 | push edi |
654 | or [formatter_symbols_allowed],-1 |
||
2287 | heavyiron | 655 | call get_symbol |
624 | heavyiron | 656 | mov [formatter_symbols_allowed],0 |
2287 | heavyiron | 657 | pop edi |
624 | heavyiron | 658 | jc parse_public_label |
659 | cmp al,1Dh |
||
660 | jne parse_public_label |
||
661 | add esp,12 |
||
662 | stos word [edi] |
||
663 | jmp parse_public_directive |
||
664 | parse_public_label: |
||
665 | pop ecx esi |
||
666 | mov al,2 |
||
157 | heavyiron | 667 | stos byte [edi] |
668 | call get_label_id |
||
669 | stos dword [edi] |
||
670 | mov ax,8600h |
||
671 | stos word [edi] |
||
672 | pop ebx |
||
673 | push ebx esi edi |
||
674 | mov edi,directive_operators |
||
675 | call get_operator |
||
676 | pop edi edx ebx |
||
677 | cmp al,86h |
||
678 | je argument_parsed |
||
679 | mov esi,edx |
||
680 | xchg esi,ebx |
||
681 | movzx ecx,byte [esi] |
||
682 | inc esi |
||
683 | mov ax,'(' |
||
684 | stos word [edi] |
||
685 | mov eax,ecx |
||
686 | stos dword [edi] |
||
687 | rep movs byte [edi],[esi] |
||
688 | xor al,al |
||
689 | stos byte [edi] |
||
690 | xchg esi,ebx |
||
691 | jmp argument_parsed |
||
692 | parse_extrn_directive: |
||
31 | halyavin | 693 | cmp byte [esi],22h |
157 | heavyiron | 694 | je parse_quoted_extrn |
695 | cmp byte [esi],1Ah |
||
696 | jne parse_argument |
||
697 | push esi |
||
698 | movzx ecx,byte [esi+1] |
||
699 | add esi,2 |
||
700 | mov ax,'(' |
||
701 | stos word [edi] |
||
702 | mov eax,ecx |
||
703 | stos dword [edi] |
||
704 | rep movs byte [edi],[esi] |
||
705 | mov ax,8600h |
||
706 | stos word [edi] |
||
707 | pop esi |
||
708 | parse_label_operator: |
||
31 | halyavin | 709 | cmp byte [esi],1Ah |
157 | heavyiron | 710 | jne argument_parsed |
711 | inc esi |
||
712 | movzx ecx,byte [esi] |
||
713 | inc esi |
||
714 | mov al,2 |
||
715 | stos byte [edi] |
||
716 | call get_label_id |
||
717 | stos dword [edi] |
||
718 | xor al,al |
||
719 | stos byte [edi] |
||
720 | jmp argument_parsed |
||
721 | parse_from_operator: |
||
31 | halyavin | 722 | cmp byte [esi],22h |
157 | heavyiron | 723 | jne forced_expression |
724 | jmp argument_parsed |
||
725 | parse_quoted_extrn: |
||
31 | halyavin | 726 | inc esi |
157 | heavyiron | 727 | mov ax,'(' |
728 | stos word [edi] |
||
729 | lods dword [esi] |
||
730 | mov ecx,eax |
||
731 | stos dword [edi] |
||
732 | rep movs byte [edi],[esi] |
||
733 | xor al,al |
||
734 | stos byte [edi] |
||
735 | push esi edi |
||
736 | mov edi,directive_operators |
||
737 | call get_operator |
||
738 | mov edx,esi |
||
739 | pop edi esi |
||
740 | cmp al,86h |
||
741 | jne argument_parsed |
||
742 | stos byte [edi] |
||
743 | mov esi,edx |
||
744 | jmp parse_label_operator |
||
745 | ptr_argument: |
||
31 | halyavin | 746 | call parse_address |
157 | heavyiron | 747 | jmp address_parsed |
748 | check_argument: |
||
31 | halyavin | 749 | push esi ecx |
157 | heavyiron | 750 | sub esi,2 |
751 | mov edi,single_operand_operators |
||
752 | call get_operator |
||
753 | pop ecx esi |
||
754 | or al,al |
||
755 | jnz not_instruction |
||
756 | call get_instruction |
||
757 | jnc embedded_instruction |
||
758 | call get_data_directive |
||
759 | jnc embedded_instruction |
||
760 | not_instruction: |
||
31 | halyavin | 761 | pop edi |
157 | heavyiron | 762 | sub esi,2 |
763 | expression_argument: |
||
31 | halyavin | 764 | cmp byte [esi],22h |
157 | heavyiron | 765 | jne not_string |
766 | mov eax,[esi+1] |
||
767 | lea ebx,[esi+5+eax] |
||
768 | push ebx ecx esi edi |
||
769 | mov al,'(' |
||
770 | stos byte [edi] |
||
771 | call convert_expression |
||
772 | mov al,')' |
||
773 | stos byte [edi] |
||
774 | pop eax edx ecx ebx |
||
775 | cmp esi,ebx |
||
776 | jne expression_parsed |
||
777 | mov edi,eax |
||
778 | mov esi,edx |
||
779 | string_argument: |
||
31 | halyavin | 780 | inc esi |
157 | heavyiron | 781 | mov ax,'(' |
782 | stos word [edi] |
||
783 | lods dword [esi] |
||
784 | mov ecx,eax |
||
785 | stos dword [edi] |
||
786 | shr ecx,1 |
||
787 | jnc string_movsb_ok |
||
788 | movs byte [edi],[esi] |
||
789 | string_movsb_ok: |
||
31 | halyavin | 790 | shr ecx,1 |
157 | heavyiron | 791 | jnc string_movsw_ok |
792 | movs word [edi],[esi] |
||
793 | string_movsw_ok: |
||
31 | halyavin | 794 | rep movs dword [edi],[esi] |
157 | heavyiron | 795 | xor al,al |
796 | stos byte [edi] |
||
797 | jmp expression_parsed |
||
798 | not_string: |
||
31 | halyavin | 799 | cmp byte [esi],'(' |
157 | heavyiron | 800 | jne expression |
801 | mov eax,esp |
||
802 | sub eax,100h |
||
803 | jc stack_overflow |
||
804 | cmp eax,[stack_limit] |
||
805 | jb stack_overflow |
||
806 | push esi edi |
||
807 | inc esi |
||
808 | mov al,'{' |
||
809 | stos byte [edi] |
||
810 | inc [parenthesis_stack] |
||
811 | jmp parse_argument |
||
812 | expression: |
||
31 | halyavin | 813 | mov al,'(' |
157 | heavyiron | 814 | stos byte [edi] |
815 | call convert_expression |
||
816 | mov al,')' |
||
817 | stos byte [edi] |
||
818 | jmp expression_parsed |
||
819 | forced_expression: |
||
31 | halyavin | 820 | xor al,al |
2287 | heavyiron | 821 | xchg al,[formatter_symbols_allowed] |
822 | push eax |
||
823 | mov al,'(' |
||
157 | heavyiron | 824 | stos byte [edi] |
825 | call convert_expression |
||
826 | mov al,')' |
||
827 | stos byte [edi] |
||
828 | pop eax |
||
2287 | heavyiron | 829 | mov [formatter_symbols_allowed],al |
830 | jmp argument_parsed |
||
157 | heavyiron | 831 | address_argument: |
31 | halyavin | 832 | call parse_address |
157 | heavyiron | 833 | lods byte [esi] |
834 | cmp al,']' |
||
835 | je address_parsed |
||
836 | dec esi |
||
837 | mov al,')' |
||
838 | stos byte [edi] |
||
839 | jmp argument_parsed |
||
840 | address_parsed: |
||
31 | halyavin | 841 | mov al,']' |
157 | heavyiron | 842 | stos byte [edi] |
843 | jmp argument_parsed |
||
844 | parse_address: |
||
31 | halyavin | 845 | mov al,'[' |
157 | heavyiron | 846 | stos byte [edi] |
847 | cmp word [esi],021Ah |
||
848 | jne convert_address |
||
849 | push esi |
||
850 | add esi,4 |
||
851 | lea ebx,[esi+1] |
||
852 | cmp byte [esi],':' |
||
853 | pop esi |
||
854 | jne convert_address |
||
855 | add esi,2 |
||
856 | mov ecx,2 |
||
857 | push ebx edi |
||
858 | call get_symbol |
||
859 | pop edi esi |
||
860 | jc unknown_segment_prefix |
||
861 | cmp al,10h |
||
862 | jne unknown_segment_prefix |
||
863 | mov al,ah |
||
864 | and ah,11110000b |
||
865 | cmp ah,60h |
||
866 | jne unknown_segment_prefix |
||
867 | stos byte [edi] |
||
868 | jmp convert_address |
||
869 | unknown_segment_prefix: |
||
109 | heavyiron | 870 | sub esi,5 |
157 | heavyiron | 871 | convert_address: |
31 | halyavin | 872 | push edi |
157 | heavyiron | 873 | mov edi,address_sizes |
874 | call get_operator |
||
875 | pop edi |
||
876 | or al,al |
||
877 | jz convert_expression |
||
878 | add al,70h |
||
879 | stos byte [edi] |
||
880 | jmp convert_expression |
||
881 | forced_parenthesis: |
||
31 | halyavin | 882 | cmp byte [esi],'(' |
157 | heavyiron | 883 | jne argument_parsed |
884 | inc esi |
||
885 | mov al,'{' |
||
886 | jmp separator |
||
887 | unallowed_character: |
||
31 | halyavin | 888 | mov al,0FFh |
157 | heavyiron | 889 | jmp separator |
890 | close_parenthesis: |
||
31 | halyavin | 891 | mov al,'}' |
157 | heavyiron | 892 | separator: |
31 | halyavin | 893 | stos byte [edi] |
157 | heavyiron | 894 | jmp argument_parsed |
895 | instruction_separator: |
||
31 | halyavin | 896 | stos byte [edi] |
157 | heavyiron | 897 | jmp allow_embedded_instruction |
898 | greater: |
||
31 | halyavin | 899 | cmp byte [esi],'=' |
157 | heavyiron | 900 | jne separator |
901 | inc esi |
||
902 | mov al,0F2h |
||
903 | jmp separator |
||
904 | less: |
||
31 | halyavin | 905 | cmp byte [edi-1],0F6h |
157 | heavyiron | 906 | je separator |
907 | cmp byte [esi],'>' |
||
908 | je not_equal |
||
909 | cmp byte [esi],'=' |
||
910 | jne separator |
||
911 | inc esi |
||
912 | mov al,0F3h |
||
913 | jmp separator |
||
914 | not_equal: |
||
31 | halyavin | 915 | inc esi |
157 | heavyiron | 916 | mov al,0F1h |
917 | jmp separator |
||
918 | argument_parsed: |
||
31 | halyavin | 919 | cmp [parenthesis_stack],0 |
157 | heavyiron | 920 | je parse_argument |
921 | dec [parenthesis_stack] |
||
922 | add esp,8 |
||
923 | jmp argument_parsed |
||
924 | expression_parsed: |
||
31 | halyavin | 925 | cmp [parenthesis_stack],0 |
157 | heavyiron | 926 | je parse_argument |
927 | cmp byte [esi],')' |
||
928 | jne argument_parsed |
||
929 | dec [parenthesis_stack] |
||
930 | pop edi esi |
||
931 | jmp expression |
||
932 | contents_parsed: |
||
109 | heavyiron | 933 | cmp [parenthesis_stack],0 |
157 | heavyiron | 934 | je contents_ok |
242 | heavyiron | 935 | dec [parenthesis_stack] |
936 | add esp,8 |
||
937 | jmp contents_parsed |
||
938 | contents_ok: |
||
939 | ret |
||
157 | heavyiron | 940 | |
31 | halyavin | 941 | |
109 | heavyiron | 942 | cmp byte [esi],'.' |
157 | heavyiron | 943 | je local_label_name |
944 | call get_label_id |
||
945 | cmp eax,10h |
||
946 | jb label_identified |
||
947 | or ebx,ebx |
||
948 | jz anonymous_label_name |
||
949 | dec ebx |
||
950 | mov [current_locals_prefix],ebx |
||
951 | label_identified: |
||
109 | heavyiron | 952 | ret |
157 | heavyiron | 953 | anonymous_label_name: |
109 | heavyiron | 954 | cmp byte [esi-1],'@' |
157 | heavyiron | 955 | je anonymous_label_name_ok |
956 | mov eax,0Fh |
||
957 | anonymous_label_name_ok: |
||
109 | heavyiron | 958 | ret |
157 | heavyiron | 959 | local_label_name: |
109 | heavyiron | 960 | call get_label_id |
157 | heavyiron | 961 | ret |
962 | |||
109 | heavyiron | 963 | |
31 | halyavin | 964 | cmp byte [esi],1Ah |
157 | heavyiron | 965 | jne get_simple_operator |
966 | mov edx,esi |
||
967 | push ebp |
||
968 | inc esi |
||
969 | lods byte [esi] |
||
970 | movzx ebp,al |
||
971 | push edi |
||
972 | mov ecx,ebp |
||
973 | call lower_case |
||
974 | pop edi |
||
975 | check_operator: |
||
31 | halyavin | 976 | mov esi,converted |
157 | heavyiron | 977 | movzx ecx,byte [edi] |
978 | jecxz no_operator |
||
979 | inc edi |
||
980 | mov ebx,edi |
||
981 | add ebx,ecx |
||
982 | cmp ecx,ebp |
||
983 | jne next_operator |
||
984 | repe cmps byte [esi],[edi] |
||
985 | je operator_found |
||
986 | next_operator: |
||
31 | halyavin | 987 | mov edi,ebx |
157 | heavyiron | 988 | inc edi |
989 | jmp check_operator |
||
990 | no_operator: |
||
31 | halyavin | 991 | mov esi,edx |
157 | heavyiron | 992 | mov ecx,ebp |
993 | pop ebp |
||
994 | no_simple_operator: |
||
31 | halyavin | 995 | xor al,al |
157 | heavyiron | 996 | ret |
997 | operator_found: |
||
31 | halyavin | 998 | lea esi,[edx+2+ebp] |
157 | heavyiron | 999 | mov ecx,ebp |
1000 | pop ebp |
||
1001 | mov al,[edi] |
||
1002 | ret |
||
1003 | get_simple_operator: |
||
31 | halyavin | 1004 | mov al,[esi] |
157 | heavyiron | 1005 | cmp al,22h |
1006 | je no_simple_operator |
||
1007 | simple_operator: |
||
31 | halyavin | 1008 | cmp byte [edi],1 |
157 | heavyiron | 1009 | jb no_simple_operator |
1010 | ja simple_next_operator |
||
1011 | cmp al,[edi+1] |
||
1012 | je simple_operator_found |
||
1013 | simple_next_operator: |
||
31 | halyavin | 1014 | movzx ecx,byte [edi] |
157 | heavyiron | 1015 | lea edi,[edi+1+ecx+1] |
1016 | jmp simple_operator |
||
1017 | simple_operator_found: |
||
31 | halyavin | 1018 | inc esi |
157 | heavyiron | 1019 | mov al,[edi+2] |
1020 | ret |
||
1021 | |||
31 | halyavin | 1022 | |
1023 | push esi |
||
157 | heavyiron | 1024 | mov ebp,ecx |
1025 | call lower_case |
||
1026 | mov ecx,ebp |
||
1027 | cmp cl,11 |
||
1028 | ja no_symbol |
||
1029 | sub cl,2 |
||
1030 | jc no_symbol |
||
1031 | movzx ebx,word [symbols+ecx*4] |
||
1032 | add ebx,symbols |
||
1033 | movzx edx,word [symbols+ecx*4+2] |
||
1034 | scan_symbols: |
||
31 | halyavin | 1035 | or edx,edx |
157 | heavyiron | 1036 | jz no_symbol |
1037 | mov eax,edx |
||
1038 | shr eax,1 |
||
1039 | lea edi,[ebp+2] |
||
1040 | imul eax,edi |
||
1041 | lea edi,[ebx+eax] |
||
1042 | mov esi,converted |
||
1043 | mov ecx,ebp |
||
1044 | repe cmps byte [esi],[edi] |
||
1045 | ja symbols_up |
||
1046 | jb symbols_down |
||
1047 | mov ax,[edi] |
||
2287 | heavyiron | 1048 | |
1049 | |||
1050 | jb symbol_ok |
||
1051 | cmp [formatter_symbols_allowed],0 |
||
1052 | je no_symbol |
||
1053 | |||
1054 | |||
1055 | pop esi |
||
157 | heavyiron | 1056 | add esi,ebp |
1057 | clc |
||
1058 | ret |
||
1059 | no_symbol: |
||
31 | halyavin | 1060 | pop esi |
157 | heavyiron | 1061 | mov ecx,ebp |
1062 | stc |
||
1063 | ret |
||
1064 | symbols_down: |
||
109 | heavyiron | 1065 | shr edx,1 |
157 | heavyiron | 1066 | jmp scan_symbols |
1067 | symbols_up: |
||
109 | heavyiron | 1068 | lea ebx,[edi+ecx+2] |
157 | heavyiron | 1069 | shr edx,1 |
1070 | adc edx,-1 |
||
1071 | jmp scan_symbols |
||
1072 | |||
31 | halyavin | 1073 | |
109 | heavyiron | 1074 | push esi |
157 | heavyiron | 1075 | mov ebp,ecx |
1076 | call lower_case |
||
1077 | mov ecx,ebp |
||
1078 | cmp cl,4 |
||
1079 | ja no_instruction |
||
1080 | sub cl,2 |
||
1081 | jc no_instruction |
||
1082 | movzx ebx,word [data_directives+ecx*4] |
||
1083 | add ebx,data_directives |
||
1084 | movzx edx,word [data_directives+ecx*4+2] |
||
1085 | jmp scan_instructions |
||
1086 | |||
109 | heavyiron | 1087 | |
31 | halyavin | 1088 | push esi |
157 | heavyiron | 1089 | mov ebp,ecx |
1090 | call lower_case |
||
1091 | mov ecx,ebp |
||
1092 | cmp cl,16 |
||
2287 | heavyiron | 1093 | ja no_instruction |
157 | heavyiron | 1094 | sub cl,2 |
1095 | jc no_instruction |
||
1096 | movzx ebx,word [instructions+ecx*4] |
||
1097 | add ebx,instructions |
||
1098 | movzx edx,word [instructions+ecx*4+2] |
||
1099 | scan_instructions: |
||
31 | halyavin | 1100 | or edx,edx |
157 | heavyiron | 1101 | jz no_instruction |
1102 | mov eax,edx |
||
1103 | shr eax,1 |
||
1104 | lea edi,[ebp+3] |
||
1105 | imul eax,edi |
||
1106 | lea edi,[ebx+eax] |
||
1107 | mov esi,converted |
||
1108 | mov ecx,ebp |
||
1109 | repe cmps byte [esi],[edi] |
||
1110 | ja instructions_up |
||
1111 | jb instructions_down |
||
1112 | pop esi |
||
1113 | add esi,ebp |
||
1114 | mov al,[edi] |
||
1115 | mov bx,[edi+1] |
||
1116 | clc |
||
1117 | ret |
||
1118 | no_instruction: |
||
31 | halyavin | 1119 | pop esi |
157 | heavyiron | 1120 | mov ecx,ebp |
1121 | stc |
||
1122 | ret |
||
1123 | instructions_down: |
||
109 | heavyiron | 1124 | shr edx,1 |
157 | heavyiron | 1125 | jmp scan_instructions |
1126 | instructions_up: |
||
109 | heavyiron | 1127 | lea ebx,[edi+ecx+3] |
157 | heavyiron | 1128 | shr edx,1 |
1129 | adc edx,-1 |
||
1130 | jmp scan_instructions |
||
1131 | |||
31 | halyavin | 1132 | |
1133 | cmp ecx,100h |
||
157 | heavyiron | 1134 | jae name_too_long |
1135 | cmp byte [esi],'@' |
||
1136 | je anonymous_label |
||
1137 | cmp byte [esi],'.' |
||
1138 | jne standard_label |
||
1139 | cmp byte [esi+1],'.' |
||
1140 | je standard_label |
||
1141 | cmp [current_locals_prefix],0 |
||
1142 | je standard_label |
||
1143 | push edi |
||
1144 | mov edi,[additional_memory_end] |
||
1145 | sub edi,2 |
||
1146 | sub edi,ecx |
||
1147 | push ecx esi |
||
1148 | mov esi,[current_locals_prefix] |
||
1149 | lods byte [esi] |
||
1150 | movzx ecx,al |
||
1151 | sub edi,ecx |
||
1152 | cmp edi,[free_additional_memory] |
||
1153 | jb out_of_memory |
||
1154 | mov word [edi],0 |
||
1155 | add edi,2 |
||
1156 | mov ebx,edi |
||
1157 | rep movs byte [edi],[esi] |
||
1158 | pop esi ecx |
||
1159 | add al,cl |
||
1160 | jc name_too_long |
||
1161 | rep movs byte [edi],[esi] |
||
1162 | pop edi |
||
1163 | push ebx esi |
||
1164 | movzx ecx,al |
||
1165 | mov byte [ebx-1],al |
||
1166 | mov esi,ebx |
||
1167 | call get_label_id |
||
1168 | pop esi ebx |
||
1169 | cmp ebx,[eax+24] |
||
1170 | jne composed_label_id_ok |
||
1171 | lea edx,[ebx-2] |
||
1172 | mov [additional_memory_end],edx |
||
1173 | composed_label_id_ok: |
||
109 | heavyiron | 1174 | ret |
157 | heavyiron | 1175 | anonymous_label: |
31 | halyavin | 1176 | cmp ecx,2 |
157 | heavyiron | 1177 | jne standard_label |
1178 | mov al,[esi+1] |
||
1179 | mov ebx,characters |
||
1180 | xlat byte [ebx] |
||
1181 | cmp al,'@' |
||
1182 | je new_anonymous |
||
1183 | cmp al,'b' |
||
1184 | je anonymous_back |
||
1185 | cmp al,'r' |
||
1186 | je anonymous_back |
||
1187 | cmp al,'f' |
||
1188 | jne standard_label |
||
1189 | add esi,2 |
||
1190 | mov eax,[anonymous_forward] |
||
1191 | or eax,eax |
||
1192 | jnz anonymous_ok |
||
1193 | mov eax,[current_line] |
||
1194 | mov [error_line],eax |
||
1195 | call allocate_label |
||
1196 | mov [anonymous_forward],eax |
||
1197 | anonymous_ok: |
||
31 | halyavin | 1198 | xor ebx,ebx |
157 | heavyiron | 1199 | ret |
1200 | anonymous_back: |
||
31 | halyavin | 1201 | mov eax,[anonymous_reverse] |
157 | heavyiron | 1202 | add esi,2 |
2287 | heavyiron | 1203 | or eax,eax |
157 | heavyiron | 1204 | jz bogus_anonymous |
2287 | heavyiron | 1205 | jmp anonymous_ok |
157 | heavyiron | 1206 | bogus_anonymous: |
2287 | heavyiron | 1207 | call allocate_label |
1208 | mov [anonymous_reverse],eax |
||
1209 | jmp anonymous_ok |
||
1210 | new_anonymous: |
||
31 | halyavin | 1211 | add esi,2 |
157 | heavyiron | 1212 | mov eax,[anonymous_forward] |
1213 | or eax,eax |
||
1214 | jnz new_anonymous_ok |
||
1215 | call allocate_label |
||
1216 | new_anonymous_ok: |
||
31 | halyavin | 1217 | mov [anonymous_reverse],eax |
157 | heavyiron | 1218 | mov [anonymous_forward],0 |
1219 | jmp anonymous_ok |
||
1220 | standard_label: |
||
31 | halyavin | 1221 | cmp byte [esi],'%' |
157 | heavyiron | 1222 | je get_predefined_id |
1223 | cmp byte [esi],'$' |
||
1224 | je current_address_label |
||
2287 | heavyiron | 1225 | cmp byte [esi],'?' |
1226 | jne find_label |
||
157 | heavyiron | 1227 | cmp ecx,1 |
2287 | heavyiron | 1228 | jne find_label |
1229 | inc esi |
||
1230 | mov eax,0Fh |
||
1231 | ret |
||
1232 | current_address_label: |
||
1233 | cmp ecx,2 |
||
157 | heavyiron | 1234 | ja find_label |
1235 | inc esi |
||
1236 | jb get_current_offset_id |
||
1237 | inc esi |
||
1238 | cmp byte [esi-1],'$' |
||
1239 | je get_org_origin_id |
||
1240 | sub esi,ecx |
||
1241 | jmp find_label |
||
1242 | get_current_offset_id: |
||
31 | halyavin | 1243 | xor eax,eax |
157 | heavyiron | 1244 | ret |
1245 | get_counter_id: |
||
31 | halyavin | 1246 | mov eax,1 |
157 | heavyiron | 1247 | ret |
1248 | get_timestamp_id: |
||
31 | halyavin | 1249 | mov eax,2 |
157 | heavyiron | 1250 | ret |
1251 | get_org_origin_id: |
||
31 | halyavin | 1252 | mov eax,3 |
157 | heavyiron | 1253 | ret |
1254 | get_predefined_id: |
||
31 | halyavin | 1255 | cmp ecx,2 |
157 | heavyiron | 1256 | ja find_label |
1257 | inc esi |
||
1258 | cmp cl,1 |
||
1259 | je get_counter_id |
||
1260 | lods byte [esi] |
||
1261 | mov ebx,characters |
||
1262 | xlat [ebx] |
||
1263 | cmp al,'t' |
||
1264 | je get_timestamp_id |
||
1265 | sub esi,2 |
||
1266 | find_label: |
||
31 | halyavin | 1267 | xor ebx,ebx |
157 | heavyiron | 1268 | mov eax,2166136261 |
1269 | mov ebp,16777619 |
||
1270 | hash_label: |
||
31 | halyavin | 1271 | xor al,[esi+ebx] |
157 | heavyiron | 1272 | mul ebp |
1273 | inc bl |
||
1274 | cmp bl,cl |
||
1275 | jb hash_label |
||
1276 | mov ebp,eax |
||
1277 | shl eax,8 |
||
1278 | and ebp,0FFh shl 24 |
||
1279 | xor ebp,eax |
||
1280 | or ebp,ebx |
||
1281 | mov [label_hash],ebp |
||
1282 | push edi esi |
||
1283 | push ecx |
||
1284 | mov ecx,32 |
||
1285 | mov ebx,hash_tree |
||
1286 | follow_tree: |
||
31 | halyavin | 1287 | mov edx,[ebx] |
157 | heavyiron | 1288 | or edx,edx |
1289 | jz extend_tree |
||
1290 | xor eax,eax |
||
1291 | shl ebp,1 |
||
1292 | adc eax,0 |
||
1293 | lea ebx,[edx+eax*4] |
||
1294 | dec ecx |
||
1295 | jnz follow_tree |
||
1296 | mov [label_leaf],ebx |
||
1297 | pop edx |
||
1298 | mov eax,[ebx] |
||
1299 | or eax,eax |
||
1300 | jz add_label |
||
1301 | mov ebx,esi |
||
1302 | mov ebp,[label_hash] |
||
1303 | compare_labels: |
||
31 | halyavin | 1304 | mov esi,ebx |
157 | heavyiron | 1305 | mov ecx,edx |
1306 | mov edi,[eax+4] |
||
1307 | mov edi,[edi+24] |
||
1308 | repe cmps byte [esi],[edi] |
||
1309 | je label_found |
||
1310 | mov eax,[eax] |
||
1311 | or eax,eax |
||
1312 | jnz compare_labels |
||
1313 | jmp add_label |
||
1314 | label_found: |
||
31 | halyavin | 1315 | add esp,4 |
157 | heavyiron | 1316 | pop edi |
1317 | mov eax,[eax+4] |
||
1318 | ret |
||
1319 | extend_tree: |
||
31 | halyavin | 1320 | mov edx,[free_additional_memory] |
157 | heavyiron | 1321 | lea eax,[edx+8] |
1322 | cmp eax,[additional_memory_end] |
||
1323 | ja out_of_memory |
||
1324 | mov [free_additional_memory],eax |
||
1325 | xor eax,eax |
||
1326 | mov [edx],eax |
||
1327 | mov [edx+4],eax |
||
1328 | shl ebp,1 |
||
1329 | adc eax,0 |
||
1330 | mov [ebx],edx |
||
1331 | lea ebx,[edx+eax*4] |
||
1332 | dec ecx |
||
1333 | jnz extend_tree |
||
1334 | mov [label_leaf],ebx |
||
1335 | pop edx |
||
1336 | add_label: |
||
31 | halyavin | 1337 | mov ecx,edx |
157 | heavyiron | 1338 | pop esi |
1339 | cmp byte [esi-2],0 |
||
1340 | je label_name_ok |
||
1341 | mov al,[esi] |
||
1342 | cmp al,30h |
||
1343 | jb name_first_char_ok |
||
1344 | cmp al,39h |
||
1345 | jbe invalid_name |
||
1346 | name_first_char_ok: |
||
31 | halyavin | 1347 | cmp al,'$' |
340 | heavyiron | 1348 | jne check_for_reserved_word |
1349 | cmp ecx,1 |
||
157 | heavyiron | 1350 | jne invalid_name |
340 | heavyiron | 1351 | reserved_word: |
1352 | mov eax,0Fh |
||
1353 | pop edi |
||
1354 | ret |
||
1355 | check_for_reserved_word: |
||
31 | halyavin | 1356 | call get_instruction |
157 | heavyiron | 1357 | jnc reserved_word |
1358 | call get_data_directive |
||
1359 | jnc reserved_word |
||
1360 | call get_symbol |
||
1361 | jnc reserved_word |
||
1362 | sub esi,2 |
||
1363 | mov edi,operators |
||
1364 | call get_operator |
||
1365 | or al,al |
||
1366 | jnz reserved_word |
||
1367 | mov edi,single_operand_operators |
||
1368 | call get_operator |
||
1369 | or al,al |
||
1370 | jnz reserved_word |
||
1371 | mov edi,directive_operators |
||
1372 | call get_operator |
||
1373 | or al,al |
||
1374 | jnz reserved_word |
||
1375 | inc esi |
||
1376 | movzx ecx,byte [esi] |
||
1377 | inc esi |
||
1378 | label_name_ok: |
||
31 | halyavin | 1379 | mov edx,[free_additional_memory] |
157 | heavyiron | 1380 | lea eax,[edx+8] |
1381 | cmp eax,[additional_memory_end] |
||
1382 | ja out_of_memory |
||
1383 | mov [free_additional_memory],eax |
||
1384 | mov ebx,esi |
||
1385 | add esi,ecx |
||
1386 | mov eax,[label_leaf] |
||
1387 | mov edi,[eax] |
||
1388 | mov [edx],edi |
||
1389 | mov [eax],edx |
||
1390 | call allocate_label |
||
1391 | mov [edx+4],eax |
||
1392 | mov [eax+24],ebx |
||
1393 | pop edi |
||
1394 | ret |
||
1395 | allocate_label: |
||
109 | heavyiron | 1396 | mov eax,[labels_list] |
157 | heavyiron | 1397 | mov ecx,LABEL_STRUCTURE_SIZE shr 2 |
1398 | initialize_label: |
||
109 | heavyiron | 1399 | sub eax,4 |
157 | heavyiron | 1400 | mov dword [eax],0 |
1401 | loop initialize_label |
||
1402 | mov [labels_list],eax |
||
1403 | ret |
||
1404 | |||
31 | halyavin | 1405 | |
109 | heavyiron | 1406 | > |