Subversion Repositories Kolibri OS

Rev

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