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