Subversion Repositories Kolibri OS

Rev

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