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