Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | |
2 | ; Copyright (c) 1999-2005, Tomasz Grysztar. |
||
3 | ; All rights reserved. |
||
4 | |||
5 | |||
6 | push ebp |
||
7 | call get_fp_value |
||
8 | jnc fp_expression |
||
9 | mov ebp,esp |
||
10 | expression_loop: |
||
11 | push ebp edi |
||
12 | mov edi,single_operand_operators |
||
13 | call get_operator |
||
14 | pop edi |
||
15 | push eax |
||
16 | mov al,[esi] |
||
17 | cmp al,1Ah |
||
18 | je expression_number |
||
19 | cmp al,22h |
||
20 | je expression_number |
||
21 | cmp al,'(' |
||
22 | je expression_number |
||
23 | mov al,11h |
||
24 | stos byte [edi] |
||
25 | or eax,-1 |
||
26 | stos dword [edi] |
||
27 | jmp expression_number_ok |
||
28 | expression_number: |
||
29 | call convert_number |
||
30 | expression_number_ok: |
||
31 | pop eax |
||
32 | or al,al |
||
33 | jz expression_operator |
||
34 | stos byte [edi] |
||
35 | expression_operator: |
||
36 | push edi |
||
37 | mov edi,operators |
||
38 | call get_operator |
||
39 | pop edi ebp |
||
40 | or al,al |
||
41 | jz expression_end |
||
42 | operators_loop: |
||
43 | cmp esp,ebp |
||
44 | je push_operator |
||
45 | mov bl,al |
||
46 | and bl,0F0h |
||
47 | mov bh,byte [esp] |
||
48 | and bh,0F0h |
||
49 | cmp bl,bh |
||
50 | ja push_operator |
||
51 | pop ebx |
||
52 | mov byte [edi],bl |
||
53 | inc edi |
||
54 | jmp operators_loop |
||
55 | push_operator: |
||
56 | push eax |
||
57 | jmp expression_loop |
||
58 | expression_end: |
||
59 | cmp esp,ebp |
||
60 | je expression_converted |
||
61 | pop eax |
||
62 | stos byte [edi] |
||
63 | jmp expression_end |
||
64 | expression_converted: |
||
65 | pop ebp |
||
66 | ret |
||
67 | fp_expression: |
||
68 | mov al,'.' |
||
69 | stos byte [edi] |
||
70 | mov eax,[fp_value] |
||
71 | stos dword [edi] |
||
72 | mov eax,[fp_value+4] |
||
73 | stos dword [edi] |
||
74 | mov eax,[fp_value+8] |
||
75 | stos dword [edi] |
||
76 | pop ebp |
||
77 | ret |
||
78 | |||
79 | |||
80 | cmp byte [esi],'(' |
||
81 | je expression_value |
||
82 | inc edi |
||
83 | call get_number |
||
84 | jc symbol_value |
||
85 | or ebp,ebp |
||
86 | jz valid_number |
||
87 | mov byte [edi-1],0Fh |
||
88 | ret |
||
89 | valid_number: |
||
90 | cmp dword [edi+4],0 |
||
91 | jne qword_number |
||
92 | cmp word [edi+2],0 |
||
93 | jne dword_number |
||
94 | cmp byte [edi+1],0 |
||
95 | jne word_number |
||
96 | byte_number: |
||
97 | mov byte [edi-1],1 |
||
98 | inc edi |
||
99 | ret |
||
100 | qword_number: |
||
101 | mov byte [edi-1],8 |
||
102 | add edi,8 |
||
103 | ret |
||
104 | dword_number: |
||
105 | mov byte [edi-1],4 |
||
106 | scas dword [edi] |
||
107 | ret |
||
108 | word_number: |
||
109 | mov byte [edi-1],2 |
||
110 | scas word [edi] |
||
111 | ret |
||
112 | expression_value: |
||
113 | mov eax,esp |
||
114 | sub eax,100h |
||
115 | jc stack_overflow |
||
116 | cmp eax,[stack_limit] |
||
117 | jb stack_overflow |
||
118 | inc esi |
||
119 | call convert_expression |
||
120 | lods byte [esi] |
||
121 | cmp al,')' |
||
122 | jne invalid_expression |
||
123 | ret |
||
124 | symbol_value: |
||
125 | lods byte [esi] |
||
126 | cmp al,1Ah |
||
127 | jne invalid_value |
||
128 | lods byte [esi] |
||
129 | movzx ecx,al |
||
130 | push ecx esi edi |
||
131 | mov edi,address_registers |
||
132 | call get_symbol |
||
133 | jnc register_value |
||
134 | mov edi,directive_operators |
||
135 | call get_symbol |
||
136 | pop edi esi ecx |
||
137 | jnc broken_value |
||
138 | call get_label_id |
||
139 | store_label_value: |
||
140 | mov byte [edi-1],11h |
||
141 | stos dword [edi] |
||
142 | ret |
||
143 | broken_value: |
||
144 | sub esi,2 |
||
145 | or eax,-1 |
||
146 | jmp store_label_value |
||
147 | register_value: |
||
148 | pop edi |
||
149 | add esp,8 |
||
150 | mov byte [edi-1],10h |
||
151 | mov al,ah |
||
152 | stos byte [edi] |
||
153 | ret |
||
154 | |||
155 | |||
156 | xor ebp,ebp |
||
157 | lods byte [esi] |
||
158 | cmp al,22h |
||
159 | je get_text_number |
||
160 | cmp al,1Ah |
||
161 | jne not_number |
||
162 | lods byte [esi] |
||
163 | movzx ecx,al |
||
164 | mov [number_start],esi |
||
165 | mov al,[esi] |
||
166 | cmp al,'$' |
||
167 | je number_begin |
||
168 | sub al,30h |
||
169 | cmp al,9 |
||
170 | ja invalid_number |
||
171 | number_begin: |
||
172 | mov ebx,esi |
||
173 | add esi,ecx |
||
174 | push esi |
||
175 | dec esi |
||
176 | mov dword [edi],0 |
||
177 | mov dword [edi+4],0 |
||
178 | cmp byte [ebx],'$' |
||
179 | je pascal_hex_number |
||
180 | cmp word [ebx],'0x' |
||
181 | je get_hex_number |
||
182 | mov al,[esi] |
||
183 | dec esi |
||
184 | cmp al,'h' |
||
185 | je get_hex_number |
||
186 | cmp al,'b' |
||
187 | je get_bin_number |
||
188 | cmp al,'d' |
||
189 | je get_dec_number |
||
190 | cmp al,'o' |
||
191 | je get_oct_number |
||
192 | cmp al,'H' |
||
193 | je get_hex_number |
||
194 | cmp al,'B' |
||
195 | je get_bin_number |
||
196 | cmp al,'D' |
||
197 | je get_dec_number |
||
198 | cmp al,'O' |
||
199 | je get_oct_number |
||
200 | inc esi |
||
201 | get_dec_number: |
||
202 | mov ebx,esi |
||
203 | mov esi,[number_start] |
||
204 | get_dec_digit: |
||
205 | cmp esi,ebx |
||
206 | ja number_ok |
||
207 | xor edx,edx |
||
208 | mov eax,[edi] |
||
209 | shld edx,eax,2 |
||
210 | shl eax,2 |
||
211 | add eax,[edi] |
||
212 | adc edx,0 |
||
213 | add eax,eax |
||
214 | adc edx,edx |
||
215 | mov [edi],eax |
||
216 | mov eax,[edi+4] |
||
217 | add eax,eax |
||
218 | jc dec_out_of_range |
||
219 | add eax,eax |
||
220 | jc dec_out_of_range |
||
221 | add eax,[edi+4] |
||
222 | jc dec_out_of_range |
||
223 | add eax,eax |
||
224 | jc dec_out_of_range |
||
225 | add eax,edx |
||
226 | jc dec_out_of_range |
||
227 | mov [edi+4],eax |
||
228 | movzx eax,byte [esi] |
||
229 | sub al,30h |
||
230 | cmp al,9 |
||
231 | ja bad_number |
||
232 | add [edi],eax |
||
233 | adc dword [edi+4],0 |
||
234 | jc dec_out_of_range |
||
235 | inc esi |
||
236 | jmp get_dec_digit |
||
237 | dec_out_of_range: |
||
238 | or ebp,-1 |
||
239 | inc esi |
||
240 | jmp get_dec_digit |
||
241 | bad_number: |
||
242 | pop eax |
||
243 | invalid_number: |
||
244 | mov esi,[number_start] |
||
245 | dec esi |
||
246 | not_number: |
||
247 | dec esi |
||
248 | stc |
||
249 | ret |
||
250 | get_bin_number: |
||
251 | xor bl,bl |
||
252 | get_bin_digit: |
||
253 | cmp esi,[number_start] |
||
254 | jb number_ok |
||
255 | movzx eax,byte [esi] |
||
256 | sub al,30h |
||
257 | cmp al,1 |
||
258 | ja bad_number |
||
259 | xor edx,edx |
||
260 | mov cl,bl |
||
261 | dec esi |
||
262 | cmp bl,64 |
||
263 | je bin_out_of_range |
||
264 | inc bl |
||
265 | cmp cl,32 |
||
266 | jae bin_digit_high |
||
267 | shl eax,cl |
||
268 | or dword [edi],eax |
||
269 | jmp get_bin_digit |
||
270 | bin_digit_high: |
||
271 | sub cl,32 |
||
272 | shl eax,cl |
||
273 | or dword [edi+4],eax |
||
274 | jmp get_bin_digit |
||
275 | bin_out_of_range: |
||
276 | or al,al |
||
277 | jz get_bin_digit |
||
278 | or ebp,-1 |
||
279 | jmp get_bin_digit |
||
280 | pascal_hex_number: |
||
281 | cmp cl,1 |
||
282 | je bad_number |
||
283 | get_hex_number: |
||
284 | xor bl,bl |
||
285 | get_hex_digit: |
||
286 | cmp esi,[number_start] |
||
287 | jb number_ok |
||
288 | movzx eax,byte [esi] |
||
289 | cmp al,'x' |
||
290 | je hex_number_ok |
||
291 | cmp al,'$' |
||
292 | je pascal_hex_ok |
||
293 | sub al,30h |
||
294 | cmp al,9 |
||
295 | jbe hex_digit_ok |
||
296 | sub al,7 |
||
297 | cmp al,15 |
||
298 | jbe hex_letter_digit_ok |
||
299 | sub al,20h |
||
300 | cmp al,15 |
||
301 | ja bad_number |
||
302 | hex_letter_digit_ok: |
||
303 | cmp al,10 |
||
304 | jb bad_number |
||
305 | hex_digit_ok: |
||
306 | xor edx,edx |
||
307 | mov cl,bl |
||
308 | dec esi |
||
309 | cmp bl,64 |
||
310 | je hex_out_of_range |
||
311 | add bl,4 |
||
312 | cmp cl,32 |
||
313 | jae hex_digit_high |
||
314 | shl eax,cl |
||
315 | or dword [edi],eax |
||
316 | jmp get_hex_digit |
||
317 | hex_digit_high: |
||
318 | sub cl,32 |
||
319 | shl eax,cl |
||
320 | or dword [edi+4],eax |
||
321 | jmp get_hex_digit |
||
322 | hex_out_of_range: |
||
323 | or al,al |
||
324 | jz get_hex_digit |
||
325 | or ebp,-1 |
||
326 | jmp get_hex_digit |
||
327 | get_oct_number: |
||
328 | xor bl,bl |
||
329 | get_oct_digit: |
||
330 | cmp esi,[number_start] |
||
331 | jb number_ok |
||
332 | movzx eax,byte [esi] |
||
333 | sub al,30h |
||
334 | cmp al,7 |
||
335 | ja bad_number |
||
336 | oct_digit_ok: |
||
337 | xor edx,edx |
||
338 | mov cl,bl |
||
339 | dec esi |
||
340 | cmp bl,64 |
||
341 | jae oct_out_of_range |
||
342 | add bl,3 |
||
343 | cmp cl,30 |
||
344 | je oct_digit_wrap |
||
345 | ja oct_digit_high |
||
346 | shl eax,cl |
||
347 | or dword [edi],eax |
||
348 | jmp get_oct_digit |
||
349 | oct_digit_wrap: |
||
350 | shl eax,cl |
||
351 | adc dword [edi+4],0 |
||
352 | or dword [edi],eax |
||
353 | jmp get_oct_digit |
||
354 | oct_digit_high: |
||
355 | sub cl,32 |
||
356 | shl eax,cl |
||
357 | or dword [edi+4],eax |
||
358 | jmp get_oct_digit |
||
359 | oct_out_of_range: |
||
360 | or al,al |
||
361 | jz get_oct_digit |
||
362 | or ebp,-1 |
||
363 | jmp get_oct_digit |
||
364 | hex_number_ok: |
||
365 | dec esi |
||
366 | pascal_hex_ok: |
||
367 | cmp esi,[number_start] |
||
368 | jne bad_number |
||
369 | number_ok: |
||
370 | pop esi |
||
371 | number_done: |
||
372 | clc |
||
373 | ret |
||
374 | get_text_number: |
||
375 | lods dword [esi] |
||
376 | mov edx,eax |
||
377 | xor bl,bl |
||
378 | mov dword [edi],0 |
||
379 | mov dword [edi+4],0 |
||
380 | get_text_character: |
||
381 | sub edx,1 |
||
382 | jc number_done |
||
383 | movzx eax,byte [esi] |
||
384 | inc esi |
||
385 | mov cl,bl |
||
386 | cmp bl,64 |
||
387 | je text_out_of_range |
||
388 | add bl,8 |
||
389 | cmp cl,32 |
||
390 | jae text_character_high |
||
391 | shl eax,cl |
||
392 | or dword [edi],eax |
||
393 | jmp get_text_character |
||
394 | text_character_high: |
||
395 | sub cl,32 |
||
396 | shl eax,cl |
||
397 | or dword [edi+4],eax |
||
398 | jmp get_text_character |
||
399 | text_out_of_range: |
||
400 | or ebp,-1 |
||
401 | jmp get_text_character |
||
402 | |||
403 | |||
404 | push edi esi |
||
405 | lods byte [esi] |
||
406 | cmp al,1Ah |
||
407 | je fp_value_start |
||
408 | cmp al,'-' |
||
409 | je fp_sign_ok |
||
410 | cmp al,'+' |
||
411 | jne not_fp_value |
||
412 | fp_sign_ok: |
||
413 | lods byte [esi] |
||
414 | cmp al,1Ah |
||
415 | jne not_fp_value |
||
416 | fp_value_start: |
||
417 | lods byte [esi] |
||
418 | movzx ecx,al |
||
419 | cmp cl,1 |
||
420 | jbe not_fp_value |
||
421 | lea edx,[esi+1] |
||
422 | xor ah,ah |
||
423 | check_fp_value: |
||
424 | lods byte [esi] |
||
425 | cmp al,'.' |
||
426 | je fp_character_dot |
||
427 | cmp al,'E' |
||
428 | je fp_character_exp |
||
429 | cmp al,'e' |
||
430 | je fp_character_exp |
||
431 | cmp al,'F' |
||
432 | je fp_last_character |
||
433 | cmp al,'f' |
||
434 | je fp_last_character |
||
435 | digit_expected: |
||
436 | cmp al,'0' |
||
437 | jb not_fp_value |
||
438 | cmp al,'9' |
||
439 | ja not_fp_value |
||
440 | jmp fp_character_ok |
||
441 | fp_character_dot: |
||
442 | cmp esi,edx |
||
443 | je not_fp_value |
||
444 | or ah,ah |
||
445 | jnz not_fp_value |
||
446 | or ah,1 |
||
447 | lods byte [esi] |
||
448 | loop digit_expected |
||
449 | not_fp_value: |
||
450 | pop esi edi |
||
451 | stc |
||
452 | ret |
||
453 | fp_character_exp: |
||
454 | cmp esi,edx |
||
455 | je not_fp_value |
||
456 | cmp ah,1 |
||
457 | ja not_fp_value |
||
458 | or ah,2 |
||
459 | cmp ecx,1 |
||
460 | jne fp_character_ok |
||
461 | cmp byte [esi],'+' |
||
462 | je fp_exp_sign |
||
463 | cmp byte [esi],'-' |
||
464 | jne fp_character_ok |
||
465 | fp_last_character: |
||
466 | cmp cl,1 |
||
467 | jne not_fp_value |
||
468 | or ah,4 |
||
469 | jmp fp_character_ok |
||
470 | fp_exp_sign: |
||
471 | inc esi |
||
472 | cmp byte [esi],1Ah |
||
473 | jne not_fp_value |
||
474 | inc esi |
||
475 | lods byte [esi] |
||
476 | movzx ecx,al |
||
477 | inc ecx |
||
478 | fp_character_ok: |
||
479 | dec ecx |
||
480 | jnz check_fp_value |
||
481 | or ah,ah |
||
482 | jz not_fp_value |
||
483 | pop esi |
||
484 | lods byte [esi] |
||
485 | mov [fp_sign],0 |
||
486 | cmp al,1Ah |
||
487 | je fp_get |
||
488 | inc esi |
||
489 | cmp al,'+' |
||
490 | je fp_get |
||
491 | mov [fp_sign],1 |
||
492 | fp_get: |
||
493 | lods byte [esi] |
||
494 | movzx ecx,al |
||
495 | xor edx,edx |
||
496 | mov edi,fp_value |
||
497 | mov [edi],edx |
||
498 | mov [edi+4],edx |
||
499 | mov [edi+12],edx |
||
500 | call fp_optimize |
||
501 | mov [fp_format],0 |
||
502 | mov al,[esi] |
||
503 | fp_before_dot: |
||
504 | lods byte [esi] |
||
505 | cmp al,'.' |
||
506 | je fp_dot |
||
507 | cmp al,'E' |
||
508 | je fp_exponent |
||
509 | cmp al,'e' |
||
510 | je fp_exponent |
||
511 | cmp al,'F' |
||
512 | je fp_done |
||
513 | cmp al,'f' |
||
514 | je fp_done |
||
515 | sub al,30h |
||
516 | mov edi,fp_value+16 |
||
517 | xor edx,edx |
||
518 | mov dword [edi+12],edx |
||
519 | mov dword [edi],edx |
||
520 | mov dword [edi+4],edx |
||
521 | mov [edi+7],al |
||
522 | mov dl,7 |
||
523 | mov dword [edi+8],edx |
||
524 | call fp_optimize |
||
525 | mov edi,fp_value |
||
526 | push ecx |
||
527 | mov ecx,10 |
||
528 | call fp_mul |
||
529 | pop ecx |
||
530 | mov ebx,fp_value+16 |
||
531 | call fp_add |
||
532 | loop fp_before_dot |
||
533 | fp_dot: |
||
534 | mov edi,fp_value+16 |
||
535 | xor edx,edx |
||
536 | mov [edi],edx |
||
537 | mov [edi+4],edx |
||
538 | mov byte [edi+7],80h |
||
539 | mov [edi+8],edx |
||
540 | mov dword [edi+12],edx |
||
541 | dec ecx |
||
542 | jz fp_done |
||
543 | fp_after_dot: |
||
544 | lods byte [esi] |
||
545 | cmp al,'E' |
||
546 | je fp_exponent |
||
547 | cmp al,'e' |
||
548 | je fp_exponent |
||
549 | cmp al,'F' |
||
550 | je fp_done |
||
551 | cmp al,'f' |
||
552 | je fp_done |
||
553 | inc [fp_format] |
||
554 | cmp [fp_format],80h |
||
555 | jne fp_counter_ok |
||
556 | mov [fp_format],7Fh |
||
557 | fp_counter_ok: |
||
558 | dec esi |
||
559 | mov edi,fp_value+16 |
||
560 | push ecx |
||
561 | mov ecx,10 |
||
562 | call fp_div |
||
563 | push dword [edi] |
||
564 | push dword [edi+4] |
||
565 | push dword [edi+8] |
||
566 | push dword [edi+12] |
||
567 | lods byte [esi] |
||
568 | sub al,30h |
||
569 | movzx ecx,al |
||
570 | call fp_mul |
||
571 | mov ebx,edi |
||
572 | mov edi,fp_value |
||
573 | call fp_add |
||
574 | mov edi,fp_value+16 |
||
575 | pop dword [edi+12] |
||
576 | pop dword [edi+8] |
||
577 | pop dword [edi+4] |
||
578 | pop dword [edi] |
||
579 | pop ecx |
||
580 | loop fp_after_dot |
||
581 | jmp fp_done |
||
582 | fp_exponent: |
||
583 | or [fp_format],80h |
||
584 | xor edx,edx |
||
585 | xor ebp,ebp |
||
586 | dec ecx |
||
587 | jnz get_exponent |
||
588 | cmp byte [esi],'+' |
||
589 | je fp_exponent_sign |
||
590 | cmp byte [esi],'-' |
||
591 | jne fp_done |
||
592 | not ebp |
||
593 | fp_exponent_sign: |
||
594 | add esi,2 |
||
595 | lods byte [esi] |
||
596 | movzx ecx,al |
||
597 | get_exponent: |
||
598 | movzx eax,byte [esi] |
||
599 | inc esi |
||
600 | sub al,30h |
||
601 | cmp al,10 |
||
602 | jae exponent_ok |
||
603 | imul edx,10 |
||
604 | cmp edx,8000h |
||
605 | jae value_out_of_range |
||
606 | add edx,eax |
||
607 | loop get_exponent |
||
608 | exponent_ok: |
||
609 | mov edi,fp_value |
||
610 | or edx,edx |
||
611 | jz fp_done |
||
612 | mov ecx,edx |
||
613 | or ebp,ebp |
||
614 | jnz fp_negative_power |
||
615 | fp_power: |
||
616 | push ecx |
||
617 | mov ecx,10 |
||
618 | call fp_mul |
||
619 | pop ecx |
||
620 | loop fp_power |
||
621 | jmp fp_done |
||
622 | fp_negative_power: |
||
623 | push ecx |
||
624 | mov ecx,10 |
||
625 | call fp_div |
||
626 | pop ecx |
||
627 | loop fp_negative_power |
||
628 | fp_done: |
||
629 | mov edi,fp_value |
||
630 | mov al,[fp_format] |
||
631 | mov [edi+10],al |
||
632 | mov al,[fp_sign] |
||
633 | mov [edi+11],al |
||
634 | test byte [edi+15],80h |
||
635 | jz fp_ok |
||
636 | add dword [edi],1 |
||
637 | adc dword [edi+4],0 |
||
638 | jnc fp_ok |
||
639 | mov eax,[edi+4] |
||
640 | shrd [edi],eax,1 |
||
641 | shr eax,1 |
||
642 | or eax,80000000h |
||
643 | mov [edi+4],eax |
||
644 | inc word [edi+8] |
||
645 | fp_ok: |
||
646 | pop edi |
||
647 | clc |
||
648 | ret |
||
649 | fp_mul: |
||
650 | or ecx,ecx |
||
651 | jz fp_zero |
||
652 | mov eax,[edi+12] |
||
653 | mul ecx |
||
654 | mov [edi+12],eax |
||
655 | mov ebx,edx |
||
656 | mov eax,[edi] |
||
657 | mul ecx |
||
658 | add eax,ebx |
||
659 | adc edx,0 |
||
660 | mov [edi],eax |
||
661 | mov ebx,edx |
||
662 | mov eax,[edi+4] |
||
663 | mul ecx |
||
664 | add eax,ebx |
||
665 | adc edx,0 |
||
666 | mov [edi+4],eax |
||
667 | .loop: |
||
668 | or edx,edx |
||
669 | jz .done |
||
670 | mov eax,[edi] |
||
671 | shrd [edi+12],eax,1 |
||
672 | mov eax,[edi+4] |
||
673 | shrd [edi],eax,1 |
||
674 | shrd eax,edx,1 |
||
675 | mov [edi+4],eax |
||
676 | shr edx,1 |
||
677 | inc dword [edi+8] |
||
678 | cmp dword [edi+8],8000h |
||
679 | jge value_out_of_range |
||
680 | jmp .loop |
||
681 | .done: |
||
682 | ret |
||
683 | fp_div: |
||
684 | mov eax,[edi+4] |
||
685 | xor edx,edx |
||
686 | div ecx |
||
687 | mov [edi+4],eax |
||
688 | mov eax,[edi] |
||
689 | div ecx |
||
690 | mov [edi],eax |
||
691 | mov eax,[edi+12] |
||
692 | div ecx |
||
693 | mov [edi+12],eax |
||
694 | mov ebx,eax |
||
695 | or ebx,[edi] |
||
696 | or ebx,[edi+4] |
||
697 | jz fp_zero |
||
698 | .loop: |
||
699 | test byte [edi+7],80h |
||
700 | jnz .exp_ok |
||
701 | mov eax,[edi] |
||
702 | shld [edi+4],eax,1 |
||
703 | mov eax,[edi+12] |
||
704 | shld [edi],eax,1 |
||
705 | add eax,eax |
||
706 | mov [edi+12],eax |
||
707 | dec dword [edi+8] |
||
708 | add edx,edx |
||
709 | jmp .loop |
||
710 | .exp_ok: |
||
711 | mov eax,edx |
||
712 | xor edx,edx |
||
713 | div ecx |
||
714 | add [edi+12],eax |
||
715 | adc dword [edi],0 |
||
716 | adc dword [edi+4],0 |
||
717 | jnc .done |
||
718 | mov eax,[edi+4] |
||
719 | mov ebx,[edi] |
||
720 | shrd [edi],eax,1 |
||
721 | shrd [edi+12],ebx,1 |
||
722 | shr eax,1 |
||
723 | or eax,80000000h |
||
724 | mov [edi+4],eax |
||
725 | inc dword [edi+8] |
||
726 | .done: |
||
727 | ret |
||
728 | fp_add: |
||
729 | cmp dword [ebx+8],8000h |
||
730 | je .done |
||
731 | cmp dword [edi+8],8000h |
||
732 | je .copy |
||
733 | mov eax,[ebx+8] |
||
734 | cmp eax,[edi+8] |
||
735 | jge .exp_ok |
||
736 | mov eax,[edi+8] |
||
737 | .exp_ok: |
||
738 | call .change_exp |
||
739 | xchg ebx,edi |
||
740 | call .change_exp |
||
741 | xchg ebx,edi |
||
742 | mov edx,[ebx+12] |
||
743 | mov eax,[ebx] |
||
744 | mov ebx,[ebx+4] |
||
745 | add [edi+12],edx |
||
746 | adc [edi],eax |
||
747 | adc [edi+4],ebx |
||
748 | jnc .done |
||
749 | mov eax,[edi] |
||
750 | shrd [edi+12],eax,1 |
||
751 | mov eax,[edi+4] |
||
752 | shrd [edi],eax,1 |
||
753 | shr eax,1 |
||
754 | or eax,80000000h |
||
755 | mov [edi+4],eax |
||
756 | inc dword [edi+8] |
||
757 | .done: |
||
758 | ret |
||
759 | .copy: |
||
760 | mov eax,[ebx] |
||
761 | mov [edi],eax |
||
762 | mov eax,[ebx+4] |
||
763 | mov [edi+4],eax |
||
764 | mov eax,[ebx+8] |
||
765 | mov [edi+8],eax |
||
766 | mov eax,[ebx+12] |
||
767 | mov [edi+12],eax |
||
768 | ret |
||
769 | .change_exp: |
||
770 | push ecx |
||
771 | mov ecx,eax |
||
772 | sub ecx,[ebx+8] |
||
773 | mov edx,[ebx+4] |
||
774 | jecxz .exp_done |
||
775 | .exp_loop: |
||
776 | mov ebp,[ebx] |
||
777 | shrd [ebx+12],ebp,1 |
||
778 | shrd [ebx],edx,1 |
||
779 | shr edx,1 |
||
780 | inc dword [ebx+8] |
||
781 | loop .exp_loop |
||
782 | .exp_done: |
||
783 | mov [ebx+4],edx |
||
784 | pop ecx |
||
785 | ret |
||
786 | fp_optimize: |
||
787 | mov eax,[edi] |
||
788 | mov ebp,[edi+4] |
||
789 | or ebp,[edi] |
||
790 | or ebp,[edi+12] |
||
791 | jz fp_zero |
||
792 | .loop: |
||
793 | test byte [edi+7],80h |
||
794 | jnz .done |
||
795 | shld [edi+4],eax,1 |
||
796 | mov ebp,[edi+12] |
||
797 | shld eax,ebp,1 |
||
798 | mov [edi],eax |
||
799 | shl dword [edi+12],1 |
||
800 | dec dword [edi+8] |
||
801 | jmp .loop |
||
802 | .done: |
||
803 | ret |
||
804 | fp_zero: |
||
805 | mov dword [edi+8],8000h |
||
806 | ret |
||
807 | |||
808 | |||
809 | mov [current_offset],edi |
||
810 | mov [value_undefined],0 |
||
811 | calculation_loop: |
||
812 | lods byte [esi] |
||
813 | or al,al |
||
814 | jz get_string_value |
||
815 | cmp al,'.' |
||
816 | je convert_fp |
||
817 | cmp al,1 |
||
818 | je get_byte_number |
||
819 | cmp al,2 |
||
820 | je get_word_number |
||
821 | cmp al,4 |
||
822 | je get_dword_number |
||
823 | cmp al,8 |
||
824 | je get_qword_number |
||
825 | cmp al,0Fh |
||
826 | je value_out_of_range |
||
827 | cmp al,10h |
||
828 | je get_register |
||
829 | cmp al,11h |
||
830 | je get_label |
||
831 | cmp al,')' |
||
832 | je expression_calculated |
||
833 | cmp al,']' |
||
834 | je expression_calculated |
||
835 | sub edi,14h |
||
836 | mov ebx,edi |
||
837 | sub ebx,14h |
||
838 | cmp al,0E0h |
||
839 | je calculate_rva |
||
840 | cmp al,0D0h |
||
841 | je calculate_not |
||
842 | cmp al,0D1h |
||
843 | je calculate_neg |
||
844 | mov dx,[ebx+8] |
||
845 | or dx,[edi+8] |
||
846 | cmp al,80h |
||
847 | je calculate_add |
||
848 | cmp al,81h |
||
849 | je calculate_sub |
||
850 | mov ah,[ebx+12] |
||
851 | or ah,[edi+12] |
||
852 | jz absolute_values_calculation |
||
853 | cmp [error_line],0 |
||
854 | jne absolute_values_calculation |
||
855 | mov eax,[current_line] |
||
856 | mov [error_line],eax |
||
857 | mov [error],invalid_use_of_symbol |
||
858 | absolute_values_calculation: |
||
859 | cmp al,90h |
||
860 | je calculate_mul |
||
861 | cmp al,91h |
||
862 | je calculate_div |
||
863 | or dx,dx |
||
864 | jnz invalid_expression |
||
865 | cmp al,0A0h |
||
866 | je calculate_mod |
||
867 | cmp al,0B0h |
||
868 | je calculate_and |
||
869 | cmp al,0B1h |
||
870 | je calculate_or |
||
871 | cmp al,0B2h |
||
872 | je calculate_xor |
||
873 | cmp al,0C0h |
||
874 | je calculate_shl |
||
875 | cmp al,0C1h |
||
876 | je calculate_shr |
||
877 | jmp invalid_expression |
||
878 | expression_calculated: |
||
879 | sub edi,14h |
||
880 | cmp [value_undefined],0 |
||
881 | je expression_value_ok |
||
882 | xor eax,eax |
||
883 | mov [edi],eax |
||
884 | mov [edi+4],eax |
||
885 | expression_value_ok: |
||
886 | ret |
||
887 | get_byte_number: |
||
888 | mov word [edi+8],0 |
||
889 | mov byte [edi+12],0 |
||
890 | xor eax,eax |
||
891 | lods byte [esi] |
||
892 | stos dword [edi] |
||
893 | xor al,al |
||
894 | stos dword [edi] |
||
895 | add edi,0Ch |
||
896 | jmp calculation_loop |
||
897 | get_word_number: |
||
898 | mov word [edi+8],0 |
||
899 | mov byte [edi+12],0 |
||
900 | xor eax,eax |
||
901 | lods word [esi] |
||
902 | stos dword [edi] |
||
903 | xor ax,ax |
||
904 | stos dword [edi] |
||
905 | add edi,0Ch |
||
906 | jmp calculation_loop |
||
907 | get_dword_number: |
||
908 | mov word [edi+8],0 |
||
909 | mov byte [edi+12],0 |
||
910 | movs dword [edi],[esi] |
||
911 | xor eax,eax |
||
912 | stos dword [edi] |
||
913 | add edi,0Ch |
||
914 | jmp calculation_loop |
||
915 | get_qword_number: |
||
916 | mov word [edi+8],0 |
||
917 | mov byte [edi+12],0 |
||
918 | movs dword [edi],[esi] |
||
919 | movs dword [edi],[esi] |
||
920 | add edi,0Ch |
||
921 | jmp calculation_loop |
||
922 | get_register: |
||
923 | mov byte [edi+9],0 |
||
924 | mov byte [edi+12],0 |
||
925 | lods byte [esi] |
||
926 | mov [edi+8],al |
||
927 | mov byte [edi+10],1 |
||
928 | xor eax,eax |
||
929 | stos dword [edi] |
||
930 | stos dword [edi] |
||
931 | add edi,0Ch |
||
932 | jmp calculation_loop |
||
933 | get_label: |
||
934 | xor eax,eax |
||
935 | mov [edi+8],eax |
||
936 | mov [edi+12],al |
||
937 | mov [edi+20],eax |
||
938 | lods dword [esi] |
||
939 | cmp eax,0Fh |
||
940 | jb predefined_label |
||
941 | je reserved_word_used_as_symbol |
||
942 | cmp eax,-1 |
||
943 | je invalid_expression |
||
944 | mov ebx,eax |
||
945 | mov ax,[current_pass] |
||
946 | mov [ebx+18],ax |
||
947 | or byte [ebx+8],8 |
||
948 | test byte [ebx+8],1 |
||
949 | jz label_undefined |
||
950 | cmp ax,[ebx+16] |
||
951 | je label_defined |
||
952 | test byte [ebx+8],4 |
||
953 | jnz label_undefined |
||
954 | test byte [ebx+9],1 |
||
955 | jz label_defined |
||
956 | mov eax,[ebx] |
||
957 | sub eax,dword [adjustment] |
||
958 | stos dword [edi] |
||
959 | mov eax,[ebx+4] |
||
960 | sbb eax,dword [adjustment+4] |
||
961 | stos dword [edi] |
||
962 | mov eax,dword [adjustment] |
||
963 | or eax,dword [adjustment+4] |
||
964 | jz got_label |
||
965 | or [next_pass_needed],-1 |
||
966 | jmp got_label |
||
967 | label_defined: |
||
968 | mov eax,[ebx] |
||
969 | stos dword [edi] |
||
970 | mov eax,[ebx+4] |
||
971 | stos dword [edi] |
||
972 | got_label: |
||
973 | mov al,[ebx+11] |
||
974 | mov [edi-8+12],al |
||
975 | mov eax,[ebx+12] |
||
976 | mov [edi-8+8],eax |
||
977 | mov eax,[ebx+20] |
||
978 | mov [edi-8+16],eax |
||
979 | add edi,0Ch |
||
980 | mov al,[ebx+10] |
||
981 | or al,al |
||
982 | jz calculation_loop |
||
983 | cmp [size_override],-1 |
||
984 | je calculation_loop |
||
985 | cmp [size_override],0 |
||
986 | je check_size |
||
987 | cmp [operand_size],0 |
||
988 | jne calculation_loop |
||
989 | mov [operand_size],al |
||
990 | jmp calculation_loop |
||
991 | check_size: |
||
992 | xchg [operand_size],al |
||
993 | or al,al |
||
994 | jz calculation_loop |
||
995 | cmp al,[operand_size] |
||
996 | jne operand_sizes_do_not_match |
||
997 | jmp calculation_loop |
||
998 | current_offset_label: |
||
999 | mov al,[labels_type] |
||
1000 | mov [edi+12],al |
||
1001 | mov eax,[org_symbol] |
||
1002 | mov [edi+16],eax |
||
1003 | mov eax,[current_offset] |
||
1004 | xor edx,edx |
||
1005 | sub eax,dword [org_origin] |
||
1006 | sbb edx,dword [org_origin+4] |
||
1007 | stos dword [edi] |
||
1008 | mov eax,edx |
||
1009 | stos dword [edi] |
||
1010 | mov eax,[org_registers] |
||
1011 | stos dword [edi] |
||
1012 | add edi,8 |
||
1013 | jmp calculation_loop |
||
1014 | org_origin_label: |
||
1015 | mov al,[labels_type] |
||
1016 | mov [edi+12],al |
||
1017 | mov eax,[org_symbol] |
||
1018 | mov [edi+16],eax |
||
1019 | mov eax,[org_start] |
||
1020 | xor edx,edx |
||
1021 | sub eax,dword [org_origin] |
||
1022 | sbb edx,dword [org_origin+4] |
||
1023 | stos dword [edi] |
||
1024 | mov eax,edx |
||
1025 | stos dword [edi] |
||
1026 | mov eax,[org_registers] |
||
1027 | stos dword [edi] |
||
1028 | add edi,8 |
||
1029 | jmp calculation_loop |
||
1030 | counter_label: |
||
1031 | mov eax,[counter] |
||
1032 | make_dword_label_value: |
||
1033 | stos dword [edi] |
||
1034 | xor eax,eax |
||
1035 | stos dword [edi] |
||
1036 | add edi,0Ch |
||
1037 | jmp calculation_loop |
||
1038 | timestamp_label: |
||
1039 | call make_timestamp |
||
1040 | jmp make_dword_label_value |
||
1041 | predefined_label: |
||
1042 | or eax,eax |
||
1043 | jz current_offset_label |
||
1044 | cmp eax,1 |
||
1045 | je counter_label |
||
1046 | cmp eax,2 |
||
1047 | je timestamp_label |
||
1048 | cmp eax,3 |
||
1049 | je org_origin_label |
||
1050 | label_undefined: |
||
1051 | cmp [current_pass],1 |
||
1052 | jbe force_next_pass |
||
1053 | cmp [error_line],0 |
||
1054 | jne undefined_value |
||
1055 | mov eax,[current_line] |
||
1056 | mov [error_line],eax |
||
1057 | mov [error],undefined_symbol |
||
1058 | jmp undefined_value |
||
1059 | force_next_pass: |
||
1060 | or [next_pass_needed],-1 |
||
1061 | undefined_value: |
||
1062 | mov byte [edi+12],0 |
||
1063 | or [value_undefined],-1 |
||
1064 | xor eax,eax |
||
1065 | stos dword [edi] |
||
1066 | stos dword [edi] |
||
1067 | add edi,0Ch |
||
1068 | jmp calculation_loop |
||
1069 | calculate_add: |
||
1070 | mov ecx,[ebx+16] |
||
1071 | cmp byte [edi+12],0 |
||
1072 | je add_values |
||
1073 | mov ecx,[edi+16] |
||
1074 | cmp byte [ebx+12],0 |
||
1075 | je add_values |
||
1076 | cmp [error_line],0 |
||
1077 | jne add_values |
||
1078 | mov eax,[current_line] |
||
1079 | mov [error_line],eax |
||
1080 | mov [error],invalid_use_of_symbol |
||
1081 | add_values: |
||
1082 | mov al,[edi+12] |
||
1083 | or [ebx+12],al |
||
1084 | mov [ebx+16],ecx |
||
1085 | mov eax,[edi] |
||
1086 | add [ebx],eax |
||
1087 | mov eax,[edi+4] |
||
1088 | adc [ebx+4],eax |
||
1089 | or dx,dx |
||
1090 | jz calculation_loop |
||
1091 | push esi |
||
1092 | mov esi,ebx |
||
1093 | lea ebx,[edi+10] |
||
1094 | mov cl,[edi+8] |
||
1095 | call add_register |
||
1096 | lea ebx,[edi+11] |
||
1097 | mov cl,[edi+9] |
||
1098 | call add_register |
||
1099 | pop esi |
||
1100 | jmp calculation_loop |
||
1101 | add_register: |
||
1102 | or cl,cl |
||
1103 | jz add_register_done |
||
1104 | add_register_start: |
||
1105 | cmp [esi+8],cl |
||
1106 | jne add_in_second_slot |
||
1107 | mov al,[ebx] |
||
1108 | add [esi+10],al |
||
1109 | jnz add_register_done |
||
1110 | mov byte [esi+8],0 |
||
1111 | ret |
||
1112 | add_in_second_slot: |
||
1113 | cmp [esi+9],cl |
||
1114 | jne create_in_first_slot |
||
1115 | mov al,[ebx] |
||
1116 | add [esi+11],al |
||
1117 | jnz add_register_done |
||
1118 | mov byte [esi+9],0 |
||
1119 | ret |
||
1120 | create_in_first_slot: |
||
1121 | cmp byte [esi+8],0 |
||
1122 | jne create_in_second_slot |
||
1123 | mov [esi+8],cl |
||
1124 | mov al,[ebx] |
||
1125 | mov [esi+10],al |
||
1126 | ret |
||
1127 | create_in_second_slot: |
||
1128 | cmp byte [esi+9],0 |
||
1129 | jne invalid_expression |
||
1130 | mov [esi+9],cl |
||
1131 | mov al,[ebx] |
||
1132 | mov [esi+11],al |
||
1133 | add_register_done: |
||
1134 | ret |
||
1135 | calculate_sub: |
||
1136 | xor ah,ah |
||
1137 | mov ah,[ebx+12] |
||
1138 | mov al,[edi+12] |
||
1139 | or al,al |
||
1140 | jz sub_values |
||
1141 | cmp al,ah |
||
1142 | jne invalid_sub |
||
1143 | xor ah,ah |
||
1144 | mov ecx,[edi+16] |
||
1145 | cmp ecx,[ebx+16] |
||
1146 | je sub_values |
||
1147 | cmp ecx,[org_symbol] |
||
1148 | jne invalid_sub |
||
1149 | test byte [ebx+12],1 |
||
1150 | jnz invalid_sub |
||
1151 | mov ah,3 |
||
1152 | sub_values: |
||
1153 | mov [ebx+12],ah |
||
1154 | mov eax,[edi] |
||
1155 | sub [ebx],eax |
||
1156 | mov eax,[edi+4] |
||
1157 | sbb [ebx+4],eax |
||
1158 | or dx,dx |
||
1159 | jz calculation_loop |
||
1160 | push esi |
||
1161 | mov esi,ebx |
||
1162 | lea ebx,[edi+10] |
||
1163 | mov cl,[edi+8] |
||
1164 | call sub_register |
||
1165 | lea ebx,[edi+11] |
||
1166 | mov cl,[edi+9] |
||
1167 | call sub_register |
||
1168 | pop esi |
||
1169 | jmp calculation_loop |
||
1170 | invalid_sub: |
||
1171 | cmp [error_line],0 |
||
1172 | jne sub_values |
||
1173 | mov eax,[current_line] |
||
1174 | mov [error_line],eax |
||
1175 | mov [error],invalid_use_of_symbol |
||
1176 | jmp sub_values |
||
1177 | sub_register: |
||
1178 | or cl,cl |
||
1179 | jz add_register_done |
||
1180 | neg byte [ebx] |
||
1181 | jmp add_register_start |
||
1182 | calculate_mul: |
||
1183 | or dx,dx |
||
1184 | jz mul_start |
||
1185 | cmp word [ebx+8],0 |
||
1186 | jne mul_start |
||
1187 | mov eax,[ebx] |
||
1188 | xchg eax,[edi] |
||
1189 | mov [ebx],eax |
||
1190 | mov eax,[ebx+4] |
||
1191 | xchg eax,[edi+4] |
||
1192 | mov [ebx+4],eax |
||
1193 | mov eax,[ebx+8] |
||
1194 | xchg eax,[edi+8] |
||
1195 | mov [ebx+8],eax |
||
1196 | mov eax,[ebx+12] |
||
1197 | xchg eax,[edi+12] |
||
1198 | mov [ebx+12],eax |
||
1199 | mul_start: |
||
1200 | push esi edx |
||
1201 | mov esi,ebx |
||
1202 | xor bl,bl |
||
1203 | bt dword [esi+4],31 |
||
1204 | jnc mul_first_sign_ok |
||
1205 | not dword [esi] |
||
1206 | not dword [esi+4] |
||
1207 | add dword [esi],1 |
||
1208 | adc dword [esi+4],0 |
||
1209 | not bl |
||
1210 | mul_first_sign_ok: |
||
1211 | bt dword [edi+4],31 |
||
1212 | jnc mul_second_sign_ok |
||
1213 | not dword [edi] |
||
1214 | not dword [edi+4] |
||
1215 | add dword [edi],1 |
||
1216 | adc dword [edi+4],0 |
||
1217 | not bl |
||
1218 | mul_second_sign_ok: |
||
1219 | cmp dword [esi+4],0 |
||
1220 | jz mul_numbers |
||
1221 | cmp dword [edi+4],0 |
||
1222 | jnz value_out_of_range |
||
1223 | mul_numbers: |
||
1224 | mov eax,[esi+4] |
||
1225 | mul dword [edi] |
||
1226 | or edx,edx |
||
1227 | jnz value_out_of_range |
||
1228 | mov ecx,eax |
||
1229 | mov eax,[esi] |
||
1230 | mul dword [edi+4] |
||
1231 | or edx,edx |
||
1232 | jnz value_out_of_range |
||
1233 | add ecx,eax |
||
1234 | jc value_out_of_range |
||
1235 | mov eax,[esi] |
||
1236 | mul dword [edi] |
||
1237 | add edx,ecx |
||
1238 | jc value_out_of_range |
||
1239 | test edx,1 shl 31 |
||
1240 | jnz value_out_of_range |
||
1241 | mov [esi],eax |
||
1242 | mov [esi+4],edx |
||
1243 | or bl,bl |
||
1244 | jz mul_ok |
||
1245 | not dword [esi] |
||
1246 | not dword [esi+4] |
||
1247 | add dword [esi],1 |
||
1248 | adc dword [esi+4],0 |
||
1249 | mul_ok: |
||
1250 | pop edx |
||
1251 | or dx,dx |
||
1252 | jz mul_calculated |
||
1253 | cmp word [edi+8],0 |
||
1254 | jne invalid_value |
||
1255 | cmp byte [esi+8],0 |
||
1256 | je mul_first_register_ok |
||
1257 | mov al,[edi] |
||
1258 | cbw |
||
1259 | cwde |
||
1260 | cdq |
||
1261 | cmp edx,[edi+4] |
||
1262 | jne value_out_of_range |
||
1263 | cmp eax,[edi] |
||
1264 | jne value_out_of_range |
||
1265 | imul byte [esi+10] |
||
1266 | mov dl,ah |
||
1267 | cbw |
||
1268 | cmp ah,dl |
||
1269 | jne value_out_of_range |
||
1270 | mov [esi+10],al |
||
1271 | mul_first_register_ok: |
||
1272 | cmp byte [esi+9],0 |
||
1273 | je mul_calculated |
||
1274 | mov al,[edi] |
||
1275 | cbw |
||
1276 | cwde |
||
1277 | cdq |
||
1278 | cmp edx,[edi+4] |
||
1279 | jne value_out_of_range |
||
1280 | cmp eax,[edi] |
||
1281 | jne value_out_of_range |
||
1282 | imul byte [esi+11] |
||
1283 | mov dl,ah |
||
1284 | cbw |
||
1285 | cmp ah,dl |
||
1286 | jne value_out_of_range |
||
1287 | mov [esi+11],al |
||
1288 | mul_calculated: |
||
1289 | pop esi |
||
1290 | jmp calculation_loop |
||
1291 | calculate_div: |
||
1292 | push esi edx |
||
1293 | mov esi,ebx |
||
1294 | call div_64 |
||
1295 | pop edx |
||
1296 | or dx,dx |
||
1297 | jz div_calculated |
||
1298 | cmp byte [esi+8],0 |
||
1299 | je div_first_register_ok |
||
1300 | mov al,[edi] |
||
1301 | cbw |
||
1302 | cwde |
||
1303 | cdq |
||
1304 | cmp edx,[edi+4] |
||
1305 | jne value_out_of_range |
||
1306 | cmp eax,[edi] |
||
1307 | jne value_out_of_range |
||
1308 | or al,al |
||
1309 | jz value_out_of_range |
||
1310 | mov al,[esi+10] |
||
1311 | cbw |
||
1312 | idiv byte [edi] |
||
1313 | mov [esi+10],al |
||
1314 | div_first_register_ok: |
||
1315 | cmp byte [esi+9],0 |
||
1316 | je div_calculated |
||
1317 | mov al,[edi] |
||
1318 | cbw |
||
1319 | cwde |
||
1320 | cdq |
||
1321 | cmp edx,[edi+4] |
||
1322 | jne value_out_of_range |
||
1323 | cmp eax,[edi] |
||
1324 | jne value_out_of_range |
||
1325 | or al,al |
||
1326 | jz value_out_of_range |
||
1327 | mov al,[esi+11] |
||
1328 | cbw |
||
1329 | idiv byte [edi] |
||
1330 | mov [esi+11],al |
||
1331 | div_calculated: |
||
1332 | pop esi |
||
1333 | jmp calculation_loop |
||
1334 | calculate_mod: |
||
1335 | push esi |
||
1336 | mov esi,ebx |
||
1337 | call div_64 |
||
1338 | mov [esi],eax |
||
1339 | mov [esi+4],edx |
||
1340 | pop esi |
||
1341 | jmp calculation_loop |
||
1342 | calculate_and: |
||
1343 | mov eax,[edi] |
||
1344 | and [ebx],eax |
||
1345 | mov eax,[edi+4] |
||
1346 | and [ebx+4],eax |
||
1347 | jmp calculation_loop |
||
1348 | calculate_or: |
||
1349 | mov eax,[edi] |
||
1350 | or [ebx],eax |
||
1351 | mov eax,[edi+4] |
||
1352 | or [ebx+4],eax |
||
1353 | jmp calculation_loop |
||
1354 | calculate_xor: |
||
1355 | mov eax,[edi] |
||
1356 | xor [ebx],eax |
||
1357 | mov eax,[edi+4] |
||
1358 | xor [ebx+4],eax |
||
1359 | jmp calculation_loop |
||
1360 | shr_negative: |
||
1361 | not dword [edi] |
||
1362 | not dword [edi+4] |
||
1363 | add dword [edi],1 |
||
1364 | adc dword [edi+4],0 |
||
1365 | calculate_shl: |
||
1366 | mov eax,dword [edi+4] |
||
1367 | bt eax,31 |
||
1368 | jc shl_negative |
||
1369 | or eax,eax |
||
1370 | jnz zero_value |
||
1371 | mov ecx,[edi] |
||
1372 | cmp ecx,64 |
||
1373 | jae zero_value |
||
1374 | cmp ecx,32 |
||
1375 | jae shl_high |
||
1376 | mov edx,[ebx+4] |
||
1377 | mov eax,[ebx] |
||
1378 | shld edx,eax,cl |
||
1379 | shl eax,cl |
||
1380 | mov [ebx],eax |
||
1381 | mov [ebx+4],edx |
||
1382 | jmp calculation_loop |
||
1383 | shl_high: |
||
1384 | sub cl,32 |
||
1385 | mov eax,[ebx] |
||
1386 | shl eax,cl |
||
1387 | mov [ebx+4],eax |
||
1388 | mov dword [ebx],0 |
||
1389 | jmp calculation_loop |
||
1390 | shl_negative: |
||
1391 | not dword [edi] |
||
1392 | not dword [edi+4] |
||
1393 | add dword [edi],1 |
||
1394 | adc dword [edi+4],0 |
||
1395 | calculate_shr: |
||
1396 | mov eax,dword [edi+4] |
||
1397 | bt eax,31 |
||
1398 | jc shr_negative |
||
1399 | or eax,eax |
||
1400 | jnz zero_value |
||
1401 | mov ecx,[edi] |
||
1402 | cmp ecx,64 |
||
1403 | jae zero_value |
||
1404 | cmp ecx,32 |
||
1405 | jae shr_high |
||
1406 | mov edx,[ebx+4] |
||
1407 | mov eax,[ebx] |
||
1408 | shrd eax,edx,cl |
||
1409 | shr edx,cl |
||
1410 | mov [ebx],eax |
||
1411 | mov [ebx+4],edx |
||
1412 | jmp calculation_loop |
||
1413 | shr_high: |
||
1414 | sub cl,32 |
||
1415 | mov eax,[ebx+4] |
||
1416 | shr eax,cl |
||
1417 | mov [ebx],eax |
||
1418 | mov dword [ebx+4],0 |
||
1419 | jmp calculation_loop |
||
1420 | zero_value: |
||
1421 | mov dword [ebx],0 |
||
1422 | mov dword [ebx+4],0 |
||
1423 | jmp calculation_loop |
||
1424 | calculate_not: |
||
1425 | cmp word [edi+8],0 |
||
1426 | jne invalid_expression |
||
1427 | cmp byte [edi+12],0 |
||
1428 | je not_ok |
||
1429 | cmp [error_line],0 |
||
1430 | jne not_ok |
||
1431 | mov eax,[current_line] |
||
1432 | mov [error_line],eax |
||
1433 | mov [error],invalid_use_of_symbol |
||
1434 | not_ok: |
||
1435 | cmp [value_size],1 |
||
1436 | je not_byte |
||
1437 | cmp [value_size],2 |
||
1438 | je not_word |
||
1439 | cmp [value_size],4 |
||
1440 | je not_dword |
||
1441 | cmp [value_size],6 |
||
1442 | je not_pword |
||
1443 | not_qword: |
||
1444 | not dword [edi] |
||
1445 | not dword [edi+4] |
||
1446 | add edi,14h |
||
1447 | jmp calculation_loop |
||
1448 | not_byte: |
||
1449 | cmp dword [edi+4],0 |
||
1450 | jne not_qword |
||
1451 | cmp word [edi+2],0 |
||
1452 | jne not_qword |
||
1453 | cmp byte [edi+1],0 |
||
1454 | jne not_qword |
||
1455 | not byte [edi] |
||
1456 | add edi,14h |
||
1457 | jmp calculation_loop |
||
1458 | not_word: |
||
1459 | cmp dword [edi+4],0 |
||
1460 | jne not_qword |
||
1461 | cmp word [edi+2],0 |
||
1462 | jne not_qword |
||
1463 | not word [edi] |
||
1464 | add edi,14h |
||
1465 | jmp calculation_loop |
||
1466 | not_dword: |
||
1467 | cmp dword [edi+4],0 |
||
1468 | jne not_qword |
||
1469 | not dword [edi] |
||
1470 | add edi,14h |
||
1471 | jmp calculation_loop |
||
1472 | not_pword: |
||
1473 | cmp word [edi+6],0 |
||
1474 | jne not_qword |
||
1475 | not dword [edi] |
||
1476 | not word [edi+4] |
||
1477 | add edi,14h |
||
1478 | jmp calculation_loop |
||
1479 | calculate_neg: |
||
1480 | cmp word [edi+8],0 |
||
1481 | jne invalid_expression |
||
1482 | cmp byte [edi+12],0 |
||
1483 | je neg_ok |
||
1484 | cmp [error_line],0 |
||
1485 | jne neg_ok |
||
1486 | mov eax,[current_line] |
||
1487 | mov [error_line],eax |
||
1488 | mov [error],invalid_use_of_symbol |
||
1489 | neg_ok: |
||
1490 | mov eax,[edi] |
||
1491 | mov edx,[edi+4] |
||
1492 | mov dword [edi],0 |
||
1493 | mov dword [edi+4],0 |
||
1494 | sub [edi],eax |
||
1495 | sbb [edi+4],edx |
||
1496 | add edi,14h |
||
1497 | jmp calculation_loop |
||
1498 | calculate_rva: |
||
1499 | cmp [output_format],3 |
||
1500 | jne invalid_expression |
||
1501 | cmp word [edi+8],0 |
||
1502 | jne invalid_expression |
||
1503 | test [format_flags],8 |
||
1504 | jnz pe64_rva |
||
1505 | cmp byte [edi+12],2 |
||
1506 | je rva_ok |
||
1507 | cmp [error_line],0 |
||
1508 | jne rva_ok |
||
1509 | mov eax,[current_line] |
||
1510 | mov [error_line],eax |
||
1511 | mov [error],invalid_use_of_symbol |
||
1512 | rva_ok: |
||
1513 | mov byte [edi+12],0 |
||
1514 | mov eax,[code_start] |
||
1515 | mov eax,[eax+34h] |
||
1516 | cdq |
||
1517 | sub [edi],eax |
||
1518 | sbb [edi+4],edx |
||
1519 | add edi,14h |
||
1520 | jmp calculation_loop |
||
1521 | pe64_rva: |
||
1522 | cmp byte [edi+12],4 |
||
1523 | je pe64_rva_ok |
||
1524 | cmp [error_line],0 |
||
1525 | jne pe64_rva_ok |
||
1526 | mov eax,[current_line] |
||
1527 | mov [error_line],eax |
||
1528 | mov [error],invalid_use_of_symbol |
||
1529 | pe64_rva_ok: |
||
1530 | mov byte [edi+12],0 |
||
1531 | mov eax,[code_start] |
||
1532 | mov edx,[eax+34h] |
||
1533 | mov eax,[eax+30h] |
||
1534 | sub [edi],eax |
||
1535 | sbb [edi+4],edx |
||
1536 | add edi,14h |
||
1537 | jmp calculation_loop |
||
1538 | div_64: |
||
1539 | xor ebx,ebx |
||
1540 | cmp dword [edi],0 |
||
1541 | jne divider_ok |
||
1542 | cmp dword [edi+4],0 |
||
1543 | jne divider_ok |
||
1544 | cmp [next_pass_needed],0 |
||
1545 | je value_out_of_range |
||
1546 | jmp div_done |
||
1547 | divider_ok: |
||
1548 | bt dword [esi+4],31 |
||
1549 | jnc div_first_sign_ok |
||
1550 | not dword [esi] |
||
1551 | not dword [esi+4] |
||
1552 | add dword [esi],1 |
||
1553 | adc dword [esi+4],0 |
||
1554 | not bx |
||
1555 | div_first_sign_ok: |
||
1556 | bt dword [edi+4],31 |
||
1557 | jnc div_second_sign_ok |
||
1558 | not dword [edi] |
||
1559 | not dword [edi+4] |
||
1560 | add dword [edi],1 |
||
1561 | adc dword [edi+4],0 |
||
1562 | not bl |
||
1563 | div_second_sign_ok: |
||
1564 | cmp dword [edi+4],0 |
||
1565 | jne div_high |
||
1566 | mov ecx,[edi] |
||
1567 | mov eax,[esi+4] |
||
1568 | xor edx,edx |
||
1569 | div ecx |
||
1570 | mov [esi+4],eax |
||
1571 | mov eax,[esi] |
||
1572 | div ecx |
||
1573 | mov [esi],eax |
||
1574 | mov eax,edx |
||
1575 | xor edx,edx |
||
1576 | jmp div_done |
||
1577 | div_high: |
||
1578 | mov eax,[esi+4] |
||
1579 | xor edx,edx |
||
1580 | div dword [edi+4] |
||
1581 | mov ebx,[esi] |
||
1582 | mov [esi],eax |
||
1583 | mov dword [esi+4],0 |
||
1584 | mov ecx,edx |
||
1585 | mul dword [edi] |
||
1586 | div_high_loop: |
||
1587 | cmp ecx,edx |
||
1588 | ja div_high_done |
||
1589 | jb div_high_large_correction |
||
1590 | cmp ebx,eax |
||
1591 | jae div_high_done |
||
1592 | div_high_correction: |
||
1593 | dec dword [esi] |
||
1594 | sub eax,[edi] |
||
1595 | sbb edx,[edi+4] |
||
1596 | jnc div_high_loop |
||
1597 | div_high_done: |
||
1598 | sub ebx,eax |
||
1599 | sbb ecx,edx |
||
1600 | mov edx,ecx |
||
1601 | mov eax,ebx |
||
1602 | ret |
||
1603 | div_high_large_correction: |
||
1604 | push eax edx |
||
1605 | mov eax,edx |
||
1606 | sub eax,ecx |
||
1607 | xor edx,edx |
||
1608 | div dword [edi+4] |
||
1609 | shr eax,1 |
||
1610 | jz div_high_small_correction |
||
1611 | sub [esi],eax |
||
1612 | push eax |
||
1613 | mul dword [edi+4] |
||
1614 | sub dword [esp+4],eax |
||
1615 | pop eax |
||
1616 | mul dword [edi] |
||
1617 | sub dword [esp+4],eax |
||
1618 | sbb dword [esp],edx |
||
1619 | pop edx eax |
||
1620 | jmp div_high_loop |
||
1621 | div_high_small_correction: |
||
1622 | pop edx eax |
||
1623 | jmp div_high_correction |
||
1624 | div_done: |
||
1625 | or bh,bh |
||
1626 | jz remainder_ok |
||
1627 | not eax |
||
1628 | not edx |
||
1629 | add eax,1 |
||
1630 | adc edx,0 |
||
1631 | remainder_ok: |
||
1632 | or bl,bl |
||
1633 | jz div_ok |
||
1634 | not dword [esi] |
||
1635 | not dword [esi+4] |
||
1636 | add dword [esi],1 |
||
1637 | adc dword [esi+4],0 |
||
1638 | div_ok: |
||
1639 | ret |
||
1640 | convert_fp: |
||
1641 | mov word [edi+8],0 |
||
1642 | mov byte [edi+12],0 |
||
1643 | mov al,[value_size] |
||
1644 | cmp al,4 |
||
1645 | je convert_fp_dword |
||
1646 | cmp al,8 |
||
1647 | je convert_fp_qword |
||
1648 | jmp invalid_value |
||
1649 | convert_fp_dword: |
||
1650 | xor eax,eax |
||
1651 | cmp word [esi+8],8000h |
||
1652 | je fp_dword_store |
||
1653 | mov bx,[esi+8] |
||
1654 | mov eax,[esi+4] |
||
1655 | shl eax,1 |
||
1656 | shr eax,9 |
||
1657 | jnc fp_dword_ok |
||
1658 | inc eax |
||
1659 | bt eax,23 |
||
1660 | jnc fp_dword_ok |
||
1661 | and eax,1 shl 23 - 1 |
||
1662 | inc bx |
||
1663 | shr eax,1 |
||
1664 | fp_dword_ok: |
||
1665 | add bx,7Fh |
||
1666 | cmp bx,100h |
||
1667 | jae value_out_of_range |
||
1668 | shl ebx,23 |
||
1669 | or eax,ebx |
||
1670 | fp_dword_store: |
||
1671 | mov bl,[esi+11] |
||
1672 | shl ebx,31 |
||
1673 | or eax,ebx |
||
1674 | mov [edi],eax |
||
1675 | xor eax,eax |
||
1676 | mov [edi+4],eax |
||
1677 | add esi,13 |
||
1678 | ret |
||
1679 | convert_fp_qword: |
||
1680 | xor eax,eax |
||
1681 | xor edx,edx |
||
1682 | cmp word [esi+8],8000h |
||
1683 | je fp_qword_store |
||
1684 | mov bx,[esi+8] |
||
1685 | mov eax,[esi] |
||
1686 | mov edx,[esi+4] |
||
1687 | add eax,eax |
||
1688 | adc edx,edx |
||
1689 | mov ecx,edx |
||
1690 | shr edx,12 |
||
1691 | shrd eax,ecx,12 |
||
1692 | jnc fp_qword_ok |
||
1693 | add eax,1 |
||
1694 | adc edx,0 |
||
1695 | bt edx,20 |
||
1696 | jnc fp_qword_ok |
||
1697 | and edx,1 shl 20 - 1 |
||
1698 | inc bx |
||
1699 | shr edx,1 |
||
1700 | rcr eax,1 |
||
1701 | fp_qword_ok: |
||
1702 | add bx,3FFh |
||
1703 | cmp bx,800h |
||
1704 | jae value_out_of_range |
||
1705 | shl ebx,20 |
||
1706 | or edx,ebx |
||
1707 | fp_qword_store: |
||
1708 | mov bl,[esi+11] |
||
1709 | shl ebx,31 |
||
1710 | or edx,ebx |
||
1711 | mov [edi],eax |
||
1712 | mov [edi+4],edx |
||
1713 | add esi,13 |
||
1714 | ret |
||
1715 | get_string_value: |
||
1716 | lods dword [esi] |
||
1717 | mov ecx,eax |
||
1718 | cmp ecx,8 |
||
1719 | ja value_out_of_range |
||
1720 | mov edx,edi |
||
1721 | xor eax,eax |
||
1722 | stos dword [edi] |
||
1723 | stos dword [edi] |
||
1724 | mov edi,edx |
||
1725 | rep movs byte [edi],[esi] |
||
1726 | mov edi,edx |
||
1727 | inc esi |
||
1728 | mov word [edi+8],0 |
||
1729 | mov byte [edi+12],0 |
||
1730 | ret |
||
1731 | |||
1732 | |||
1733 | mov [value_size],1 |
||
1734 | mov [size_override],-1 |
||
1735 | call calculate_expression |
||
1736 | mov eax,[edi+16] |
||
1737 | mov [symbol_identifier],eax |
||
1738 | mov [value_type],0 |
||
1739 | cmp word [edi+8],0 |
||
1740 | jne invalid_value |
||
1741 | cmp byte [edi+12],0 |
||
1742 | je check_byte_value |
||
1743 | cmp [error_line],0 |
||
1744 | jne check_byte_value |
||
1745 | mov eax,[current_line] |
||
1746 | mov [error_line],eax |
||
1747 | mov [error],invalid_use_of_symbol |
||
1748 | check_byte_value: |
||
1749 | mov eax,[edi] |
||
1750 | mov edx,[edi+4] |
||
1751 | or edx,edx |
||
1752 | jz byte_positive |
||
1753 | cmp edx,-1 |
||
1754 | jne range_exceeded |
||
1755 | cmp eax,-80h |
||
1756 | jb range_exceeded |
||
1757 | ret |
||
1758 | byte_positive: |
||
1759 | cmp eax,100h |
||
1760 | jae range_exceeded |
||
1761 | return_byte_value: |
||
1762 | ret |
||
1763 | range_exceeded: |
||
1764 | xor eax,eax |
||
1765 | xor edx,edx |
||
1766 | cmp [error_line],0 |
||
1767 | jne return_byte_value |
||
1768 | mov ecx,[current_line] |
||
1769 | mov [error_line],ecx |
||
1770 | mov [error],value_out_of_range |
||
1771 | ret |
||
1772 | get_word_value: |
||
1773 | mov [value_size],2 |
||
1774 | mov [size_override],-1 |
||
1775 | call calculate_expression |
||
1776 | mov eax,[edi+16] |
||
1777 | mov [symbol_identifier],eax |
||
1778 | cmp word [edi+8],0 |
||
1779 | jne invalid_value |
||
1780 | mov al,[edi+12] |
||
1781 | mov [value_type],al |
||
1782 | cmp al,2 |
||
1783 | jb check_word_value |
||
1784 | cmp [error_line],0 |
||
1785 | jne check_word_value |
||
1786 | mov eax,[current_line] |
||
1787 | mov [error_line],eax |
||
1788 | mov [error],invalid_use_of_symbol |
||
1789 | check_word_value: |
||
1790 | mov eax,[edi] |
||
1791 | mov edx,[edi+4] |
||
1792 | or edx,edx |
||
1793 | jz word_positive |
||
1794 | cmp edx,-1 |
||
1795 | jne range_exceeded |
||
1796 | cmp eax,-8000h |
||
1797 | jb range_exceeded |
||
1798 | ret |
||
1799 | word_positive: |
||
1800 | cmp eax,10000h |
||
1801 | jae range_exceeded |
||
1802 | ret |
||
1803 | get_dword_value: |
||
1804 | mov [value_size],4 |
||
1805 | mov [size_override],-1 |
||
1806 | call calculate_expression |
||
1807 | mov eax,[edi+16] |
||
1808 | mov [symbol_identifier],eax |
||
1809 | cmp word [edi+8],0 |
||
1810 | jne invalid_value |
||
1811 | mov al,[edi+12] |
||
1812 | mov [value_type],al |
||
1813 | cmp al,4 |
||
1814 | jb check_dword_value |
||
1815 | cmp [error_line],0 |
||
1816 | jne check_dword_value |
||
1817 | mov eax,[current_line] |
||
1818 | mov [error_line],eax |
||
1819 | mov [error],invalid_use_of_symbol |
||
1820 | check_dword_value: |
||
1821 | mov eax,[edi] |
||
1822 | mov edx,[edi+4] |
||
1823 | or edx,edx |
||
1824 | jz dword_positive |
||
1825 | cmp edx,-1 |
||
1826 | jne range_exceeded |
||
1827 | bt eax,31 |
||
1828 | jnc range_exceeded |
||
1829 | dword_positive: |
||
1830 | ret |
||
1831 | get_pword_value: |
||
1832 | mov [value_size],6 |
||
1833 | mov [size_override],-1 |
||
1834 | call calculate_expression |
||
1835 | mov eax,[edi+16] |
||
1836 | mov [symbol_identifier],eax |
||
1837 | cmp word [edi+8],0 |
||
1838 | jne invalid_value |
||
1839 | mov al,[edi+12] |
||
1840 | mov [value_type],al |
||
1841 | cmp al,4 |
||
1842 | jb check_pword_value |
||
1843 | cmp [error_line],0 |
||
1844 | jne check_pword_value |
||
1845 | mov eax,[current_line] |
||
1846 | mov [error_line],eax |
||
1847 | mov [error],invalid_use_of_symbol |
||
1848 | check_pword_value: |
||
1849 | mov eax,[edi] |
||
1850 | mov edx,[edi+4] |
||
1851 | cmp edx,10000h |
||
1852 | jge range_exceeded |
||
1853 | cmp edx,-8000h |
||
1854 | jl range_exceeded |
||
1855 | ret |
||
1856 | get_qword_value: |
||
1857 | mov [value_size],8 |
||
1858 | mov [size_override],-1 |
||
1859 | call calculate_expression |
||
1860 | mov eax,[edi+16] |
||
1861 | mov [symbol_identifier],eax |
||
1862 | cmp word [edi+8],0 |
||
1863 | jne invalid_value |
||
1864 | mov al,[edi+12] |
||
1865 | mov [value_type],al |
||
1866 | check_qword_value: |
||
1867 | mov eax,[edi] |
||
1868 | mov edx,[edi+4] |
||
1869 | ret |
||
1870 | get_value: |
||
1871 | mov [operand_size],0 |
||
1872 | lods byte [esi] |
||
1873 | call get_size_operator |
||
1874 | cmp al,'(' |
||
1875 | jne invalid_value |
||
1876 | mov al,[operand_size] |
||
1877 | cmp al,1 |
||
1878 | je value_byte |
||
1879 | cmp al,2 |
||
1880 | je value_word |
||
1881 | cmp al,4 |
||
1882 | je value_dword |
||
1883 | cmp al,6 |
||
1884 | je value_pword |
||
1885 | cmp al,8 |
||
1886 | je value_qword |
||
1887 | or al,al |
||
1888 | jnz invalid_value |
||
1889 | value_qword: |
||
1890 | call get_qword_value |
||
1891 | ret |
||
1892 | value_pword: |
||
1893 | call get_pword_value |
||
1894 | movzx edx,dx |
||
1895 | ret |
||
1896 | value_dword: |
||
1897 | call get_dword_value |
||
1898 | xor edx,edx |
||
1899 | ret |
||
1900 | value_word: |
||
1901 | call get_word_value |
||
1902 | xor edx,edx |
||
1903 | movzx eax,ax |
||
1904 | ret |
||
1905 | value_byte: |
||
1906 | call get_byte_value |
||
1907 | xor edx,edx |
||
1908 | movzx eax,al |
||
1909 | ret |
||
1910 | get_address_value: |
||
1911 | mov [address_size],0 |
||
1912 | mov [value_size],8 |
||
1913 | calculate_address: |
||
1914 | cmp byte [esi],'.' |
||
1915 | je invalid_address |
||
1916 | call calculate_expression |
||
1917 | mov eax,[edi+16] |
||
1918 | mov [address_symbol],eax |
||
1919 | mov al,[edi+12] |
||
1920 | test al,1 |
||
1921 | jnz invalid_use_of_symbol |
||
1922 | mov [value_type],al |
||
1923 | or al,al |
||
1924 | jz address_symbol_ok |
||
1925 | shl al,5 |
||
1926 | mov ah,[address_size] |
||
1927 | or [address_size],al |
||
1928 | shr al,4 |
||
1929 | or ah,ah |
||
1930 | jz address_symbol_ok |
||
1931 | cmp al,ah |
||
1932 | jne address_sizes_do_not_agree |
||
1933 | address_symbol_ok: |
||
1934 | xor bx,bx |
||
1935 | xor cl,cl |
||
1936 | mov ch,[address_size] |
||
1937 | cmp word [edi+8],0 |
||
1938 | je check_immediate_address |
||
1939 | mov al,[edi+8] |
||
1940 | mov dl,[edi+10] |
||
1941 | call get_address_register |
||
1942 | mov al,[edi+9] |
||
1943 | mov dl,[edi+11] |
||
1944 | call get_address_register |
||
1945 | mov ax,bx |
||
1946 | shr ah,4 |
||
1947 | shr al,4 |
||
1948 | or bh,bh |
||
1949 | jz check_address_registers |
||
1950 | or bl,bl |
||
1951 | jz check_address_registers |
||
1952 | cmp al,ah |
||
1953 | jne invalid_address |
||
1954 | check_address_registers: |
||
1955 | or al,ah |
||
1956 | cmp al,4 |
||
1957 | je sib_allowed |
||
1958 | cmp al,8 |
||
1959 | je sib_allowed |
||
1960 | or cl,cl |
||
1961 | jz check_word_value |
||
1962 | cmp cl,1 |
||
1963 | je check_word_value |
||
1964 | jmp invalid_address |
||
1965 | get_address_register: |
||
1966 | or al,al |
||
1967 | jz address_register_ok |
||
1968 | cmp dl,1 |
||
1969 | jne scaled_register |
||
1970 | or bh,bh |
||
1971 | jnz scaled_register |
||
1972 | mov bh,al |
||
1973 | address_register_ok: |
||
1974 | ret |
||
1975 | scaled_register: |
||
1976 | or bl,bl |
||
1977 | jnz invalid_address |
||
1978 | mov bl,al |
||
1979 | mov cl,dl |
||
1980 | jmp address_register_ok |
||
1981 | sib_allowed: |
||
1982 | or bh,bh |
||
1983 | jnz check_index_scale |
||
1984 | cmp cl,2 |
||
1985 | je special_index_scale |
||
1986 | cmp cl,3 |
||
1987 | je special_index_scale |
||
1988 | cmp cl,5 |
||
1989 | je special_index_scale |
||
1990 | cmp cl,9 |
||
1991 | je special_index_scale |
||
1992 | check_index_scale: |
||
1993 | or cl,cl |
||
1994 | jz address_registers_ok |
||
1995 | cmp cl,1 |
||
1996 | je address_registers_ok |
||
1997 | cmp cl,2 |
||
1998 | je address_registers_ok |
||
1999 | cmp cl,4 |
||
2000 | je address_registers_ok |
||
2001 | cmp cl,8 |
||
2002 | je address_registers_ok |
||
2003 | jmp invalid_address |
||
2004 | special_index_scale: |
||
2005 | mov bh,bl |
||
2006 | dec cl |
||
2007 | address_registers_ok: |
||
2008 | jmp check_dword_value |
||
2009 | check_immediate_address: |
||
2010 | cmp [code_type],64 |
||
2011 | jne check_dword_value |
||
2012 | jmp check_qword_value |
||
2013 | get_relative_offset: |
||
2014 | mov [value_size],4 |
||
2015 | mov [size_override],-1 |
||
2016 | call calculate_expression |
||
2017 | calculate_relative_offset: |
||
2018 | push esi |
||
2019 | add edi,14h |
||
2020 | mov esi,[display_buffer] |
||
2021 | sub esi,7 |
||
2022 | lea eax,[esi-14h] |
||
2023 | cmp eax,edi |
||
2024 | jb out_of_memory |
||
2025 | mov byte [esi],11h |
||
2026 | xor eax,eax |
||
2027 | mov dword [esi+1],eax |
||
2028 | mov word [esi+5],')' shl 8 + 81h |
||
2029 | call calculation_loop |
||
2030 | pop esi |
||
2031 | cmp word [edi+8],0 |
||
2032 | jne invalid_value |
||
2033 | mov al,[edi+12] |
||
2034 | mov [value_type],al |
||
2035 | mov eax,[edi+16] |
||
2036 | mov [symbol_identifier],eax |
||
2037 | mov eax,[edi] |
||
2038 | mov edx,[edi+4] |
||
2039 | or edx,edx |
||
2040 | jz offset_positive |
||
2041 | cmp edx,-1 |
||
2042 | jne range_exceeded |
||
2043 | bt eax,31 |
||
2044 | jnc range_exceeded |
||
2045 | ret |
||
2046 | offset_positive: |
||
2047 | bt eax,31 |
||
2048 | jc range_exceeded |
||
2049 | ret |
||
2050 | |||
2051 | |||
2052 | call get_logical_value |
||
2053 | logical_loop: |
||
2054 | cmp byte [esi],'|' |
||
2055 | je logical_or |
||
2056 | cmp byte [esi],'&' |
||
2057 | je logical_and |
||
2058 | ret |
||
2059 | logical_or: |
||
2060 | inc esi |
||
2061 | push eax |
||
2062 | call get_logical_value |
||
2063 | pop ebx |
||
2064 | or al,bl |
||
2065 | jmp logical_loop |
||
2066 | logical_and: |
||
2067 | inc esi |
||
2068 | push eax |
||
2069 | call get_logical_value |
||
2070 | pop ebx |
||
2071 | and al,bl |
||
2072 | jmp logical_loop |
||
2073 | |||
2074 | |||
2075 | xor al,al |
||
2076 | check_for_negation: |
||
2077 | cmp byte [esi],'~' |
||
2078 | jne negation_ok |
||
2079 | inc esi |
||
2080 | xor al,-1 |
||
2081 | jmp check_for_negation |
||
2082 | negation_ok: |
||
2083 | push eax |
||
2084 | mov al,[esi] |
||
2085 | cmp al,'{' |
||
2086 | je logical_expression |
||
2087 | cmp al,88h |
||
2088 | je check_for_defined |
||
2089 | cmp al,89h |
||
2090 | je check_for_used |
||
2091 | push esi |
||
2092 | cmp al,11h |
||
2093 | jne check_for_values |
||
2094 | add esi,2 |
||
2095 | check_for_values: |
||
2096 | xor bl,bl |
||
2097 | cmp byte [esi],'(' |
||
2098 | jne find_eq_symbol |
||
2099 | call skip_symbol |
||
2100 | lods byte [esi] |
||
2101 | cmp al,'=' |
||
2102 | je compare_values |
||
2103 | cmp al,'>' |
||
2104 | je compare_values |
||
2105 | cmp al,'<' |
||
2106 | je compare_values |
||
2107 | cmp al,0F1h |
||
2108 | je compare_values |
||
2109 | cmp al,0F2h |
||
2110 | je compare_values |
||
2111 | cmp al,0F3h |
||
2112 | je compare_values |
||
2113 | dec esi |
||
2114 | find_eq_symbol: |
||
2115 | cmp byte [esi],0F0h |
||
2116 | je compare_symbols |
||
2117 | cmp byte [esi],0F7h |
||
2118 | je compare_symbol_types |
||
2119 | cmp byte [esi],0F6h |
||
2120 | je scan_symbols_list |
||
2121 | call check_character |
||
2122 | jc logical_number |
||
2123 | cmp al,',' |
||
2124 | jne next_eq_symbol |
||
2125 | mov bl,1 |
||
2126 | next_eq_symbol: |
||
2127 | call skip_symbol |
||
2128 | jmp find_eq_symbol |
||
2129 | compare_symbols: |
||
2130 | inc esi |
||
2131 | pop ebx |
||
2132 | mov edx,esi |
||
2133 | push edi |
||
2134 | mov edi,ebx |
||
2135 | mov ecx,esi |
||
2136 | dec ecx |
||
2137 | sub ecx,edi |
||
2138 | repe cmps byte [esi],[edi] |
||
2139 | pop edi |
||
2140 | je symbols_equal |
||
2141 | mov esi,edx |
||
2142 | symbols_different: |
||
2143 | call check_character |
||
2144 | jc return_false |
||
2145 | call skip_symbol |
||
2146 | jmp symbols_different |
||
2147 | symbols_equal: |
||
2148 | call check_character |
||
2149 | jc return_true |
||
2150 | jmp symbols_different |
||
2151 | compare_symbol_types: |
||
2152 | inc esi |
||
2153 | pop ebx |
||
2154 | type_comparision: |
||
2155 | call check_character |
||
2156 | jc types_compared |
||
2157 | mov al,[esi] |
||
2158 | cmp al,[ebx] |
||
2159 | jne symbols_different |
||
2160 | cmp al,'(' |
||
2161 | jne equal_type |
||
2162 | mov al,[esi+1] |
||
2163 | mov ah,[ebx+1] |
||
2164 | cmp al,ah |
||
2165 | je equal_type |
||
2166 | or al,al |
||
2167 | jz symbols_different |
||
2168 | or ah,ah |
||
2169 | jz symbols_different |
||
2170 | cmp al,'.' |
||
2171 | je symbols_different |
||
2172 | cmp ah,'.' |
||
2173 | je symbols_different |
||
2174 | equal_type: |
||
2175 | call skip_symbol |
||
2176 | xchg esi,ebx |
||
2177 | call skip_symbol |
||
2178 | xchg esi,ebx |
||
2179 | jmp type_comparision |
||
2180 | types_compared: |
||
2181 | cmp byte [ebx],0F7h |
||
2182 | jne return_false |
||
2183 | jmp return_true |
||
2184 | scan_symbols_list: |
||
2185 | or bl,bl |
||
2186 | jnz invalid_expression |
||
2187 | xor bp,bp |
||
2188 | inc esi |
||
2189 | lods byte [esi] |
||
2190 | cmp al,'<' |
||
2191 | jne invalid_expression |
||
2192 | pop ebx |
||
2193 | mov ecx,esi |
||
2194 | sub ecx,2 |
||
2195 | sub ecx,ebx |
||
2196 | compare_in_list: |
||
2197 | mov edx,esi |
||
2198 | push ecx edi |
||
2199 | mov edi,ebx |
||
2200 | repe cmps byte [esi],[edi] |
||
2201 | pop edi ecx |
||
2202 | jne not_equal_in_list |
||
2203 | cmp byte [esi],',' |
||
2204 | je skip_rest_of_list |
||
2205 | cmp byte [esi],'>' |
||
2206 | jne not_equal_in_list |
||
2207 | skip_rest_of_list: |
||
2208 | mov al,[esi] |
||
2209 | or al,al |
||
2210 | jz invalid_expression |
||
2211 | cmp al,0Fh |
||
2212 | je invalid_expression |
||
2213 | cmp al,'>' |
||
2214 | je list_return_true |
||
2215 | call skip_symbol |
||
2216 | jmp skip_rest_of_list |
||
2217 | list_return_true: |
||
2218 | inc esi |
||
2219 | jmp return_true |
||
2220 | not_equal_in_list: |
||
2221 | mov esi,edx |
||
2222 | skip_list_item: |
||
2223 | mov al,[esi] |
||
2224 | or al,al |
||
2225 | jz invalid_expression |
||
2226 | cmp al,0Fh |
||
2227 | je invalid_expression |
||
2228 | cmp al,'<' |
||
2229 | je invalid_expression |
||
2230 | cmp al,'>' |
||
2231 | je list_return_false |
||
2232 | cmp al,',' |
||
2233 | je next_in_list |
||
2234 | call skip_symbol |
||
2235 | jmp skip_list_item |
||
2236 | next_in_list: |
||
2237 | inc esi |
||
2238 | jmp compare_in_list |
||
2239 | list_return_false: |
||
2240 | inc esi |
||
2241 | jmp return_false |
||
2242 | check_character: |
||
2243 | mov al,[esi] |
||
2244 | or al,al |
||
2245 | jz stop |
||
2246 | cmp al,0Fh |
||
2247 | je stop |
||
2248 | cmp al,'}' |
||
2249 | je stop |
||
2250 | cmp al,'|' |
||
2251 | je stop |
||
2252 | cmp al,'&' |
||
2253 | je stop |
||
2254 | clc |
||
2255 | ret |
||
2256 | stop: |
||
2257 | stc |
||
2258 | ret |
||
2259 | compare_values: |
||
2260 | pop esi |
||
2261 | call get_value |
||
2262 | mov bl,[value_type] |
||
2263 | push eax edx ebx |
||
2264 | lods byte [esi] |
||
2265 | mov [compare_type],al |
||
2266 | call get_value |
||
2267 | pop ebx |
||
2268 | cmp [next_pass_needed],0 |
||
2269 | jne values_ok |
||
2270 | cmp bl,[value_type] |
||
2271 | jne invalid_use_of_symbol |
||
2272 | values_ok: |
||
2273 | pop ecx ebx |
||
2274 | cmp [compare_type],'=' |
||
2275 | je check_equal |
||
2276 | cmp [compare_type],'>' |
||
2277 | je check_greater |
||
2278 | cmp [compare_type],'<' |
||
2279 | je check_less |
||
2280 | cmp [compare_type],0F1h |
||
2281 | je check_not_equal |
||
2282 | cmp [compare_type],0F2h |
||
2283 | je check_not_less |
||
2284 | cmp [compare_type],0F3h |
||
2285 | je check_not_greater |
||
2286 | jmp invalid_expression |
||
2287 | check_equal: |
||
2288 | cmp eax,ebx |
||
2289 | jne return_false |
||
2290 | cmp edx,ecx |
||
2291 | jne return_false |
||
2292 | jmp return_true |
||
2293 | check_greater: |
||
2294 | cmp edx,ecx |
||
2295 | jl return_true |
||
2296 | jg return_false |
||
2297 | cmp eax,ebx |
||
2298 | jb return_true |
||
2299 | jae return_false |
||
2300 | check_less: |
||
2301 | cmp edx,ecx |
||
2302 | jl return_false |
||
2303 | jg return_true |
||
2304 | cmp eax,ebx |
||
2305 | jbe return_false |
||
2306 | ja return_true |
||
2307 | check_not_less: |
||
2308 | cmp edx,ecx |
||
2309 | jl return_true |
||
2310 | jg return_false |
||
2311 | cmp eax,ebx |
||
2312 | jbe return_true |
||
2313 | ja return_false |
||
2314 | check_not_greater: |
||
2315 | cmp edx,ecx |
||
2316 | jl return_false |
||
2317 | jg return_true |
||
2318 | cmp eax,ebx |
||
2319 | jb return_false |
||
2320 | jae return_true |
||
2321 | check_not_equal: |
||
2322 | cmp eax,ebx |
||
2323 | jne return_true |
||
2324 | cmp edx,ecx |
||
2325 | jne return_true |
||
2326 | jmp return_false |
||
2327 | logical_number: |
||
2328 | pop esi |
||
2329 | call get_value |
||
2330 | cmp [value_type],0 |
||
2331 | jne invalid_expression |
||
2332 | or eax,edx |
||
2333 | jnz return_true |
||
2334 | jmp return_false |
||
2335 | check_for_defined: |
||
2336 | or bl,-1 |
||
2337 | lods word [esi] |
||
2338 | cmp ah,'(' |
||
2339 | jne invalid_expression |
||
2340 | check_expression: |
||
2341 | lods byte [esi] |
||
2342 | or al,al |
||
2343 | jz defined_string |
||
2344 | cmp al,'.' |
||
2345 | je defined_fp_value |
||
2346 | cmp al,')' |
||
2347 | je expression_checked |
||
2348 | cmp al,0Fh |
||
2349 | je check_expression |
||
2350 | cmp al,10h |
||
2351 | je defined_register |
||
2352 | cmp al,11h |
||
2353 | je check_if_symbol_defined |
||
2354 | cmp al,80h |
||
2355 | jae check_expression |
||
2356 | movzx eax,al |
||
2357 | add esi,eax |
||
2358 | jmp check_expression |
||
2359 | defined_register: |
||
2360 | inc esi |
||
2361 | jmp check_expression |
||
2362 | defined_fp_value: |
||
2363 | add esi,12 |
||
2364 | jmp expression_checked |
||
2365 | defined_string: |
||
2366 | lods dword [esi] |
||
2367 | add esi,eax |
||
2368 | inc esi |
||
2369 | jmp expression_checked |
||
2370 | check_if_symbol_defined: |
||
2371 | lods dword [esi] |
||
2372 | cmp eax,-1 |
||
2373 | je invalid_expression |
||
2374 | cmp eax,0Fh |
||
2375 | jb check_expression |
||
2376 | je reserved_word_used_as_symbol |
||
2377 | test byte [eax+8],4 |
||
2378 | jnz no_prediction |
||
2379 | test byte [eax+8],1 |
||
2380 | jz symbol_predicted_undefined |
||
2381 | mov cx,[current_pass] |
||
2382 | sub cx,[eax+16] |
||
2383 | jz check_expression |
||
2384 | cmp cx,1 |
||
2385 | ja symbol_predicted_undefined |
||
2386 | or byte [eax+8],40h+80h |
||
2387 | jmp check_expression |
||
2388 | no_prediction: |
||
2389 | test byte [eax+8],1 |
||
2390 | jz symbol_undefined |
||
2391 | mov cx,[current_pass] |
||
2392 | sub cx,[eax+16] |
||
2393 | jz check_expression |
||
2394 | jmp symbol_undefined |
||
2395 | symbol_predicted_undefined: |
||
2396 | or byte [eax+8],40h |
||
2397 | and byte [eax+8],not 80h |
||
2398 | symbol_undefined: |
||
2399 | xor bl,bl |
||
2400 | jmp check_expression |
||
2401 | expression_checked: |
||
2402 | mov al,bl |
||
2403 | jmp logical_value_ok |
||
2404 | check_for_used: |
||
2405 | lods word [esi] |
||
2406 | cmp ah,2 |
||
2407 | jne invalid_expression |
||
2408 | lods dword [esi] |
||
2409 | cmp eax,0Fh |
||
2410 | jb invalid_use_of_symbol |
||
2411 | je reserved_word_used_as_symbol |
||
2412 | inc esi |
||
2413 | test byte [eax+8],8 |
||
2414 | jz not_used |
||
2415 | mov cx,[current_pass] |
||
2416 | sub cx,[eax+18] |
||
2417 | jz return_true |
||
2418 | cmp cx,1 |
||
2419 | ja not_used |
||
2420 | or byte [eax+8],10h+20h |
||
2421 | jmp return_true |
||
2422 | not_used: |
||
2423 | or byte [eax+8],10h |
||
2424 | and byte [eax+8],not 20h |
||
2425 | return_false: |
||
2426 | xor al,al |
||
2427 | jmp logical_value_ok |
||
2428 | return_true: |
||
2429 | or al,-1 |
||
2430 | jmp logical_value_ok |
||
2431 | logical_expression: |
||
2432 | inc esi |
||
2433 | call calculate_logical_expression |
||
2434 | push eax |
||
2435 | lods byte [esi] |
||
2436 | cmp al,'}' |
||
2437 | jne invalid_expression |
||
2438 | pop eax |
||
2439 | logical_value_ok: |
||
2440 | pop ebx |
||
2441 | xor al,bl |
||
2442 | ret' |
||
2443 | >' |