Rev 607 | 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_undefined |
||
959 | test byte [ebx+9],1 |
||
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 | label_undefined: |
||
31 | halyavin | 1056 | cmp [current_pass],1 |
157 | heavyiron | 1057 | ja undefined_value |
1058 | force_next_pass: |
||
31 | halyavin | 1059 | or [next_pass_needed],-1 |
157 | heavyiron | 1060 | undefined_value: |
31 | halyavin | 1061 | mov byte [edi+12],0 |
157 | heavyiron | 1062 | or [value_undefined],-1 |
1063 | xor eax,eax |
||
1064 | stos dword [edi] |
||
1065 | stos dword [edi] |
||
1066 | add edi,0Ch |
||
1067 | cmp [error_line],0 |
||
1068 | jne calculation_loop |
||
1069 | mov eax,[current_line] |
||
1070 | mov [error_line],eax |
||
1071 | mov [error],undefined_symbol |
||
1072 | jmp calculation_loop |
||
1073 | calculate_add: |
||
31 | halyavin | 1074 | mov ecx,[ebx+16] |
157 | heavyiron | 1075 | cmp byte [edi+12],0 |
1076 | je add_values |
||
1077 | mov ecx,[edi+16] |
||
1078 | cmp byte [ebx+12],0 |
||
1079 | je add_values |
||
1080 | cmp [error_line],0 |
||
1081 | jne add_values |
||
1082 | mov eax,[current_line] |
||
1083 | mov [error_line],eax |
||
1084 | mov [error],invalid_use_of_symbol |
||
1085 | add_values: |
||
31 | halyavin | 1086 | mov al,[edi+12] |
157 | heavyiron | 1087 | or [ebx+12],al |
1088 | mov [ebx+16],ecx |
||
1089 | mov eax,[edi] |
||
1090 | add [ebx],eax |
||
1091 | mov eax,[edi+4] |
||
1092 | adc [ebx+4],eax |
||
1093 | or dx,dx |
||
1094 | jz calculation_loop |
||
1095 | push esi |
||
1096 | mov esi,ebx |
||
1097 | lea ebx,[edi+10] |
||
1098 | mov cl,[edi+8] |
||
1099 | call add_register |
||
1100 | lea ebx,[edi+11] |
||
1101 | mov cl,[edi+9] |
||
1102 | call add_register |
||
1103 | pop esi |
||
1104 | jmp calculation_loop |
||
1105 | add_register: |
||
31 | halyavin | 1106 | or cl,cl |
157 | heavyiron | 1107 | jz add_register_done |
1108 | add_register_start: |
||
31 | halyavin | 1109 | cmp [esi+8],cl |
157 | heavyiron | 1110 | jne add_in_second_slot |
1111 | mov al,[ebx] |
||
1112 | add [esi+10],al |
||
1113 | jnz add_register_done |
||
1114 | mov byte [esi+8],0 |
||
1115 | ret |
||
1116 | add_in_second_slot: |
||
31 | halyavin | 1117 | cmp [esi+9],cl |
157 | heavyiron | 1118 | jne create_in_first_slot |
1119 | mov al,[ebx] |
||
1120 | add [esi+11],al |
||
1121 | jnz add_register_done |
||
1122 | mov byte [esi+9],0 |
||
1123 | ret |
||
1124 | create_in_first_slot: |
||
31 | halyavin | 1125 | cmp byte [esi+8],0 |
157 | heavyiron | 1126 | jne create_in_second_slot |
1127 | mov [esi+8],cl |
||
1128 | mov al,[ebx] |
||
1129 | mov [esi+10],al |
||
1130 | ret |
||
1131 | create_in_second_slot: |
||
31 | halyavin | 1132 | cmp byte [esi+9],0 |
157 | heavyiron | 1133 | jne invalid_expression |
1134 | mov [esi+9],cl |
||
1135 | mov al,[ebx] |
||
1136 | mov [esi+11],al |
||
1137 | add_register_done: |
||
31 | halyavin | 1138 | ret |
157 | heavyiron | 1139 | calculate_sub: |
31 | halyavin | 1140 | xor ah,ah |
157 | heavyiron | 1141 | mov ah,[ebx+12] |
1142 | mov al,[edi+12] |
||
1143 | or al,al |
||
1144 | jz sub_values |
||
1145 | cmp al,ah |
||
1146 | jne invalid_sub |
||
1147 | xor ah,ah |
||
1148 | mov ecx,[edi+16] |
||
1149 | cmp ecx,[ebx+16] |
||
1150 | jne invalid_sub |
||
1151 | sub_values: |
||
31 | halyavin | 1152 | mov [ebx+12],ah |
157 | heavyiron | 1153 | mov eax,[edi] |
1154 | sub [ebx],eax |
||
1155 | mov eax,[edi+4] |
||
1156 | sbb [ebx+4],eax |
||
1157 | or dx,dx |
||
1158 | jz calculation_loop |
||
1159 | push esi |
||
1160 | mov esi,ebx |
||
1161 | lea ebx,[edi+10] |
||
1162 | mov cl,[edi+8] |
||
1163 | call sub_register |
||
1164 | lea ebx,[edi+11] |
||
1165 | mov cl,[edi+9] |
||
1166 | call sub_register |
||
1167 | pop esi |
||
1168 | jmp calculation_loop |
||
1169 | invalid_sub: |
||
31 | halyavin | 1170 | cmp [error_line],0 |
157 | heavyiron | 1171 | jne sub_values |
1172 | mov eax,[current_line] |
||
1173 | mov [error_line],eax |
||
1174 | mov [error],invalid_use_of_symbol |
||
1175 | jmp sub_values |
||
1176 | sub_register: |
||
31 | halyavin | 1177 | or cl,cl |
157 | heavyiron | 1178 | jz add_register_done |
1179 | neg byte [ebx] |
||
1180 | jmp add_register_start |
||
1181 | calculate_mul: |
||
31 | halyavin | 1182 | or dx,dx |
157 | heavyiron | 1183 | jz mul_start |
1184 | cmp word [ebx+8],0 |
||
1185 | jne mul_start |
||
1186 | mov eax,[ebx] |
||
1187 | xchg eax,[edi] |
||
1188 | mov [ebx],eax |
||
1189 | mov eax,[ebx+4] |
||
1190 | xchg eax,[edi+4] |
||
1191 | mov [ebx+4],eax |
||
1192 | mov eax,[ebx+8] |
||
1193 | xchg eax,[edi+8] |
||
1194 | mov [ebx+8],eax |
||
1195 | mov eax,[ebx+12] |
||
1196 | xchg eax,[edi+12] |
||
1197 | mov [ebx+12],eax |
||
1198 | mul_start: |
||
31 | halyavin | 1199 | push esi edx |
157 | heavyiron | 1200 | mov esi,ebx |
1201 | xor bl,bl |
||
1202 | bt dword [esi+4],31 |
||
1203 | jnc mul_first_sign_ok |
||
1204 | not dword [esi] |
||
1205 | not dword [esi+4] |
||
1206 | add dword [esi],1 |
||
1207 | adc dword [esi+4],0 |
||
1208 | not bl |
||
1209 | mul_first_sign_ok: |
||
31 | halyavin | 1210 | bt dword [edi+4],31 |
157 | heavyiron | 1211 | jnc mul_second_sign_ok |
1212 | not dword [edi] |
||
1213 | not dword [edi+4] |
||
1214 | add dword [edi],1 |
||
1215 | adc dword [edi+4],0 |
||
1216 | not bl |
||
1217 | mul_second_sign_ok: |
||
31 | halyavin | 1218 | cmp dword [esi+4],0 |
157 | heavyiron | 1219 | jz mul_numbers |
1220 | cmp dword [edi+4],0 |
||
1221 | jnz value_out_of_range |
||
1222 | mul_numbers: |
||
31 | halyavin | 1223 | mov eax,[esi+4] |
157 | heavyiron | 1224 | mul dword [edi] |
1225 | or edx,edx |
||
1226 | jnz value_out_of_range |
||
1227 | mov ecx,eax |
||
1228 | mov eax,[esi] |
||
1229 | mul dword [edi+4] |
||
1230 | or edx,edx |
||
1231 | jnz value_out_of_range |
||
1232 | add ecx,eax |
||
1233 | jc value_out_of_range |
||
1234 | mov eax,[esi] |
||
1235 | mul dword [edi] |
||
1236 | add edx,ecx |
||
1237 | jc value_out_of_range |
||
1238 | test edx,1 shl 31 |
||
1239 | jnz value_out_of_range |
||
1240 | mov [esi],eax |
||
1241 | mov [esi+4],edx |
||
1242 | or bl,bl |
||
1243 | jz mul_ok |
||
1244 | not dword [esi] |
||
1245 | not dword [esi+4] |
||
1246 | add dword [esi],1 |
||
1247 | adc dword [esi+4],0 |
||
1248 | mul_ok: |
||
31 | halyavin | 1249 | pop edx |
157 | heavyiron | 1250 | or dx,dx |
1251 | jz mul_calculated |
||
1252 | cmp word [edi+8],0 |
||
1253 | jne invalid_value |
||
1254 | cmp byte [esi+8],0 |
||
1255 | je mul_first_register_ok |
||
1256 | mov al,[edi] |
||
1257 | cbw |
||
1258 | cwde |
||
1259 | cdq |
||
1260 | cmp edx,[edi+4] |
||
1261 | jne value_out_of_range |
||
1262 | cmp eax,[edi] |
||
1263 | jne value_out_of_range |
||
1264 | imul byte [esi+10] |
||
1265 | mov dl,ah |
||
1266 | cbw |
||
1267 | cmp ah,dl |
||
1268 | jne value_out_of_range |
||
1269 | mov [esi+10],al |
||
1270 | or al,al |
||
242 | heavyiron | 1271 | jnz mul_first_register_ok |
1272 | mov [esi+8],al |
||
1273 | mul_first_register_ok: |
||
31 | halyavin | 1274 | cmp byte [esi+9],0 |
157 | heavyiron | 1275 | je mul_calculated |
1276 | mov al,[edi] |
||
1277 | cbw |
||
1278 | cwde |
||
1279 | cdq |
||
1280 | cmp edx,[edi+4] |
||
1281 | jne value_out_of_range |
||
1282 | cmp eax,[edi] |
||
1283 | jne value_out_of_range |
||
1284 | imul byte [esi+11] |
||
1285 | mov dl,ah |
||
1286 | cbw |
||
1287 | cmp ah,dl |
||
1288 | jne value_out_of_range |
||
1289 | mov [esi+11],al |
||
1290 | or al,al |
||
242 | heavyiron | 1291 | jnz mul_calculated |
1292 | mov [esi+9],al |
||
1293 | mul_calculated: |
||
31 | halyavin | 1294 | pop esi |
157 | heavyiron | 1295 | jmp calculation_loop |
1296 | calculate_div: |
||
31 | halyavin | 1297 | push esi edx |
157 | heavyiron | 1298 | mov esi,ebx |
1299 | call div_64 |
||
1300 | pop edx |
||
1301 | or dx,dx |
||
1302 | jz div_calculated |
||
1303 | cmp byte [esi+8],0 |
||
1304 | je div_first_register_ok |
||
1305 | mov al,[edi] |
||
1306 | cbw |
||
1307 | cwde |
||
1308 | cdq |
||
1309 | cmp edx,[edi+4] |
||
1310 | jne value_out_of_range |
||
1311 | cmp eax,[edi] |
||
1312 | jne value_out_of_range |
||
1313 | or al,al |
||
1314 | jz value_out_of_range |
||
1315 | mov al,[esi+10] |
||
1316 | cbw |
||
1317 | idiv byte [edi] |
||
1318 | or ah,ah |
||
1319 | jnz invalid_use_of_symbol |
||
1320 | mov [esi+10],al |
||
1321 | div_first_register_ok: |
||
31 | halyavin | 1322 | cmp byte [esi+9],0 |
157 | heavyiron | 1323 | je div_calculated |
1324 | mov al,[edi] |
||
1325 | cbw |
||
1326 | cwde |
||
1327 | cdq |
||
1328 | cmp edx,[edi+4] |
||
1329 | jne value_out_of_range |
||
1330 | cmp eax,[edi] |
||
1331 | jne value_out_of_range |
||
1332 | or al,al |
||
1333 | jz value_out_of_range |
||
1334 | mov al,[esi+11] |
||
1335 | cbw |
||
1336 | idiv byte [edi] |
||
1337 | or ah,ah |
||
1338 | jnz invalid_use_of_symbol |
||
1339 | mov [esi+11],al |
||
1340 | div_calculated: |
||
31 | halyavin | 1341 | pop esi |
157 | heavyiron | 1342 | jmp calculation_loop |
1343 | calculate_mod: |
||
31 | halyavin | 1344 | push esi |
157 | heavyiron | 1345 | mov esi,ebx |
1346 | call div_64 |
||
1347 | mov [esi],eax |
||
1348 | mov [esi+4],edx |
||
1349 | pop esi |
||
1350 | jmp calculation_loop |
||
1351 | calculate_and: |
||
31 | halyavin | 1352 | mov eax,[edi] |
157 | heavyiron | 1353 | and [ebx],eax |
1354 | mov eax,[edi+4] |
||
1355 | and [ebx+4],eax |
||
1356 | jmp calculation_loop |
||
1357 | calculate_or: |
||
31 | halyavin | 1358 | mov eax,[edi] |
157 | heavyiron | 1359 | or [ebx],eax |
1360 | mov eax,[edi+4] |
||
1361 | or [ebx+4],eax |
||
1362 | jmp calculation_loop |
||
1363 | calculate_xor: |
||
31 | halyavin | 1364 | mov eax,[edi] |
157 | heavyiron | 1365 | xor [ebx],eax |
1366 | mov eax,[edi+4] |
||
1367 | xor [ebx+4],eax |
||
1368 | jmp calculation_loop |
||
1369 | shr_negative: |
||
31 | halyavin | 1370 | not dword [edi] |
157 | heavyiron | 1371 | not dword [edi+4] |
1372 | add dword [edi],1 |
||
1373 | adc dword [edi+4],0 |
||
1374 | calculate_shl: |
||
31 | halyavin | 1375 | mov eax,dword [edi+4] |
157 | heavyiron | 1376 | bt eax,31 |
1377 | jc shl_negative |
||
1378 | or eax,eax |
||
1379 | jnz zero_value |
||
1380 | mov ecx,[edi] |
||
1381 | cmp ecx,64 |
||
1382 | jae zero_value |
||
1383 | cmp ecx,32 |
||
1384 | jae shl_high |
||
1385 | mov edx,[ebx+4] |
||
1386 | mov eax,[ebx] |
||
1387 | shld edx,eax,cl |
||
1388 | shl eax,cl |
||
1389 | mov [ebx],eax |
||
1390 | mov [ebx+4],edx |
||
1391 | jmp calculation_loop |
||
1392 | shl_high: |
||
31 | halyavin | 1393 | sub cl,32 |
157 | heavyiron | 1394 | mov eax,[ebx] |
1395 | shl eax,cl |
||
1396 | mov [ebx+4],eax |
||
1397 | mov dword [ebx],0 |
||
1398 | jmp calculation_loop |
||
1399 | shl_negative: |
||
31 | halyavin | 1400 | not dword [edi] |
157 | heavyiron | 1401 | not dword [edi+4] |
1402 | add dword [edi],1 |
||
1403 | adc dword [edi+4],0 |
||
1404 | calculate_shr: |
||
31 | halyavin | 1405 | mov eax,dword [edi+4] |
157 | heavyiron | 1406 | bt eax,31 |
1407 | jc shr_negative |
||
1408 | or eax,eax |
||
1409 | jnz zero_value |
||
1410 | mov ecx,[edi] |
||
1411 | cmp ecx,64 |
||
1412 | jae zero_value |
||
1413 | cmp ecx,32 |
||
1414 | jae shr_high |
||
1415 | mov edx,[ebx+4] |
||
1416 | mov eax,[ebx] |
||
1417 | shrd eax,edx,cl |
||
1418 | shr edx,cl |
||
1419 | mov [ebx],eax |
||
1420 | mov [ebx+4],edx |
||
1421 | jmp calculation_loop |
||
1422 | shr_high: |
||
31 | halyavin | 1423 | sub cl,32 |
157 | heavyiron | 1424 | mov eax,[ebx+4] |
1425 | shr eax,cl |
||
1426 | mov [ebx],eax |
||
1427 | mov dword [ebx+4],0 |
||
1428 | jmp calculation_loop |
||
1429 | zero_value: |
||
31 | halyavin | 1430 | mov dword [ebx],0 |
157 | heavyiron | 1431 | mov dword [ebx+4],0 |
1432 | jmp calculation_loop |
||
1433 | calculate_not: |
||
31 | halyavin | 1434 | cmp word [edi+8],0 |
157 | heavyiron | 1435 | jne invalid_expression |
1436 | cmp byte [edi+12],0 |
||
1437 | je not_ok |
||
1438 | cmp [error_line],0 |
||
1439 | jne not_ok |
||
1440 | mov eax,[current_line] |
||
1441 | mov [error_line],eax |
||
1442 | mov [error],invalid_use_of_symbol |
||
1443 | not_ok: |
||
31 | halyavin | 1444 | cmp [value_size],1 |
157 | heavyiron | 1445 | je not_byte |
1446 | cmp [value_size],2 |
||
1447 | je not_word |
||
1448 | cmp [value_size],4 |
||
1449 | je not_dword |
||
1450 | cmp [value_size],6 |
||
1451 | je not_pword |
||
1452 | not_qword: |
||
31 | halyavin | 1453 | not dword [edi] |
157 | heavyiron | 1454 | not dword [edi+4] |
1455 | add edi,14h |
||
1456 | jmp calculation_loop |
||
1457 | not_byte: |
||
31 | halyavin | 1458 | cmp dword [edi+4],0 |
157 | heavyiron | 1459 | jne not_qword |
1460 | cmp word [edi+2],0 |
||
1461 | jne not_qword |
||
1462 | cmp byte [edi+1],0 |
||
1463 | jne not_qword |
||
1464 | not byte [edi] |
||
1465 | add edi,14h |
||
1466 | jmp calculation_loop |
||
1467 | not_word: |
||
31 | halyavin | 1468 | cmp dword [edi+4],0 |
157 | heavyiron | 1469 | jne not_qword |
1470 | cmp word [edi+2],0 |
||
1471 | jne not_qword |
||
1472 | not word [edi] |
||
1473 | add edi,14h |
||
1474 | jmp calculation_loop |
||
1475 | not_dword: |
||
31 | halyavin | 1476 | cmp dword [edi+4],0 |
157 | heavyiron | 1477 | jne not_qword |
1478 | not dword [edi] |
||
1479 | add edi,14h |
||
1480 | jmp calculation_loop |
||
1481 | not_pword: |
||
31 | halyavin | 1482 | cmp word [edi+6],0 |
157 | heavyiron | 1483 | jne not_qword |
1484 | not dword [edi] |
||
1485 | not word [edi+4] |
||
1486 | add edi,14h |
||
1487 | jmp calculation_loop |
||
1488 | calculate_neg: |
||
31 | halyavin | 1489 | cmp word [edi+8],0 |
157 | heavyiron | 1490 | jne invalid_expression |
1491 | cmp byte [edi+12],0 |
||
1492 | je neg_ok |
||
1493 | cmp [error_line],0 |
||
1494 | jne neg_ok |
||
1495 | mov eax,[current_line] |
||
1496 | mov [error_line],eax |
||
1497 | mov [error],invalid_use_of_symbol |
||
1498 | neg_ok: |
||
31 | halyavin | 1499 | mov eax,[edi] |
157 | heavyiron | 1500 | mov edx,[edi+4] |
1501 | mov dword [edi],0 |
||
1502 | mov dword [edi+4],0 |
||
1503 | sub [edi],eax |
||
1504 | sbb [edi+4],edx |
||
1505 | add edi,14h |
||
1506 | jmp calculation_loop |
||
1507 | calculate_rva: |
||
31 | halyavin | 1508 | cmp word [edi+8],0 |
157 | heavyiron | 1509 | jne invalid_expression |
1510 | cmp [output_format],5 |
||
1511 | je calculate_gotoff |
||
1512 | cmp [output_format],3 |
||
1513 | jne invalid_expression |
||
1514 | test [format_flags],8 |
||
1515 | jnz pe64_rva |
||
1516 | mov al,2 |
||
1517 | bt [resolver_flags],0 |
||
1518 | jc rva_type_ok |
||
1519 | xor al,al |
||
1520 | rva_type_ok: |
||
109 | heavyiron | 1521 | cmp byte [edi+12],al |
157 | heavyiron | 1522 | je rva_ok |
1523 | cmp [error_line],0 |
||
1524 | jne rva_ok |
||
1525 | mov eax,[current_line] |
||
1526 | mov [error_line],eax |
||
1527 | mov [error],invalid_use_of_symbol |
||
1528 | rva_ok: |
||
31 | halyavin | 1529 | mov byte [edi+12],0 |
157 | heavyiron | 1530 | mov eax,[code_start] |
1531 | mov eax,[eax+34h] |
||
1532 | cdq |
||
1533 | sub [edi],eax |
||
1534 | sbb [edi+4],edx |
||
1535 | add edi,14h |
||
1536 | jmp calculation_loop |
||
1537 | pe64_rva: |
||
31 | halyavin | 1538 | mov al,4 |
157 | heavyiron | 1539 | bt [resolver_flags],0 |
1540 | jc pe64_rva_type_ok |
||
1541 | xor al,al |
||
1542 | pe64_rva_type_ok: |
||
109 | heavyiron | 1543 | cmp byte [edi+12],al |
157 | heavyiron | 1544 | je pe64_rva_ok |
1545 | cmp [error_line],0 |
||
1546 | jne pe64_rva_ok |
||
1547 | mov eax,[current_line] |
||
1548 | mov [error_line],eax |
||
1549 | mov [error],invalid_use_of_symbol |
||
1550 | pe64_rva_ok: |
||
31 | halyavin | 1551 | mov byte [edi+12],0 |
157 | heavyiron | 1552 | mov eax,[code_start] |
1553 | mov edx,[eax+34h] |
||
1554 | mov eax,[eax+30h] |
||
1555 | sub [edi],eax |
||
1556 | sbb [edi+4],edx |
||
1557 | add edi,14h |
||
1558 | jmp calculation_loop |
||
1559 | calculate_gotoff: |
||
109 | heavyiron | 1560 | test [format_flags],8+1 |
157 | heavyiron | 1561 | jnz invalid_expression |
1562 | mov dl,5 |
||
174 | heavyiron | 1563 | cmp byte [edi+12],2 |
157 | heavyiron | 1564 | je change_value_type |
174 | heavyiron | 1565 | incorrect_change_of_value_type: |
1566 | cmp [error_line],0 |
||
157 | heavyiron | 1567 | jne change_value_type |
174 | heavyiron | 1568 | mov eax,[current_line] |
157 | heavyiron | 1569 | mov [error_line],eax |
1570 | mov [error],invalid_use_of_symbol |
||
1571 | change_value_type: |
||
174 | heavyiron | 1572 | mov byte [edi+12],dl |
1573 | add edi,14h |
||
157 | heavyiron | 1574 | jmp calculation_loop |
1575 | calculate_plt: |
||
174 | heavyiron | 1576 | cmp word [edi+8],0 |
1577 | jne invalid_expression |
||
1578 | cmp [output_format],5 |
||
1579 | jne invalid_expression |
||
1580 | test [format_flags],1 |
||
1581 | jnz invalid_expression |
||
1582 | mov dl,6 |
||
1583 | mov dh,2 |
||
1584 | test [format_flags],8 |
||
1585 | jz check_value_for_plt |
||
1586 | mov dh,4 |
||
1587 | check_value_for_plt: |
||
1588 | mov eax,[edi] |
||
1589 | or eax,[edi+4] |
||
1590 | jnz incorrect_change_of_value_type |
||
1591 | cmp byte [edi+12],dh |
||
1592 | jne incorrect_change_of_value_type |
||
1593 | mov eax,[edi+16] |
||
1594 | cmp byte [eax],81h |
||
1595 | jne incorrect_change_of_value_type |
||
1596 | jmp change_value_type |
||
1597 | div_64: |
||
31 | halyavin | 1598 | xor ebx,ebx |
157 | heavyiron | 1599 | cmp dword [edi],0 |
1600 | jne divider_ok |
||
1601 | cmp dword [edi+4],0 |
||
1602 | jne divider_ok |
||
1603 | cmp [next_pass_needed],0 |
||
1604 | je value_out_of_range |
||
1605 | jmp div_done |
||
1606 | divider_ok: |
||
31 | halyavin | 1607 | bt dword [esi+4],31 |
157 | heavyiron | 1608 | jnc div_first_sign_ok |
1609 | not dword [esi] |
||
1610 | not dword [esi+4] |
||
1611 | add dword [esi],1 |
||
1612 | adc dword [esi+4],0 |
||
1613 | not bx |
||
1614 | div_first_sign_ok: |
||
31 | halyavin | 1615 | bt dword [edi+4],31 |
157 | heavyiron | 1616 | jnc div_second_sign_ok |
1617 | not dword [edi] |
||
1618 | not dword [edi+4] |
||
1619 | add dword [edi],1 |
||
1620 | adc dword [edi+4],0 |
||
1621 | not bl |
||
1622 | div_second_sign_ok: |
||
31 | halyavin | 1623 | cmp dword [edi+4],0 |
157 | heavyiron | 1624 | jne div_high |
1625 | mov ecx,[edi] |
||
1626 | mov eax,[esi+4] |
||
1627 | xor edx,edx |
||
1628 | div ecx |
||
1629 | mov [esi+4],eax |
||
1630 | mov eax,[esi] |
||
1631 | div ecx |
||
1632 | mov [esi],eax |
||
1633 | mov eax,edx |
||
1634 | xor edx,edx |
||
1635 | jmp div_done |
||
1636 | div_high: |
||
31 | halyavin | 1637 | mov eax,[esi+4] |
157 | heavyiron | 1638 | xor edx,edx |
1639 | div dword [edi+4] |
||
1640 | mov ebx,[esi] |
||
1641 | mov [esi],eax |
||
1642 | mov dword [esi+4],0 |
||
1643 | mov ecx,edx |
||
1644 | mul dword [edi] |
||
1645 | div_high_loop: |
||
31 | halyavin | 1646 | cmp ecx,edx |
157 | heavyiron | 1647 | ja div_high_done |
1648 | jb div_high_large_correction |
||
1649 | cmp ebx,eax |
||
1650 | jae div_high_done |
||
1651 | div_high_correction: |
||
31 | halyavin | 1652 | dec dword [esi] |
157 | heavyiron | 1653 | sub eax,[edi] |
1654 | sbb edx,[edi+4] |
||
1655 | jnc div_high_loop |
||
1656 | div_high_done: |
||
31 | halyavin | 1657 | sub ebx,eax |
157 | heavyiron | 1658 | sbb ecx,edx |
1659 | mov edx,ecx |
||
1660 | mov eax,ebx |
||
1661 | ret |
||
1662 | div_high_large_correction: |
||
31 | halyavin | 1663 | push eax edx |
157 | heavyiron | 1664 | mov eax,edx |
1665 | sub eax,ecx |
||
1666 | xor edx,edx |
||
1667 | div dword [edi+4] |
||
1668 | shr eax,1 |
||
1669 | jz div_high_small_correction |
||
1670 | sub [esi],eax |
||
1671 | push eax |
||
1672 | mul dword [edi+4] |
||
1673 | sub dword [esp+4],eax |
||
1674 | pop eax |
||
1675 | mul dword [edi] |
||
1676 | sub dword [esp+4],eax |
||
1677 | sbb dword [esp],edx |
||
1678 | pop edx eax |
||
1679 | jmp div_high_loop |
||
1680 | div_high_small_correction: |
||
31 | halyavin | 1681 | pop edx eax |
157 | heavyiron | 1682 | jmp div_high_correction |
1683 | div_done: |
||
31 | halyavin | 1684 | or bh,bh |
157 | heavyiron | 1685 | jz remainder_ok |
1686 | not eax |
||
1687 | not edx |
||
1688 | add eax,1 |
||
1689 | adc edx,0 |
||
1690 | remainder_ok: |
||
31 | halyavin | 1691 | or bl,bl |
157 | heavyiron | 1692 | jz div_ok |
1693 | not dword [esi] |
||
1694 | not dword [esi+4] |
||
1695 | add dword [esi],1 |
||
1696 | adc dword [esi+4],0 |
||
1697 | div_ok: |
||
31 | halyavin | 1698 | ret |
157 | heavyiron | 1699 | convert_fp: |
31 | halyavin | 1700 | inc esi |
157 | heavyiron | 1701 | mov word [edi+8],0 |
1702 | mov byte [edi+12],0 |
||
1703 | mov al,[value_size] |
||
1704 | cmp al,4 |
||
1705 | je convert_fp_dword |
||
1706 | cmp al,8 |
||
1707 | je convert_fp_qword |
||
1708 | jmp invalid_value |
||
1709 | convert_fp_dword: |
||
31 | halyavin | 1710 | xor eax,eax |
157 | heavyiron | 1711 | cmp word [esi+8],8000h |
1712 | je fp_dword_store |
||
1713 | mov bx,[esi+8] |
||
1714 | mov eax,[esi+4] |
||
1715 | shl eax,1 |
||
1716 | shr eax,9 |
||
1717 | jnc fp_dword_ok |
||
1718 | inc eax |
||
1719 | bt eax,23 |
||
1720 | jnc fp_dword_ok |
||
1721 | and eax,1 shl 23 - 1 |
||
1722 | inc bx |
||
1723 | shr eax,1 |
||
1724 | fp_dword_ok: |
||
31 | halyavin | 1725 | add bx,7Fh |
157 | heavyiron | 1726 | cmp bx,100h |
1727 | jae value_out_of_range |
||
1728 | shl ebx,23 |
||
1729 | or eax,ebx |
||
1730 | fp_dword_store: |
||
31 | halyavin | 1731 | mov bl,[esi+11] |
157 | heavyiron | 1732 | shl ebx,31 |
1733 | or eax,ebx |
||
1734 | mov [edi],eax |
||
1735 | xor eax,eax |
||
1736 | mov [edi+4],eax |
||
1737 | add esi,13 |
||
1738 | ret |
||
1739 | convert_fp_qword: |
||
31 | halyavin | 1740 | xor eax,eax |
157 | heavyiron | 1741 | xor edx,edx |
1742 | cmp word [esi+8],8000h |
||
1743 | je fp_qword_store |
||
1744 | mov bx,[esi+8] |
||
1745 | mov eax,[esi] |
||
1746 | mov edx,[esi+4] |
||
1747 | add eax,eax |
||
1748 | adc edx,edx |
||
1749 | mov ecx,edx |
||
1750 | shr edx,12 |
||
1751 | shrd eax,ecx,12 |
||
1752 | jnc fp_qword_ok |
||
1753 | add eax,1 |
||
1754 | adc edx,0 |
||
1755 | bt edx,20 |
||
1756 | jnc fp_qword_ok |
||
1757 | and edx,1 shl 20 - 1 |
||
1758 | inc bx |
||
1759 | shr edx,1 |
||
1760 | rcr eax,1 |
||
1761 | fp_qword_ok: |
||
31 | halyavin | 1762 | add bx,3FFh |
157 | heavyiron | 1763 | cmp bx,800h |
1764 | jae value_out_of_range |
||
1765 | shl ebx,20 |
||
1766 | or edx,ebx |
||
1767 | fp_qword_store: |
||
31 | halyavin | 1768 | mov bl,[esi+11] |
157 | heavyiron | 1769 | shl ebx,31 |
1770 | or edx,ebx |
||
1771 | mov [edi],eax |
||
1772 | mov [edi+4],edx |
||
1773 | add esi,13 |
||
1774 | ret |
||
1775 | get_string_value: |
||
31 | halyavin | 1776 | inc esi |
157 | heavyiron | 1777 | lods dword [esi] |
1778 | mov ecx,eax |
||
1779 | cmp ecx,8 |
||
1780 | ja value_out_of_range |
||
1781 | mov edx,edi |
||
1782 | xor eax,eax |
||
1783 | stos dword [edi] |
||
1784 | stos dword [edi] |
||
1785 | mov edi,edx |
||
1786 | rep movs byte [edi],[esi] |
||
1787 | mov edi,edx |
||
1788 | inc esi |
||
1789 | mov word [edi+8],0 |
||
1790 | mov byte [edi+12],0 |
||
1791 | ret |
||
1792 | |||
31 | halyavin | 1793 | |
1794 | mov [value_size],1 |
||
157 | heavyiron | 1795 | mov [size_override],-1 |
1796 | call calculate_expression |
||
1797 | mov eax,[edi+16] |
||
1798 | mov [symbol_identifier],eax |
||
1799 | mov [value_type],0 |
||
1800 | cmp word [edi+8],0 |
||
1801 | jne invalid_value |
||
1802 | cmp byte [edi+12],0 |
||
1803 | je check_byte_value |
||
1804 | cmp [error_line],0 |
||
1805 | jne check_byte_value |
||
1806 | mov eax,[current_line] |
||
1807 | mov [error_line],eax |
||
1808 | mov [error],invalid_use_of_symbol |
||
1809 | check_byte_value: |
||
31 | halyavin | 1810 | mov eax,[edi] |
157 | heavyiron | 1811 | mov edx,[edi+4] |
1812 | or edx,edx |
||
1813 | jz byte_positive |
||
1814 | cmp edx,-1 |
||
1815 | jne range_exceeded |
||
1816 | cmp eax,-80h |
||
1817 | jb range_exceeded |
||
1818 | ret |
||
1819 | byte_positive: |
||
31 | halyavin | 1820 | cmp eax,100h |
157 | heavyiron | 1821 | jae range_exceeded |
1822 | return_byte_value: |
||
31 | halyavin | 1823 | ret |
157 | heavyiron | 1824 | range_exceeded: |
31 | halyavin | 1825 | xor eax,eax |
157 | heavyiron | 1826 | xor edx,edx |
1827 | cmp [error_line],0 |
||
1828 | jne return_byte_value |
||
1829 | mov ecx,[current_line] |
||
1830 | mov [error_line],ecx |
||
1831 | mov [error],value_out_of_range |
||
1832 | ret |
||
1833 | get_word_value: |
||
31 | halyavin | 1834 | mov [value_size],2 |
157 | heavyiron | 1835 | mov [size_override],-1 |
1836 | call calculate_expression |
||
1837 | cmp word [edi+8],0 |
||
220 | heavyiron | 1838 | jne invalid_value |
1839 | mov eax,[edi+16] |
||
157 | heavyiron | 1840 | mov [symbol_identifier],eax |
1841 | mov al,[edi+12] |
||
1842 | mov [value_type],al |
||
1843 | cmp al,2 |
||
1844 | jb check_word_value |
||
1845 | cmp [error_line],0 |
||
1846 | jne check_word_value |
||
1847 | mov eax,[current_line] |
||
1848 | mov [error_line],eax |
||
1849 | mov [error],invalid_use_of_symbol |
||
1850 | check_word_value: |
||
31 | halyavin | 1851 | mov eax,[edi] |
157 | heavyiron | 1852 | mov edx,[edi+4] |
1853 | or edx,edx |
||
1854 | jz word_positive |
||
1855 | cmp edx,-1 |
||
1856 | jne range_exceeded |
||
1857 | cmp eax,-8000h |
||
1858 | jb range_exceeded |
||
1859 | ret |
||
1860 | word_positive: |
||
31 | halyavin | 1861 | cmp eax,10000h |
157 | heavyiron | 1862 | jae range_exceeded |
1863 | ret |
||
1864 | get_dword_value: |
||
31 | halyavin | 1865 | mov [value_size],4 |
157 | heavyiron | 1866 | mov [size_override],-1 |
1867 | call calculate_expression |
||
1868 | cmp word [edi+8],0 |
||
220 | heavyiron | 1869 | jne invalid_value |
1870 | mov eax,[edi+16] |
||
157 | heavyiron | 1871 | mov [symbol_identifier],eax |
1872 | mov al,[edi+12] |
||
1873 | mov [value_type],al |
||
1874 | cmp al,4 |
||
1875 | jne check_dword_value |
||
1876 | mov [value_type],2 |
||
1877 | mov eax,[edi] |
||
1878 | cdq |
||
1879 | cmp edx,[edi+4] |
||
1880 | jne range_exceeded |
||
1881 | ret |
||
1882 | check_dword_value: |
||
31 | halyavin | 1883 | mov eax,[edi] |
157 | heavyiron | 1884 | mov edx,[edi+4] |
1885 | or edx,edx |
||
1886 | jz dword_positive |
||
1887 | cmp edx,-1 |
||
1888 | jne range_exceeded |
||
1889 | bt eax,31 |
||
1890 | jnc range_exceeded |
||
1891 | dword_positive: |
||
31 | halyavin | 1892 | ret |
157 | heavyiron | 1893 | get_pword_value: |
31 | halyavin | 1894 | mov [value_size],6 |
157 | heavyiron | 1895 | mov [size_override],-1 |
1896 | call calculate_expression |
||
1897 | mov eax,[edi+16] |
||
1898 | mov [symbol_identifier],eax |
||
1899 | cmp word [edi+8],0 |
||
1900 | jne invalid_value |
||
1901 | mov al,[edi+12] |
||
1902 | mov [value_type],al |
||
1903 | cmp al,4 |
||
1904 | jne check_pword_value |
||
1905 | cmp [error_line],0 |
||
1906 | jne check_pword_value |
||
1907 | mov eax,[current_line] |
||
1908 | mov [error_line],eax |
||
1909 | mov [error],invalid_use_of_symbol |
||
1910 | check_pword_value: |
||
31 | halyavin | 1911 | mov eax,[edi] |
157 | heavyiron | 1912 | mov edx,[edi+4] |
1913 | cmp edx,10000h |
||
1914 | jge range_exceeded |
||
1915 | cmp edx,-8000h |
||
1916 | jl range_exceeded |
||
1917 | ret |
||
1918 | get_qword_value: |
||
31 | halyavin | 1919 | mov [value_size],8 |
157 | heavyiron | 1920 | mov [size_override],-1 |
1921 | call calculate_expression |
||
1922 | cmp word [edi+8],0 |
||
220 | heavyiron | 1923 | jne invalid_value |
1924 | mov eax,[edi+16] |
||
157 | heavyiron | 1925 | mov [symbol_identifier],eax |
1926 | mov al,[edi+12] |
||
1927 | mov [value_type],al |
||
1928 | check_qword_value: |
||
31 | halyavin | 1929 | mov eax,[edi] |
157 | heavyiron | 1930 | mov edx,[edi+4] |
1931 | ret |
||
1932 | get_value: |
||
31 | halyavin | 1933 | mov [operand_size],0 |
157 | heavyiron | 1934 | lods byte [esi] |
1935 | call get_size_operator |
||
1936 | cmp al,'(' |
||
1937 | jne invalid_value |
||
1938 | mov al,[operand_size] |
||
1939 | cmp al,1 |
||
1940 | je value_byte |
||
1941 | cmp al,2 |
||
1942 | je value_word |
||
1943 | cmp al,4 |
||
1944 | je value_dword |
||
1945 | cmp al,6 |
||
1946 | je value_pword |
||
1947 | cmp al,8 |
||
1948 | je value_qword |
||
1949 | or al,al |
||
1950 | jnz invalid_value |
||
1951 | value_qword: |
||
31 | halyavin | 1952 | call get_qword_value |
157 | heavyiron | 1953 | ret |
1954 | value_pword: |
||
31 | halyavin | 1955 | call get_pword_value |
157 | heavyiron | 1956 | movzx edx,dx |
1957 | ret |
||
1958 | value_dword: |
||
31 | halyavin | 1959 | call get_dword_value |
157 | heavyiron | 1960 | xor edx,edx |
1961 | ret |
||
1962 | value_word: |
||
31 | halyavin | 1963 | call get_word_value |
157 | heavyiron | 1964 | xor edx,edx |
1965 | movzx eax,ax |
||
1966 | ret |
||
1967 | value_byte: |
||
31 | halyavin | 1968 | call get_byte_value |
157 | heavyiron | 1969 | xor edx,edx |
1970 | movzx eax,al |
||
1971 | ret |
||
1972 | get_address_word_value: |
||
220 | heavyiron | 1973 | mov [address_size],2 |
1974 | mov [value_size],2 |
||
1975 | jmp calculate_address |
||
1976 | get_address_dword_value: |
||
1977 | mov [address_size],4 |
||
1978 | mov [value_size],4 |
||
1979 | jmp calculate_address |
||
1980 | get_address_qword_value: |
||
1981 | mov [address_size],8 |
||
1982 | mov [value_size],8 |
||
1983 | jmp calculate_address |
||
1984 | get_address_value: |
||
31 | halyavin | 1985 | mov [address_size],0 |
157 | heavyiron | 1986 | mov [value_size],8 |
1987 | calculate_address: |
||
31 | halyavin | 1988 | cmp byte [esi],'.' |
157 | heavyiron | 1989 | je invalid_address |
1990 | call calculate_expression |
||
1991 | mov eax,[edi+16] |
||
1992 | mov [address_symbol],eax |
||
1993 | mov al,[edi+12] |
||
1994 | mov [value_type],al |
||
1995 | cmp al,6 |
||
607 | heavyiron | 1996 | je plt_address |
1997 | cmp al,5 |
||
157 | heavyiron | 1998 | je gotoff_address |
1999 | ja invalid_use_of_symbol |
||
174 | heavyiron | 2000 | test al,1 |
157 | heavyiron | 2001 | jnz invalid_use_of_symbol |
2002 | or al,al |
||
2003 | jz address_size_ok |
||
2004 | shl al,5 |
||
2005 | jmp address_symbol_ok |
||
2006 | gotoff_address: |
||
109 | heavyiron | 2007 | plt_address: |
607 | heavyiron | 2008 | mov al,40h |
157 | heavyiron | 2009 | address_symbol_ok: |
31 | halyavin | 2010 | mov ah,[address_size] |
157 | heavyiron | 2011 | or [address_size],al |
2012 | shr al,4 |
||
2013 | or ah,ah |
||
2014 | jz address_size_ok |
||
2015 | cmp al,ah |
||
2016 | je address_size_ok |
||
2017 | cmp ax,0804h |
||
340 | heavyiron | 2018 | jne address_sizes_do_not_agree |
157 | heavyiron | 2019 | mov [value_type],2 |
2020 | mov eax,[edi] |
||
2021 | cdq |
||
2022 | cmp edx,[edi+4] |
||
2023 | je address_size_ok |
||
2024 | cmp [error_line],0 |
||
2025 | jne address_size_ok |
||
2026 | mov ecx,[current_line] |
||
2027 | mov [error_line],ecx |
||
2028 | mov [error],value_out_of_range |
||
2029 | address_size_ok: |
||
109 | heavyiron | 2030 | xor ebx,ebx |
174 | heavyiron | 2031 | xor ecx,ecx |
2032 | mov cl,[value_type] |
||
2033 | shl ecx,16 |
||
2034 | mov ch,[address_size] |
||
157 | heavyiron | 2035 | cmp word [edi+8],0 |
2036 | je check_immediate_address |
||
2037 | mov al,[edi+8] |
||
2038 | mov dl,[edi+10] |
||
2039 | call get_address_register |
||
2040 | mov al,[edi+9] |
||
2041 | mov dl,[edi+11] |
||
2042 | call get_address_register |
||
2043 | mov ax,bx |
||
2044 | shr ah,4 |
||
2045 | shr al,4 |
||
2046 | or bh,bh |
||
2047 | jz check_address_registers |
||
2048 | or bl,bl |
||
2049 | jz check_address_registers |
||
2050 | cmp al,ah |
||
2051 | jne invalid_address |
||
2052 | check_address_registers: |
||
31 | halyavin | 2053 | or al,ah |
157 | heavyiron | 2054 | mov ah,[address_size] |
2055 | and ah,0Fh |
||
2056 | jz address_registers_sizes_ok |
||
2057 | cmp al,ah |
||
2058 | jne address_sizes_do_not_match |
||
176 | heavyiron | 2059 | address_registers_sizes_ok: |
157 | heavyiron | 2060 | cmp al,4 |
2061 | je sib_allowed |
||
2062 | cmp al,8 |
||
2063 | je sib_allowed |
||
2064 | cmp al,0Fh |
||
176 | heavyiron | 2065 | je check_ip_relative_address |
2066 | or cl,cl |
||
157 | heavyiron | 2067 | jz check_word_value |
2068 | cmp cl,1 |
||
2069 | je check_word_value |
||
2070 | jmp invalid_address |
||
2071 | address_sizes_do_not_match: |
||
176 | heavyiron | 2072 | cmp al,0Fh |
2073 | jne invalid_address |
||
2074 | mov al,bh |
||
2075 | and al,0Fh |
||
2076 | cmp al,ah |
||
2077 | jne invalid_address |
||
2078 | check_ip_relative_address: |
||
2079 | cmp bh,0F4h |
||
2080 | je check_dword_value |
||
2081 | cmp bh,0F8h |
||
2082 | jne invalid_address |
||
2083 | mov eax,[edi] |
||
2084 | cdq |
||
2085 | cmp edx,[edi+4] |
||
2086 | jne range_exceeded |
||
2087 | ret |
||
2088 | get_address_register: |
||
31 | halyavin | 2089 | or al,al |
157 | heavyiron | 2090 | jz address_register_ok |
2091 | cmp dl,1 |
||
2092 | jne scaled_register |
||
2093 | or bh,bh |
||
2094 | jnz scaled_register |
||
2095 | mov bh,al |
||
2096 | address_register_ok: |
||
31 | halyavin | 2097 | ret |
157 | heavyiron | 2098 | scaled_register: |
31 | halyavin | 2099 | or bl,bl |
157 | heavyiron | 2100 | jnz invalid_address |
2101 | mov bl,al |
||
2102 | mov cl,dl |
||
2103 | jmp address_register_ok |
||
2104 | sib_allowed: |
||
31 | halyavin | 2105 | or bh,bh |
157 | heavyiron | 2106 | jnz check_index_scale |
2107 | cmp cl,2 |
||
2108 | je special_index_scale |
||
2109 | cmp cl,3 |
||
2110 | je special_index_scale |
||
2111 | cmp cl,5 |
||
2112 | je special_index_scale |
||
2113 | cmp cl,9 |
||
2114 | je special_index_scale |
||
2115 | check_index_scale: |
||
31 | halyavin | 2116 | or cl,cl |
157 | heavyiron | 2117 | jz check_immediate_address |
220 | heavyiron | 2118 | cmp cl,1 |
157 | heavyiron | 2119 | je check_immediate_address |
220 | heavyiron | 2120 | cmp cl,2 |
157 | heavyiron | 2121 | je check_immediate_address |
220 | heavyiron | 2122 | cmp cl,4 |
157 | heavyiron | 2123 | je check_immediate_address |
220 | heavyiron | 2124 | cmp cl,8 |
157 | heavyiron | 2125 | je check_immediate_address |
220 | heavyiron | 2126 | jmp invalid_address |
157 | heavyiron | 2127 | special_index_scale: |
31 | halyavin | 2128 | mov bh,bl |
157 | heavyiron | 2129 | dec cl |
2130 | check_immediate_address: |
||
31 | halyavin | 2131 | mov al,[address_size] |
220 | heavyiron | 2132 | and al,0Fh |
2133 | cmp al,2 |
||
2134 | je check_word_value |
||
2135 | cmp al,4 |
||
2136 | je check_dword_value |
||
2137 | cmp al,8 |
||
2138 | je check_qword_value |
||
2139 | or al,al |
||
2140 | jnz invalid_value |
||
2141 | cmp [code_type],64 |
||
157 | heavyiron | 2142 | jne check_dword_value |
2143 | jmp check_qword_value |
||
2144 | calculate_relative_offset: |
||
174 | heavyiron | 2145 | cmp [value_undefined],0 |
2146 | jne relative_offset_ok |
||
2147 | test bh,bh |
||
226 | heavyiron | 2148 | setne ch |
2149 | cmp bx,word [org_registers] |
||
2150 | je origin_registers_ok |
||
2151 | xchg bh,bl |
||
2152 | xchg ch,cl |
||
2153 | cmp bx,word [org_registers] |
||
2154 | jne invalid_value |
||
2155 | origin_registers_ok: |
||
2156 | cmp cx,word [org_registers+2] |
||
2157 | jne invalid_value |
||
2158 | add eax,dword [org_origin] |
||
174 | heavyiron | 2159 | adc edx,dword [org_origin+4] |
2160 | sub eax,edi |
||
2161 | sbb edx,0 |
||
2162 | mov bl,[value_type] |
||
2163 | or bl,bl |
||
2164 | je relative_offset_ok |
||
2165 | test bl,1 |
||
2166 | jnz invalid_use_of_symbol |
||
2167 | cmp bl,6 |
||
2168 | je plt_relative_offset |
||
2169 | cmp bl,[labels_type] |
||
2170 | jne invalid_use_of_symbol |
||
2171 | mov [value_type],0 |
||
2172 | mov ecx,[address_symbol] |
||
220 | heavyiron | 2173 | mov [symbol_identifier],ecx |
2174 | cmp ecx,[org_symbol] |
||
174 | heavyiron | 2175 | je relative_offset_ok |
2176 | mov [value_type],3 |
||
2177 | relative_offset_ok: |
||
2178 | ret |
||
157 | heavyiron | 2179 | plt_relative_offset: |
174 | heavyiron | 2180 | mov [value_type],7 |
2181 | ret |
||
157 | heavyiron | 2182 | |
31 | halyavin | 2183 | |
109 | heavyiron | 2184 | xor al,al |
242 | heavyiron | 2185 | preevaluate_embedded_logical_expression: |
2186 | mov [logical_value_wrapping],al |
||
2187 | push edi |
||
157 | heavyiron | 2188 | call preevaluate_logical_value |
2189 | preevaluation_loop: |
||
109 | heavyiron | 2190 | cmp al,0FFh |
157 | heavyiron | 2191 | je invalid_logical_expression |
2192 | mov dl,[esi] |
||
2193 | inc esi |
||
2194 | cmp dl,'|' |
||
2195 | je preevaluate_or |
||
2196 | cmp dl,'&' |
||
2197 | je preevaluate_and |
||
2198 | cmp dl,'}' |
||
2199 | je preevaluation_done |
||
2200 | or dl,dl |
||
2201 | jnz invalid_logical_expression |
||
2202 | preevaluation_done: |
||
109 | heavyiron | 2203 | pop edx |
157 | heavyiron | 2204 | dec esi |
2205 | ret |
||
2206 | preevaluate_or: |
||
109 | heavyiron | 2207 | cmp al,'1' |
157 | heavyiron | 2208 | je quick_true |
2209 | cmp al,'0' |
||
2210 | je leave_only_following |
||
2211 | push edi |
||
2212 | mov al,dl |
||
2213 | stos byte [edi] |
||
2214 | call preevaluate_logical_value |
||
2215 | pop ebx |
||
2216 | cmp al,'0' |
||
2217 | je leave_only_preceding |
||
2218 | cmp al,'1' |
||
2219 | jne preevaluation_loop |
||
2220 | stos byte [edi] |
||
2221 | xor al,al |
||
2222 | jmp preevaluation_loop |
||
2223 | preevaluate_and: |
||
109 | heavyiron | 2224 | cmp al,'0' |
157 | heavyiron | 2225 | je quick_false |
2226 | cmp al,'1' |
||
2227 | je leave_only_following |
||
2228 | push edi |
||
2229 | mov al,dl |
||
2230 | stos byte [edi] |
||
2231 | call preevaluate_logical_value |
||
2232 | pop ebx |
||
2233 | cmp al,'1' |
||
2234 | je leave_only_preceding |
||
2235 | cmp al,'0' |
||
2236 | jne preevaluation_loop |
||
2237 | stos byte [edi] |
||
2238 | xor al,al |
||
2239 | jmp preevaluation_loop |
||
2240 | leave_only_following: |
||
109 | heavyiron | 2241 | mov edi,[esp] |
157 | heavyiron | 2242 | call preevaluate_logical_value |
2243 | jmp preevaluation_loop |
||
2244 | leave_only_preceding: |
||
109 | heavyiron | 2245 | mov edi,ebx |
157 | heavyiron | 2246 | xor al,al |
2247 | jmp preevaluation_loop |
||
2248 | quick_true: |
||
109 | heavyiron | 2249 | call skip_logical_value |
157 | heavyiron | 2250 | jc invalid_logical_expression |
2251 | mov edi,[esp] |
||
2252 | mov al,'1' |
||
2253 | jmp preevaluation_loop |
||
2254 | quick_false: |
||
109 | heavyiron | 2255 | call skip_logical_value |
157 | heavyiron | 2256 | jc invalid_logical_expression |
2257 | mov edi,[esp] |
||
2258 | mov al,'0' |
||
2259 | jmp preevaluation_loop |
||
2260 | invalid_logical_expression: |
||
109 | heavyiron | 2261 | pop edi |
157 | heavyiron | 2262 | mov esi,edi |
2263 | mov al,0FFh |
||
2264 | stos byte [edi] |
||
2265 | ret |
||
2266 | skip_logical_value: |
||
242 | heavyiron | 2267 | cmp byte [esi],'~' |
157 | heavyiron | 2268 | jne negation_skipped |
2269 | inc esi |
||
2270 | jmp skip_logical_value |
||
2271 | negation_skipped: |
||
109 | heavyiron | 2272 | mov al,[esi] |
253 | heavyiron | 2273 | cmp al,'{' |
2274 | jne skip_simple_logical_value |
||
157 | heavyiron | 2275 | inc esi |
2276 | xchg al,[logical_value_wrapping] |
||
242 | heavyiron | 2277 | push eax |
2278 | skip_logical_expression: |
||
109 | heavyiron | 2279 | call skip_logical_value |
157 | heavyiron | 2280 | lods byte [esi] |
2281 | or al,al |
||
2282 | jz wrongly_structured_logical_expression |
||
2283 | cmp al,0Fh |
||
2284 | je wrongly_structured_logical_expression |
||
2285 | cmp al,'|' |
||
2286 | je skip_logical_expression |
||
2287 | cmp al,'&' |
||
2288 | je skip_logical_expression |
||
2289 | cmp al,'}' |
||
2290 | jne wrongly_structured_logical_expression |
||
242 | heavyiron | 2291 | pop eax |
2292 | mov [logical_value_wrapping],al |
||
2293 | logical_value_skipped: |
||
2294 | clc |
||
2295 | ret |
||
2296 | wrongly_structured_logical_expression: |
||
109 | heavyiron | 2297 | pop eax |
253 | heavyiron | 2298 | stc |
157 | heavyiron | 2299 | ret |
2300 | skip_simple_logical_value: |
||
109 | heavyiron | 2301 | mov [logical_value_parentheses],0 |
242 | heavyiron | 2302 | find_simple_logical_value_end: |
2303 | mov al,[esi] |
||
157 | heavyiron | 2304 | or al,al |
2305 | jz logical_value_skipped |
||
2306 | cmp al,0Fh |
||
2307 | je logical_value_skipped |
||
2308 | cmp al,'|' |
||
2309 | je logical_value_skipped |
||
2310 | cmp al,'&' |
||
2311 | je logical_value_skipped |
||
2312 | cmp al,'{' |
||
242 | heavyiron | 2313 | je skip_logical_value_internal_parenthesis |
2314 | cmp al,'}' |
||
2315 | jne skip_logical_value_symbol |
||
2316 | sub [logical_value_parentheses],1 |
||
2317 | jnc skip_logical_value_symbol |
||
2318 | cmp [logical_value_wrapping],'{' |
||
253 | heavyiron | 2319 | jne skip_logical_value_symbol |
242 | heavyiron | 2320 | jmp logical_value_skipped |
2321 | skip_logical_value_internal_parenthesis: |
||
2322 | inc [logical_value_parentheses] |
||
2323 | skip_logical_value_symbol: |
||
2324 | call skip_symbol |
||
157 | heavyiron | 2325 | jmp find_simple_logical_value_end |
242 | heavyiron | 2326 | preevaluate_logical_value: |
2327 | mov ebp,edi |
||
157 | heavyiron | 2328 | preevaluate_negation: |
109 | heavyiron | 2329 | cmp byte [esi],'~' |
157 | heavyiron | 2330 | jne preevaluate_negation_ok |
2331 | movs byte [edi],[esi] |
||
2332 | jmp preevaluate_negation |
||
2333 | preevaluate_negation_ok: |
||
109 | heavyiron | 2334 | mov ebx,esi |
157 | heavyiron | 2335 | cmp byte [esi],'{' |
2336 | jne preevaluate_simple_logical_value |
||
242 | heavyiron | 2337 | lods byte [esi] |
2338 | stos byte [edi] |
||
2339 | push ebp |
||
157 | heavyiron | 2340 | mov dl,[logical_value_wrapping] |
242 | heavyiron | 2341 | push edx |
2342 | call preevaluate_embedded_logical_expression |
||
2343 | pop edx |
||
2344 | mov [logical_value_wrapping],dl |
||
2345 | pop ebp |
||
157 | heavyiron | 2346 | cmp al,0FFh |
2347 | je invalid_logical_value |
||
2348 | cmp byte [esi],'}' |
||
2349 | jne invalid_logical_value |
||
2350 | or al,al |
||
2351 | jnz preevaluated_expression_value |
||
2352 | movs byte [edi],[esi] |
||
2353 | ret |
||
2354 | preevaluated_expression_value: |
||
109 | heavyiron | 2355 | inc esi |
157 | heavyiron | 2356 | lea edx,[edi-1] |
2357 | sub edx,ebp |
||
2358 | test edx,1 |
||
2359 | jz expression_negation_ok |
||
2360 | xor al,1 |
||
2361 | expression_negation_ok: |
||
109 | heavyiron | 2362 | mov edi,ebp |
157 | heavyiron | 2363 | ret |
2364 | invalid_logical_value: |
||
109 | heavyiron | 2365 | mov edi,ebp |
157 | heavyiron | 2366 | mov al,0FFh |
2367 | ret |
||
2368 | preevaluate_simple_logical_value: |
||
242 | heavyiron | 2369 | xor edx,edx |
2370 | mov [logical_value_parentheses],edx |
||
2371 | find_logical_value_boundaries: |
||
109 | heavyiron | 2372 | mov al,[esi] |
157 | heavyiron | 2373 | or al,al |
2374 | jz logical_value_boundaries_found |
||
2375 | cmp al,'{' |
||
242 | heavyiron | 2376 | je logical_value_internal_parentheses |
2377 | cmp al,'}' |
||
157 | heavyiron | 2378 | je logical_value_boundaries_parenthesis_close |
242 | heavyiron | 2379 | cmp al,'|' |
157 | heavyiron | 2380 | je logical_value_boundaries_found |
2381 | cmp al,'&' |
||
2382 | je logical_value_boundaries_found |
||
2383 | or edx,edx |
||
2384 | jnz next_symbol_in_logical_value |
||
2385 | cmp al,0F0h |
||
2386 | je preevaluable_logical_operator |
||
2387 | cmp al,0F7h |
||
2388 | je preevaluable_logical_operator |
||
2389 | cmp al,0F6h |
||
2390 | jne next_symbol_in_logical_value |
||
2391 | preevaluable_logical_operator: |
||
109 | heavyiron | 2392 | mov edx,esi |
157 | heavyiron | 2393 | next_symbol_in_logical_value: |
109 | heavyiron | 2394 | call skip_symbol |
157 | heavyiron | 2395 | jmp find_logical_value_boundaries |
2396 | logical_value_internal_parentheses: |
||
242 | heavyiron | 2397 | inc [logical_value_parentheses] |
2398 | jmp next_symbol_in_logical_value |
||
2399 | logical_value_boundaries_parenthesis_close: |
||
2400 | sub [logical_value_parentheses],1 |
||
2401 | jnc next_symbol_in_logical_value |
||
2402 | cmp [logical_value_wrapping],'{' |
||
2403 | jne next_symbol_in_logical_value |
||
2404 | logical_value_boundaries_found: |
||
109 | heavyiron | 2405 | or edx,edx |
157 | heavyiron | 2406 | jz non_preevaluable_logical_value |
2407 | mov al,[edx] |
||
2408 | cmp al,0F0h |
||
2409 | je compare_symbols |
||
2410 | cmp al,0F7h |
||
2411 | je compare_symbol_types |
||
2412 | cmp al,0F6h |
||
2413 | je scan_symbols_list |
||
2414 | non_preevaluable_logical_value: |
||
109 | heavyiron | 2415 | mov ecx,esi |
157 | heavyiron | 2416 | mov esi,ebx |
2417 | sub ecx,esi |
||
2418 | jz invalid_logical_value |
||
2419 | cmp esi,edi |
||
2420 | je leave_logical_value_intact |
||
2421 | rep movs byte [edi],[esi] |
||
2422 | xor al,al |
||
2423 | ret |
||
2424 | leave_logical_value_intact: |
||
109 | heavyiron | 2425 | add edi,ecx |
157 | heavyiron | 2426 | add esi,ecx |
2427 | xor al,al |
||
2428 | ret |
||
2429 | compare_symbols: |
||
31 | halyavin | 2430 | lea ecx,[esi-1] |
157 | heavyiron | 2431 | sub ecx,edx |
2432 | mov eax,edx |
||
2433 | sub eax,ebx |
||
2434 | cmp ecx,eax |
||
2435 | jne preevaluated_false |
||
2436 | push esi edi |
||
2437 | mov esi,ebx |
||
2438 | lea edi,[edx+1] |
||
2439 | repe cmps byte [esi],[edi] |
||
2440 | pop edi esi |
||
2441 | je preevaluated_true |
||
2442 | preevaluated_false: |
||
109 | heavyiron | 2443 | mov eax,edi |
157 | heavyiron | 2444 | sub eax,ebp |
2445 | test eax,1 |
||
2446 | jnz store_true |
||
2447 | store_false: |
||
109 | heavyiron | 2448 | mov edi,ebp |
157 | heavyiron | 2449 | mov al,'0' |
2450 | ret |
||
2451 | preevaluated_true: |
||
109 | heavyiron | 2452 | mov eax,edi |
157 | heavyiron | 2453 | sub eax,ebp |
2454 | test eax,1 |
||
2455 | jnz store_false |
||
2456 | store_true: |
||
109 | heavyiron | 2457 | mov edi,ebp |
157 | heavyiron | 2458 | mov al,'1' |
2459 | ret |
||
2460 | compare_symbol_types: |
||
31 | halyavin | 2461 | push esi |
157 | heavyiron | 2462 | lea esi,[edx+1] |
2463 | type_comparison: |
||
109 | heavyiron | 2464 | cmp esi,[esp] |
157 | heavyiron | 2465 | je types_compared |
2466 | mov al,[esi] |
||
2467 | cmp al,[ebx] |
||
2468 | jne different_type |
||
2469 | cmp al,'(' |
||
2470 | jne equal_type |
||
2471 | mov al,[esi+1] |
||
2472 | mov ah,[ebx+1] |
||
2473 | cmp al,ah |
||
2474 | je equal_type |
||
2475 | or al,al |
||
2476 | jz different_type |
||
2477 | or ah,ah |
||
2478 | jz different_type |
||
2479 | cmp al,'.' |
||
2480 | je different_type |
||
2481 | cmp ah,'.' |
||
2482 | je different_type |
||
2483 | equal_type: |
||
31 | halyavin | 2484 | call skip_symbol |
157 | heavyiron | 2485 | xchg esi,ebx |
2486 | call skip_symbol |
||
2487 | xchg esi,ebx |
||
2488 | jmp type_comparison |
||
2489 | types_compared: |
||
31 | halyavin | 2490 | pop esi |
157 | heavyiron | 2491 | cmp byte [ebx],0F7h |
2492 | jne preevaluated_false |
||
2493 | jmp preevaluated_true |
||
2494 | different_type: |
||
109 | heavyiron | 2495 | pop esi |
157 | heavyiron | 2496 | jmp preevaluated_false |
2497 | scan_symbols_list: |
||
31 | halyavin | 2498 | push edi esi |
157 | heavyiron | 2499 | lea esi,[edx+1] |
2500 | sub edx,ebx |
||
2501 | lods byte [esi] |
||
2502 | cmp al,'<' |
||
2503 | jne invalid_symbols_list |
||
2504 | get_next_from_list: |
||
109 | heavyiron | 2505 | mov edi,esi |
157 | heavyiron | 2506 | get_from_list: |
109 | heavyiron | 2507 | cmp byte [esi],',' |
157 | heavyiron | 2508 | je compare_in_list |
2509 | cmp byte [esi],'>' |
||
2510 | je compare_in_list |
||
2511 | cmp esi,[esp] |
||
2512 | jae invalid_symbols_list |
||
2513 | call skip_symbol |
||
2514 | jmp get_from_list |
||
2515 | compare_in_list: |
||
31 | halyavin | 2516 | mov ecx,esi |
157 | heavyiron | 2517 | sub ecx,edi |
2518 | cmp ecx,edx |
||
2519 | jne not_equal_length_in_list |
||
2520 | mov esi,ebx |
||
2521 | repe cmps byte [esi],[edi] |
||
2522 | mov esi,edi |
||
2523 | jne not_equal_in_list |
||
2524 | skip_rest_of_list: |
||
31 | halyavin | 2525 | cmp byte [esi],'>' |
157 | heavyiron | 2526 | je check_list_end |
2527 | cmp esi,[esp] |
||
2528 | jae invalid_symbols_list |
||
2529 | call skip_symbol |
||
2530 | jmp skip_rest_of_list |
||
2531 | check_list_end: |
||
109 | heavyiron | 2532 | inc esi |
157 | heavyiron | 2533 | cmp esi,[esp] |
2534 | jne invalid_symbols_list |
||
2535 | pop esi edi |
||
2536 | jmp preevaluated_true |
||
2537 | not_equal_in_list: |
||
31 | halyavin | 2538 | add esi,ecx |
157 | heavyiron | 2539 | not_equal_length_in_list: |
109 | heavyiron | 2540 | lods byte [esi] |
157 | heavyiron | 2541 | cmp al,',' |
2542 | je get_next_from_list |
||
2543 | cmp esi,[esp] |
||
2544 | jne invalid_symbols_list |
||
2545 | pop esi edi |
||
2546 | jmp preevaluated_false |
||
2547 | invalid_symbols_list: |
||
109 | heavyiron | 2548 | pop esi edi |
157 | heavyiron | 2549 | jmp invalid_logical_value |
2550 | |||
109 | heavyiron | 2551 | |
2552 | xor al,al |
||
242 | heavyiron | 2553 | calculate_embedded_logical_expression: |
2554 | mov [logical_value_wrapping],al |
||
2555 | call get_logical_value |
||
157 | heavyiron | 2556 | logical_loop: |
109 | heavyiron | 2557 | cmp byte [esi],'|' |
157 | heavyiron | 2558 | je logical_or |
2559 | cmp byte [esi],'&' |
||
2560 | je logical_and |
||
2561 | ret |
||
2562 | logical_or: |
||
109 | heavyiron | 2563 | inc esi |
157 | heavyiron | 2564 | or al,al |
2565 | jnz logical_value_already_determined |
||
2566 | push eax |
||
2567 | call get_logical_value |
||
2568 | pop ebx |
||
2569 | or al,bl |
||
2570 | jmp logical_loop |
||
2571 | logical_and: |
||
109 | heavyiron | 2572 | inc esi |
157 | heavyiron | 2573 | or al,al |
2574 | jz logical_value_already_determined |
||
2575 | push eax |
||
2576 | call get_logical_value |
||
2577 | pop ebx |
||
2578 | and al,bl |
||
2579 | jmp logical_loop |
||
2580 | logical_value_already_determined: |
||
109 | heavyiron | 2581 | push eax |
157 | heavyiron | 2582 | call skip_logical_value |
2583 | jc invalid_expression |
||
2584 | pop eax |
||
2585 | jmp logical_loop |
||
2586 | get_logical_value: |
||
242 | heavyiron | 2587 | xor al,al |
157 | heavyiron | 2588 | check_for_negation: |
109 | heavyiron | 2589 | cmp byte [esi],'~' |
157 | heavyiron | 2590 | jne negation_ok |
2591 | inc esi |
||
2592 | xor al,-1 |
||
2593 | jmp check_for_negation |
||
2594 | negation_ok: |
||
109 | heavyiron | 2595 | push eax |
157 | heavyiron | 2596 | mov al,[esi] |
2597 | cmp al,'{' |
||
2598 | je logical_expression |
||
2599 | cmp al,0FFh |
||
2600 | je invalid_expression |
||
2601 | cmp al,88h |
||
2602 | je check_for_defined |
||
2603 | cmp al,89h |
||
2604 | je check_for_used |
||
2605 | cmp al,'0' |
||
2606 | je given_false |
||
2607 | cmp al,'1' |
||
2608 | je given_true |
||
2609 | call get_value |
||
2610 | mov bl,[value_type] |
||
2611 | push eax edx ebx |
||
2612 | mov al,[esi] |
||
2613 | or al,al |
||
2614 | jz logical_number |
||
2615 | cmp al,0Fh |
||
2616 | je logical_number |
||
2617 | cmp al,'}' |
||
2618 | je logical_number |
||
2619 | cmp al,'&' |
||
2620 | je logical_number |
||
2621 | cmp al,'|' |
||
2622 | je logical_number |
||
2623 | inc esi |
||
2624 | mov [compare_type],al |
||
2625 | call get_value |
||
2626 | pop ebx |
||
2627 | cmp [next_pass_needed],0 |
||
2628 | jne values_ok |
||
2629 | cmp bl,[value_type] |
||
2630 | jne invalid_use_of_symbol |
||
2631 | values_ok: |
||
31 | halyavin | 2632 | pop ecx ebx |
157 | heavyiron | 2633 | cmp [compare_type],'=' |
2634 | je check_equal |
||
2635 | cmp [compare_type],'>' |
||
2636 | je check_greater |
||
2637 | cmp [compare_type],'<' |
||
2638 | je check_less |
||
2639 | cmp [compare_type],0F1h |
||
2640 | je check_not_equal |
||
2641 | cmp [compare_type],0F2h |
||
2642 | je check_not_less |
||
2643 | cmp [compare_type],0F3h |
||
2644 | je check_not_greater |
||
2645 | jmp invalid_expression |
||
2646 | check_equal: |
||
31 | halyavin | 2647 | cmp eax,ebx |
157 | heavyiron | 2648 | jne return_false |
2649 | cmp edx,ecx |
||
2650 | jne return_false |
||
2651 | jmp return_true |
||
2652 | check_greater: |
||
31 | halyavin | 2653 | cmp edx,ecx |
157 | heavyiron | 2654 | jl return_true |
2655 | jg return_false |
||
2656 | cmp eax,ebx |
||
2657 | jb return_true |
||
2658 | jae return_false |
||
2659 | check_less: |
||
31 | halyavin | 2660 | cmp edx,ecx |
157 | heavyiron | 2661 | jl return_false |
2662 | jg return_true |
||
2663 | cmp eax,ebx |
||
2664 | jbe return_false |
||
2665 | ja return_true |
||
2666 | check_not_less: |
||
31 | halyavin | 2667 | cmp edx,ecx |
157 | heavyiron | 2668 | jl return_true |
2669 | jg return_false |
||
2670 | cmp eax,ebx |
||
2671 | jbe return_true |
||
2672 | ja return_false |
||
2673 | check_not_greater: |
||
31 | halyavin | 2674 | cmp edx,ecx |
157 | heavyiron | 2675 | jl return_false |
2676 | jg return_true |
||
2677 | cmp eax,ebx |
||
2678 | jb return_false |
||
2679 | jae return_true |
||
2680 | check_not_equal: |
||
31 | halyavin | 2681 | cmp eax,ebx |
157 | heavyiron | 2682 | jne return_true |
2683 | cmp edx,ecx |
||
2684 | jne return_true |
||
2685 | jmp return_false |
||
2686 | logical_number: |
||
31 | halyavin | 2687 | pop ebx edx eax |
157 | heavyiron | 2688 | or bl,bl |
2689 | jnz invalid_expression |
||
2690 | or eax,edx |
||
2691 | jnz return_true |
||
2692 | jmp return_false |
||
2693 | check_for_defined: |
||
31 | halyavin | 2694 | or bl,-1 |
157 | heavyiron | 2695 | lods word [esi] |
2696 | cmp ah,'(' |
||
2697 | jne invalid_expression |
||
2698 | check_expression: |
||
31 | halyavin | 2699 | lods byte [esi] |
157 | heavyiron | 2700 | or al,al |
2701 | jz defined_string |
||
2702 | cmp al,'.' |
||
2703 | je defined_fp_value |
||
2704 | cmp al,')' |
||
2705 | je expression_checked |
||
2706 | cmp al,'!' |
||
196 | heavyiron | 2707 | je invalid_expression |
2708 | cmp al,0Fh |
||
157 | heavyiron | 2709 | je check_expression |
2710 | cmp al,10h |
||
2711 | je defined_register |
||
2712 | cmp al,11h |
||
2713 | je check_if_symbol_defined |
||
2714 | cmp al,80h |
||
2715 | jae check_expression |
||
2716 | movzx eax,al |
||
2717 | add esi,eax |
||
2718 | jmp check_expression |
||
2719 | defined_register: |
||
31 | halyavin | 2720 | inc esi |
157 | heavyiron | 2721 | jmp check_expression |
2722 | defined_fp_value: |
||
31 | halyavin | 2723 | add esi,12 |
157 | heavyiron | 2724 | jmp expression_checked |
2725 | defined_string: |
||
31 | halyavin | 2726 | lods dword [esi] |
157 | heavyiron | 2727 | add esi,eax |
2728 | inc esi |
||
2729 | jmp expression_checked |
||
2730 | check_if_symbol_defined: |
||
31 | halyavin | 2731 | lods dword [esi] |
157 | heavyiron | 2732 | cmp eax,-1 |
2733 | je invalid_expression |
||
2734 | cmp eax,0Fh |
||
2735 | jb check_expression |
||
2736 | je reserved_word_used_as_symbol |
||
2737 | test byte [eax+8],4 |
||
2738 | jnz no_prediction |
||
2739 | test byte [eax+8],1 |
||
2740 | jz symbol_predicted_undefined |
||
2741 | mov cx,[current_pass] |
||
2742 | sub cx,[eax+16] |
||
2743 | jz check_expression |
||
2744 | cmp cx,1 |
||
2745 | ja symbol_predicted_undefined |
||
2746 | or byte [eax+8],40h+80h |
||
2747 | jmp check_expression |
||
2748 | no_prediction: |
||
31 | halyavin | 2749 | test byte [eax+8],1 |
157 | heavyiron | 2750 | jz symbol_undefined |
2751 | mov cx,[current_pass] |
||
2752 | sub cx,[eax+16] |
||
2753 | jz check_expression |
||
2754 | jmp symbol_undefined |
||
2755 | symbol_predicted_undefined: |
||
31 | halyavin | 2756 | or byte [eax+8],40h |
157 | heavyiron | 2757 | and byte [eax+8],not 80h |
2758 | symbol_undefined: |
||
31 | halyavin | 2759 | xor bl,bl |
157 | heavyiron | 2760 | jmp check_expression |
2761 | expression_checked: |
||
31 | halyavin | 2762 | mov al,bl |
157 | heavyiron | 2763 | jmp logical_value_ok |
2764 | check_for_used: |
||
31 | halyavin | 2765 | lods word [esi] |
157 | heavyiron | 2766 | cmp ah,2 |
2767 | jne invalid_expression |
||
2768 | lods dword [esi] |
||
2769 | cmp eax,0Fh |
||
2770 | jb invalid_use_of_symbol |
||
2771 | je reserved_word_used_as_symbol |
||
2772 | inc esi |
||
2773 | test byte [eax+8],8 |
||
2774 | jz not_used |
||
2775 | mov cx,[current_pass] |
||
2776 | sub cx,[eax+18] |
||
2777 | jz return_true |
||
2778 | cmp cx,1 |
||
2779 | ja not_used |
||
2780 | or byte [eax+8],10h+20h |
||
2781 | jmp return_true |
||
2782 | not_used: |
||
31 | halyavin | 2783 | or byte [eax+8],10h |
157 | heavyiron | 2784 | and byte [eax+8],not 20h |
2785 | jmp return_false |
||
2786 | given_false: |
||
109 | heavyiron | 2787 | inc esi |
157 | heavyiron | 2788 | return_false: |
31 | halyavin | 2789 | xor al,al |
157 | heavyiron | 2790 | jmp logical_value_ok |
2791 | given_true: |
||
109 | heavyiron | 2792 | inc esi |
157 | heavyiron | 2793 | return_true: |
31 | halyavin | 2794 | or al,-1 |
157 | heavyiron | 2795 | jmp logical_value_ok |
2796 | logical_expression: |
||
31 | halyavin | 2797 | lods byte [esi] |
242 | heavyiron | 2798 | mov dl,[logical_value_wrapping] |
2799 | push edx |
||
2800 | call calculate_embedded_logical_expression |
||
2801 | pop edx |
||
2802 | mov [logical_value_wrapping],dl |
||
2803 | push eax |
||
157 | heavyiron | 2804 | lods byte [esi] |
2805 | cmp al,'}' |
||
2806 | jne invalid_expression |
||
2807 | pop eax |
||
2808 | logical_value_ok: |
||
31 | halyavin | 2809 | pop ebx |
157 | heavyiron | 2810 | xor al,bl |
2811 | ret' |
||
2812 | >' |