Subversion Repositories Kolibri OS

Rev

Rev 220 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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