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