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