Subversion Repositories Kolibri OS

Rev

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