Subversion Repositories Kolibri OS

Rev

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

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