Subversion Repositories Kolibri OS

Rev

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