Subversion Repositories Kolibri OS

Rev

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