Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
 
2
; Copyright (c) 1999-2005, Tomasz Grysztar.
3
; All rights reserved.
4
5
 
6
	mov	eax,[memory_end]
7
	mov	[labels_list],eax
8
	mov	eax,[additional_memory]
9
	mov	[free_additional_memory],eax
10
	xor	eax,eax
11
	mov	[current_locals_prefix],eax
12
	mov	[anonymous_reverse],eax
13
	mov	[anonymous_forward],eax
14
	mov	[hash_tree],eax
15
	push	[memory_end]
16
	mov	esi,[memory_start]
17
	mov	edi,[source_start]
18
      parser_loop:
19
	mov	[current_line],esi
20
	lea	eax,[edi+100h]
21
	cmp	eax,[memory_end]
22
	jae	out_of_memory
23
	cmp	byte [esi+16],0
24
	je	empty_line
25
	mov	al,0Fh
26
	stos	byte [edi]
27
	mov	eax,esi
28
	stos	dword [edi]
29
	add	esi,16
30
	call	parse_line
31
      parse_next_line:
32
	cmp	esi,[source_start]
33
	jb	parser_loop
34
	xor	al,al
35
	stos	byte [edi]
36
	mov	eax,[error_line]
37
	mov	[current_line],eax
38
	cmp	[anonymous_forward],0
39
	jne	invalid_value
40
	add	edi,0Fh
41
	and	edi,not 0Fh
42
	mov	[code_start],edi
43
	pop	[memory_end]
44
	ret
45
      empty_line:
46
	add	esi,17
47
	jmp	parse_next_line
48
49
 
50
	mov	[parenthesis_stack],0
51
      instruction_start:
52
	cmp	byte [esi],1Ah
53
	jne	empty_instruction
54
	push	edi
55
	add	esi,2
56
	movzx	ecx,byte [esi-1]
57
	cmp	byte [esi+ecx],':'
58
	je	simple_label
59
	cmp	byte [esi+ecx],'='
60
	je	constant_label
61
	cmp	byte [esi+ecx],1Ah
62
	jne	get_main_instruction
63
	push	esi ecx
64
	lea	esi,[esi+ecx+2]
65
	movzx	ecx,byte [esi-1]
66
	mov	edi,data_directives
67
	call	get_symbol
68
	jnc	data_label
69
	pop	ecx esi
70
      get_main_instruction:
71
	call	get_instruction
72
	jnc	parse_instruction
73
	mov	edi,data_directives
74
	call	get_symbol
75
	jnc	data_instruction
76
	mov	edi,symbols
77
	call	get_symbol
78
	pop	edi
79
	jc	unknown_instruction
80
	stos	word [edi]
81
	jmp	parse_arguments
82
      data_instruction:
83
	movzx	ebx,ah
84
	mov	bx,[data_handlers+ebx*2]
85
	jmp	parse_instruction
86
      unknown_instruction:
87
	sub	esi,2
88
	jmp	parse_arguments
89
      constant_label:
90
	pop	edi
91
	call	get_label_id
92
	mov	byte [edi],3
93
	inc	edi
94
	stos	dword [edi]
95
	xor	al,al
96
	stos	byte [edi]
97
	inc	esi
98
	jmp	parse_arguments
99
      data_label:
100
	pop	ecx ebx
101
	pop	edi
102
	push	eax esi
103
	mov	esi,ebx
104
	movzx	ecx,byte [esi-1]
105
	call	identify_label
106
	mov	byte [edi],2
107
	inc	edi
108
	stos	dword [edi]
109
	pop	esi eax
110
	stos	byte [edi]
111
	push	edi
112
	jmp	data_instruction
113
      simple_label:
114
	pop	edi
115
	call	identify_label
116
	mov	byte [edi],2
117
	inc	edi
118
	stos	dword [edi]
119
	inc	esi
120
	xor	al,al
121
	stos	byte [edi]
122
	jmp	instruction_start
123
      identify_label:
124
	cmp	byte [esi],'.'
125
	je	local_label_name
126
	call	get_label_id
127
	cmp	eax,10h
128
	jb	label_identified
129
	or	ebx,ebx
130
	jz	anonymous_label_name
131
	dec	ebx
132
	mov	[current_locals_prefix],ebx
133
      label_identified:
134
	ret
135
      anonymous_label_name:
136
	cmp	byte [esi-1],'@'
137
	je	anonymous_label_name_ok
138
	mov	eax,0Fh
139
      anonymous_label_name_ok:
140
	ret
141
      local_label_name:
142
	call	get_label_id
143
	ret
144
      parse_label_directive:
145
	cmp	byte [esi],1Ah
146
	jne	argument_parsed
147
	inc	esi
148
	movzx	ecx,byte [esi]
149
	inc	esi
150
	mov	al,2
151
	stos	byte [edi]
152
	call	identify_label
153
	stos	dword [edi]
154
	xor	al,al
155
	stos	byte [edi]
156
	jmp	argument_parsed
157
      parse_load_directive:
158
	cmp	byte [esi],1Ah
159
	jne	argument_parsed
160
	inc	esi
161
	movzx	ecx,byte [esi]
162
	inc	esi
163
	mov	al,2
164
	stos	byte [edi]
165
	call	get_label_id
166
	stos	dword [edi]
167
	xor	al,al
168
	stos	byte [edi]
169
	jmp	argument_parsed
170
      parse_prefix_instruction:
171
	cmp	byte [esi],1Ah
172
	jne	parse_arguments
173
	push	edi
174
	inc	esi
175
	movzx	ecx,byte [esi]
176
	inc	esi
177
	jmp	get_main_instruction
178
      parse_instruction:
179
	pop	edi
180
	mov	dl,al
181
	mov	al,1
182
	stos	byte [edi]
183
	mov	ax,bx
184
	stos	word [edi]
185
	mov	al,dl
186
	stos	byte [edi]
187
	cmp	bx,prefix_instruction-assembler
188
	je	parse_prefix_instruction
189
	cmp	bx,end_directive-assembler
190
	je	parse_prefix_instruction
191
	cmp	bx,label_directive-assembler
192
	je	parse_label_directive
193
	cmp	bx,segment_directive-assembler
194
	je	parse_label_directive
195
	cmp	bx,load_directive-assembler
196
	je	parse_load_directive
197
	cmp	bx,extrn_directive-assembler
198
	je	parse_extrn_directive
199
	cmp	bx,public_directive-assembler
200
	je	parse_public_directive
201
      parse_arguments:
202
	lods	byte [esi]
203
	cmp	al,':'
204
	je	instruction_separator
205
	cmp	al,','
206
	je	separator
207
	cmp	al,'='
208
	je	separator
209
	cmp	al,'|'
210
	je	separator
211
	cmp	al,'&'
212
	je	separator
213
	cmp	al,'~'
214
	je	separator
215
	cmp	al,'>'
216
	je	greater
217
	cmp	al,'<'
218
	je	less
219
	cmp	al,')'
220
	je	close_parenthesis
221
	or	al,al
222
	jz	line_parsed
223
	cmp	al,'['
224
	je	address_argument
225
	cmp	al,']'
226
	je	separator
227
	cmp	al,'{'
228
	je	unallowed_character
229
	cmp	al,'}'
230
	je	unallowed_character
231
	cmp	al,'#'
232
	je	unallowed_character
233
	cmp	al,'`'
234
	je	unallowed_character
235
	dec	esi
236
	cmp	al,1Ah
237
	jne	expression_argument
238
	push	edi
239
	mov	edi,directive_operators
240
	call	get_operator
241
	or	al,al
242
	jnz	operator_argument
243
	inc	esi
244
	movzx	ecx,byte [esi]
245
	inc	esi
246
	mov	edi,symbols
247
	call	get_symbol
248
	jnc	symbol_argument
249
	mov	edi,formatter_symbols
250
	call	get_symbol
251
	jnc	symbol_argument
252
	cmp	ecx,1
253
	jne	check_argument
254
	cmp	byte [esi],'?'
255
	jne	check_argument
256
	pop	edi
257
	movs	byte [edi],[esi]
258
	jmp	argument_parsed
259
      symbol_argument:
260
	pop	edi
261
	stos	word [edi]
262
	jmp	argument_parsed
263
      operator_argument:
264
	pop	edi
265
	cmp	al,85h
266
	je	ptr_argument
267
	stos	byte [edi]
268
	cmp	al,80h
269
	je	forced_expression
270
	cmp	al,81h
271
	je	forced_parenthesis
272
	cmp	al,82h
273
	je	parse_from_operator
274
	cmp	al,89h
275
	je	parse_label_operator
276
	jmp	argument_parsed
277
      parse_public_directive:
278
	cmp	byte [esi],1Ah
279
	jne	parse_arguments
280
	inc	esi
281
	push	esi
282
	movzx	ecx,byte [esi]
283
	inc	esi
284
	mov	al,2
285
	stos	byte [edi]
286
	call	get_label_id
287
	stos	dword [edi]
288
	mov	ax,8600h
289
	stos	word [edi]
290
	pop	ebx
291
	push	ebx esi edi
292
	mov	edi,directive_operators
293
	call	get_operator
294
	pop	edi edx ebx
295
	cmp	al,86h
296
	je	argument_parsed
297
	mov	esi,edx
298
	xchg	esi,ebx
299
	movzx	ecx,byte [esi]
300
	inc	esi
301
	mov	ax,'('
302
	stos	word [edi]
303
	mov	eax,ecx
304
	stos	dword [edi]
305
	rep	movs byte [edi],[esi]
306
	xor	al,al
307
	stos	byte [edi]
308
	xchg	esi,ebx
309
	jmp	argument_parsed
310
      parse_extrn_directive:
311
	cmp	byte [esi],22h
312
	je	parse_quoted_extrn
313
	cmp	byte [esi],1Ah
314
	jne	parse_arguments
315
	push	esi
316
	movzx	ecx,byte [esi+1]
317
	add	esi,2
318
	mov	ax,'('
319
	stos	word [edi]
320
	mov	eax,ecx
321
	stos	dword [edi]
322
	rep	movs byte [edi],[esi]
323
	mov	ax,8600h
324
	stos	word [edi]
325
	pop	esi
326
      parse_label_operator:
327
	cmp	byte [esi],1Ah
328
	jne	argument_parsed
329
	inc	esi
330
	movzx	ecx,byte [esi]
331
	inc	esi
332
	mov	al,2
333
	stos	byte [edi]
334
	call	get_label_id
335
	stos	dword [edi]
336
	xor	al,al
337
	stos	byte [edi]
338
	jmp	argument_parsed
339
      parse_from_operator:
340
	cmp	byte [esi],22h
341
	jne	forced_expression
342
	jmp	argument_parsed
343
      parse_quoted_extrn:
344
	inc	esi
345
	mov	ax,'('
346
	stos	word [edi]
347
	lods	dword [esi]
348
	mov	ecx,eax
349
	stos	dword [edi]
350
	rep	movs byte [edi],[esi]
351
	xor	al,al
352
	stos	byte [edi]
353
	push	esi edi
354
	mov	edi,directive_operators
355
	call	get_operator
356
	mov	edx,esi
357
	pop	edi esi
358
	cmp	al,86h
359
	jne	argument_parsed
360
	stos	byte [edi]
361
	mov	esi,edx
362
	jmp	parse_label_operator
363
      ptr_argument:
364
	call	parse_address
365
	jmp	address_parsed
366
      check_argument:
367
	push	esi ecx
368
	sub	esi,2
369
	mov	edi,single_operand_operators
370
	call	get_operator
371
	pop	ecx esi
372
	or	al,al
373
	jnz	not_instruction
374
	call	get_instruction
375
	jnc	parse_instruction
376
	mov	edi,data_directives
377
	call	get_symbol
378
	jnc	data_instruction
379
      not_instruction:
380
	pop	edi
381
	sub	esi,2
382
      expression_argument:
383
	cmp	byte [esi],22h
384
	jne	not_string
385
	mov	eax,[esi+1]
386
	lea	ebx,[esi+5+eax]
387
	push	ebx ecx esi edi
388
	mov	al,'('
389
	stos	byte [edi]
390
	call	convert_expression
391
	mov	al,')'
392
	stos	byte [edi]
393
	pop	eax edx ecx ebx
394
	cmp	esi,ebx
395
	jne	expression_parsed
396
	mov	edi,eax
397
	mov	esi,edx
398
      string_argument:
399
	inc	esi
400
	mov	ax,'('
401
	stos	word [edi]
402
	lods	dword [esi]
403
	mov	ecx,eax
404
	stos	dword [edi]
405
	shr	ecx,1
406
	jnc	string_movsb_ok
407
	movs	byte [edi],[esi]
408
      string_movsb_ok:
409
	shr	ecx,1
410
	jnc	string_movsw_ok
411
	movs	word [edi],[esi]
412
      string_movsw_ok:
413
	rep	movs dword [edi],[esi]
414
	xor	al,al
415
	stos	byte [edi]
416
	jmp	expression_parsed
417
      not_string:
418
	cmp	byte [esi],'('
419
	jne	expression
420
	mov	eax,esp
421
	sub	eax,100h
422
	jc	stack_overflow
423
	cmp	eax,[stack_limit]
424
	jb	stack_overflow
425
	push	esi edi
426
	inc	esi
427
	mov	al,'{'
428
	stos	byte [edi]
429
	inc	[parenthesis_stack]
430
	jmp	parse_arguments
431
      expression:
432
	mov	al,'('
433
	stos	byte [edi]
434
	call	convert_expression
435
	mov	al,')'
436
	stos	byte [edi]
437
	jmp	expression_parsed
438
      forced_expression:
439
	mov	al,'('
440
	stos	byte [edi]
441
	call	convert_expression
442
	mov	al,')'
443
	stos	byte [edi]
444
	jmp	argument_parsed
445
      address_argument:
446
	call	parse_address
447
	lods	byte [esi]
448
	cmp	al,']'
449
	jne	invalid_address
450
      address_parsed:
451
	mov	al,']'
452
	stos	byte [edi]
453
	jmp	argument_parsed
454
      parse_address:
455
	mov	al,'['
456
	stos	byte [edi]
457
	cmp	word [esi],021Ah
458
	jne	convert_address
459
	push	esi
460
	add	esi,4
461
	lea	ebx,[esi+1]
462
	cmp	byte [esi],':'
463
	pop	esi
464
	jne	convert_address
465
	add	esi,2
466
	mov	ecx,2
467
	push	ebx edi
468
	mov	edi,symbols
469
	call	get_symbol
470
	pop	edi esi
471
	jc	invalid_address
472
	cmp	al,10h
473
	jne	invalid_address
474
	mov	al,ah
475
	and	ah,11110000b
476
	cmp	ah,60h
477
	jne	invalid_address
478
	stos	byte [edi]
479
      convert_address:
480
	cmp	byte [esi],1Ah
481
	jne	convert_expression
482
	push	esi
483
	lods	word [esi]
484
	movzx	ecx,ah
485
	push	edi
486
	mov	edi,address_sizes
487
	call	get_symbol
488
	pop	edi
489
	jc	no_size_prefix
490
	mov	al,ah
491
	add	al,70h
492
	stos	byte [edi]
493
	add	esp,4
494
	jmp	convert_expression
495
      no_size_prefix:
496
	pop	esi
497
	jmp	convert_expression
498
      forced_parenthesis:
499
	cmp	byte [esi],'('
500
	jne	argument_parsed
501
	inc	esi
502
	mov	al,'{'
503
	jmp	separator
504
      unallowed_character:
505
	mov	al,0FFh
506
	jmp	separator
507
      close_parenthesis:
508
	mov	al,'}'
509
      separator:
510
	stos	byte [edi]
511
	jmp	argument_parsed
512
      instruction_separator:
513
	stos	byte [edi]
514
	jmp	instruction_start
515
      greater:
516
	cmp	byte [esi],'='
517
	jne	separator
518
	inc	esi
519
	mov	al,0F2h
520
	jmp	separator
521
      less:
522
	cmp	byte [edi-1],0F6h
523
	je	separator
524
	cmp	byte [esi],'>'
525
	je	not_equal
526
	cmp	byte [esi],'='
527
	jne	separator
528
	inc	esi
529
	mov	al,0F3h
530
	jmp	separator
531
      not_equal:
532
	inc	esi
533
	mov	al,0F1h
534
	jmp	separator
535
      argument_parsed:
536
	cmp	[parenthesis_stack],0
537
	je	parse_arguments
538
	dec	[parenthesis_stack]
539
	add	esp,8
540
	jmp	argument_parsed
541
      expression_parsed:
542
	cmp	[parenthesis_stack],0
543
	je	parse_arguments
544
	cmp	byte [esi],')'
545
	jne	argument_parsed
546
	dec	[parenthesis_stack]
547
	pop	edi esi
548
	jmp	expression
549
      empty_instruction:
550
	lods	byte [esi]
551
	or	al,al
552
	jz	line_parsed
553
	cmp	al,':'
554
	je	invalid_name
555
	cmp	al,3Bh
556
	je	skip_preprocessed_symbol
557
	dec	esi
558
	jmp	parse_arguments
559
      skip_preprocessed_symbol:
560
	lods	byte [esi]
561
	movzx	eax,al
562
	add	esi,eax
563
      skip_next:
564
	lods	byte [esi]
565
	or	al,al
566
	jz	line_parsed
567
	cmp	al,1Ah
568
	je	skip_preprocessed_symbol
569
	cmp	al,3Bh
570
	je	skip_preprocessed_symbol
571
	cmp	al,22h
572
	je	skip_preprocessed_string
573
	jmp	skip_next
574
      skip_preprocessed_string:
575
	lods	dword [esi]
576
	add	esi,eax
577
	jmp	skip_next
578
      line_parsed:
579
	cmp	[parenthesis_stack],0
580
	jne	invalid_expression
581
	ret
582
583
 
584
	cmp	byte [esi],1Ah
585
	jne	get_simple_operator
586
	mov	edx,esi
587
	push	ebp
588
	inc	esi
589
	lods	byte [esi]
590
	movzx	ebp,al
591
	push	edi
592
	mov	ecx,ebp
593
	call	lower_case
594
	pop	edi
595
      check_operator:
596
	mov	esi,converted
597
	movzx	ecx,byte [edi]
598
	jecxz	no_operator
599
	inc	edi
600
	mov	ebx,edi
601
	add	ebx,ecx
602
	cmp	ecx,ebp
603
	jne	next_operator
604
	repe	cmps byte [esi],[edi]
605
	je	operator_found
606
      next_operator:
607
	mov	edi,ebx
608
	inc	edi
609
	jmp	check_operator
610
      no_operator:
611
	mov	esi,edx
612
	mov	ecx,ebp
613
	pop	ebp
614
      no_simple_operator:
615
	xor	al,al
616
	ret
617
      operator_found:
618
	lea	esi,[edx+2+ebp]
619
	mov	ecx,ebp
620
	pop	ebp
621
	mov	al,[edi]
622
	ret
623
      get_simple_operator:
624
	mov	al,[esi]
625
	cmp	al,22h
626
	je	no_simple_operator
627
      simple_operator:
628
	cmp	byte [edi],1
629
	jb	no_simple_operator
630
	ja	simple_next_operator
631
	cmp	al,[edi+1]
632
	je	simple_operator_found
633
      simple_next_operator:
634
	movzx	ecx,byte [edi]
635
	lea	edi,[edi+1+ecx+1]
636
	jmp	simple_operator
637
      simple_operator_found:
638
	inc	esi
639
	mov	al,[edi+2]
640
	ret
641
642
 
643
 
644
	mov	edx,esi
645
	mov	ebp,ecx
646
	push	edi
647
	call	lower_case
648
	pop	edi
649
      scan_symbols:
650
	mov	esi,converted
651
	movzx	eax,byte [edi]
652
	or	al,al
653
	jz	no_symbol
654
	mov	ecx,ebp
655
	inc	edi
656
	mov	ebx,edi
657
	add	ebx,eax
658
	mov	ah,[esi]
659
	cmp	ah,[edi]
660
	jb	no_symbol
661
	ja	next_symbol
662
	cmp	cl,al
663
	jne	next_symbol
664
	repe	cmps byte [esi],[edi]
665
	jb	no_symbol
666
	je	symbol_ok
667
      next_symbol:
668
	mov	edi,ebx
669
	add	edi,2
670
	jmp	scan_symbols
671
      no_symbol:
672
	mov	esi,edx
673
	mov	ecx,ebp
674
	stc
675
	ret
676
      symbol_ok:
677
	lea	esi,[edx+ebp]
678
	mov	ax,[ebx]
679
	clc
680
	ret
681
682
 
683
	mov	edx,esi
684
	mov	ebp,ecx
685
	call	lower_case
686
	mov	ecx,ebp
687
	cmp	cl,11
688
	ja	no_instruction
689
	sub	cl,2
690
	jc	no_instruction
691
	movzx	edi,word [instructions+ecx*2]
692
	add	edi,instructions
693
      scan_instructions:
694
	mov	esi,converted
695
	mov	al,[edi]
696
	or	al,al
697
	jz	no_instruction
698
	mov	ecx,ebp
699
	mov	ebx,edi
700
	add	ebx,ecx
701
	repe	cmps byte [esi],[edi]
702
	jb	no_instruction
703
	je	instruction_ok
704
      next_instruction:
705
	mov	edi,ebx
706
	add	edi,3
707
	jmp	scan_instructions
708
      no_instruction:
709
	mov	esi,edx
710
	mov	ecx,ebp
711
	stc
712
	ret
713
      lower_case:
714
	mov	edi,converted
715
	mov	ebx,characters
716
      convert_case:
717
	lods	byte [esi]
718
	xlat	byte [ebx]
719
	stos	byte [edi]
720
	loop	convert_case
721
      case_ok:
722
	ret
723
      instruction_ok:
724
	lea	esi,[edx+ebp]
725
	mov	al,[ebx]
726
	mov	bx,[ebx+1]
727
	clc
728
	ret
729
730
 
731
	cmp	ecx,100h
732
	jae	name_too_long
733
	cmp	byte [esi],'@'
734
	je	anonymous_label
735
	cmp	byte [esi],'.'
736
	jne	standard_label
737
	cmp	byte [esi+1],'.'
738
	je	standard_label
739
	cmp	[current_locals_prefix],0
740
	je	standard_label
741
	push	edi
742
	mov	edi,[memory_end]
743
	sub	edi,2
744
	sub	edi,ecx
745
	push	ecx esi
746
	mov	esi,[current_locals_prefix]
747
	lods	byte [esi]
748
	movzx	ecx,al
749
	sub	edi,ecx
750
	cmp	edi,[esp+8]
751
	jb	out_of_memory
752
	mov	[memory_end],edi
753
	mov	word [edi],0
754
	add	edi,2
755
	mov	ebx,edi
756
	rep	movs byte [edi],[esi]
757
	pop	esi ecx
758
	add	al,cl
759
	jc	name_too_long
760
	rep	movs byte [edi],[esi]
761
	pop	edi
762
	push	esi
763
	movzx	ecx,al
764
	mov	byte [ebx-1],al
765
	mov	esi,ebx
766
	call	get_label_id
767
	pop	esi
768
	ret
769
      anonymous_label:
770
	cmp	ecx,2
771
	jne	standard_label
772
	mov	al,[esi+1]
773
	mov	ebx,characters
774
	xlat	byte [ebx]
775
	cmp	al,'@'
776
	je	new_anonymous
777
	cmp	al,'b'
778
	je	anonymous_back
779
	cmp	al,'r'
780
	je	anonymous_back
781
	cmp	al,'f'
782
	jne	standard_label
783
	add	esi,2
784
	mov	eax,[anonymous_forward]
785
	or	eax,eax
786
	jnz	anonymous_ok
787
	mov	eax,[current_line]
788
	mov	[error_line],eax
789
	mov	eax,[labels_list]
790
	sub	eax,24
791
	mov	[labels_list],eax
792
	mov	[anonymous_forward],eax
793
      anonymous_ok:
794
	xor	ebx,ebx
795
	ret
796
      anonymous_back:
797
	add	esi,2
798
	mov	eax,[anonymous_reverse]
799
	or	eax,eax
800
	jz	invalid_value
801
	jmp	anonymous_ok
802
      new_anonymous:
803
	add	esi,2
804
	mov	eax,[anonymous_forward]
805
	or	eax,eax
806
	jnz	new_anonymous_ok
807
	mov	eax,[labels_list]
808
	sub	eax,24
809
	mov	[labels_list],eax
810
      new_anonymous_ok:
811
	mov	[anonymous_reverse],eax
812
	mov	[anonymous_forward],0
813
	jmp	anonymous_ok
814
      standard_label:
815
	cmp	byte [esi],'%'
816
	je	get_predefined_id
817
	cmp	byte [esi],'$'
818
	jne	find_label
819
	cmp	ecx,2
820
	ja	find_label
821
	inc	esi
822
	jb	get_current_offset_id
823
	inc	esi
824
	cmp	byte [esi-1],'$'
825
	je	get_org_origin_id
826
	sub	esi,ecx
827
	jmp	find_label
828
      get_current_offset_id:
829
	xor	eax,eax
830
	ret
831
      get_counter_id:
832
	mov	eax,1
833
	ret
834
      get_timestamp_id:
835
	mov	eax,2
836
	ret
837
      get_org_origin_id:
838
	mov	eax,3
839
	ret
840
      get_predefined_id:
841
	cmp	ecx,2
842
	ja	find_label
843
	inc	esi
844
	cmp	cl,1
845
	je	get_counter_id
846
	lods	byte [esi]
847
	mov	ebx,characters
848
	xlat	[ebx]
849
	cmp	al,'t'
850
	je	get_timestamp_id
851
	sub	esi,2
852
      find_label:
853
	xor	ebx,ebx
854
	mov	eax,2166136261
855
	mov	ebp,16777619
856
      hash_label:
857
	xor	al,[esi+ebx]
858
	mul	ebp
859
	inc	bl
860
	cmp	bl,cl
861
	jb	hash_label
862
	mov	ebp,eax
863
	shl	eax,8
864
	and	ebp,0FFh shl 24
865
	xor	ebp,eax
866
	or	ebp,ebx
867
	mov	[label_hash],ebp
868
	push	edi esi
869
	push	ecx
870
	mov	ecx,32
871
	mov	ebx,hash_tree
872
      follow_tree:
873
	mov	edx,[ebx]
874
	or	edx,edx
875
	jz	extend_tree
876
	xor	eax,eax
877
	shl	ebp,1
878
	adc	eax,0
879
	lea	ebx,[edx+eax*4]
880
	dec	ecx
881
	jnz	follow_tree
882
	mov	[label_leaf],ebx
883
	pop	edx
884
	mov	eax,[ebx]
885
	or	eax,eax
886
	jz	add_label
887
	mov	ebx,esi
888
	mov	ebp,[label_hash]
889
      compare_labels:
890
	mov	esi,ebx
891
	mov	ecx,edx
892
	mov	edi,[eax+4]
893
	repe	cmps byte [esi],[edi]
894
	je	label_found
895
	mov	eax,[eax]
896
	or	eax,eax
897
	jnz	compare_labels
898
	jmp	add_label
899
      label_found:
900
	add	esp,4
901
	pop	edi
902
	mov	ebx,[eax+4]
903
	mov	eax,[eax+8]
904
	ret
905
      extend_tree:
906
	mov	edx,[free_additional_memory]
907
	lea	eax,[edx+8]
908
	cmp	eax,[additional_memory_end]
909
	ja	out_of_memory
910
	mov	[free_additional_memory],eax
911
	xor	eax,eax
912
	mov	[edx],eax
913
	mov	[edx+4],eax
914
	shl	ebp,1
915
	adc	eax,0
916
	mov	[ebx],edx
917
	lea	ebx,[edx+eax*4]
918
	dec	ecx
919
	jnz	extend_tree
920
	mov	[label_leaf],ebx
921
	pop	edx
922
      add_label:
923
	mov	ecx,edx
924
	pop	esi
925
	cmp	byte [esi-2],0
926
	je	label_name_ok
927
	mov	al,[esi]
928
	cmp	al,30h
929
	jb	name_first_char_ok
930
	cmp	al,39h
931
	jbe	invalid_name
932
      name_first_char_ok:
933
	cmp	ecx,1
934
	jne	check_for_reserved_word
935
	cmp	al,'$'
936
	je	reserved_word
937
      check_for_reserved_word:
938
	call	get_instruction
939
	jnc	reserved_word
940
	mov	edi,data_directives
941
	call	get_symbol
942
	jnc	reserved_word
943
	mov	edi,symbols
944
	call	get_symbol
945
	jnc	reserved_word
946
	mov	edi,formatter_symbols
947
	call	get_symbol
948
	jnc	reserved_word
949
	sub	esi,2
950
	mov	edi,operators
951
	call	get_operator
952
	or	al,al
953
	jnz	reserved_word
954
	mov	edi,single_operand_operators
955
	call	get_operator
956
	or	al,al
957
	jnz	reserved_word
958
	mov	edi,directive_operators
959
	call	get_operator
960
	or	al,al
961
	jnz	reserved_word
962
	inc	esi
963
	movzx	ecx,byte [esi]
964
	inc	esi
965
      label_name_ok:
966
	mov	edx,[free_additional_memory]
967
	lea	eax,[edx+12]
968
	cmp	eax,[additional_memory_end]
969
	ja	out_of_memory
970
	mov	[free_additional_memory],eax
971
	mov	[edx+4],esi
972
	mov	ebx,esi
973
	add	esi,ecx
974
	mov	eax,[label_leaf]
975
	mov	edi,[eax]
976
	mov	[edx],edi
977
	mov	[eax],edx
978
	mov	eax,[labels_list]
979
	sub	eax,24
980
	mov	[labels_list],eax
981
	mov	[edx+8],eax
982
	pop	edi
983
	ret
984
      reserved_word:
985
	mov	eax,0Fh
986
	pop	edi
987
	ret
988
989
 
990
 db 1,'+',80h
991
 db 1,'-',81h
992
 db 1,'*',90h
993
 db 1,'/',91h
994
 db 3,'mod',0A0h
995
 db 3,'and',0B0h
996
 db 2,'or',0B1h
997
 db 3,'xor',0B2h
998
 db 3,'shl',0C0h
999
 db 3,'shr',0C1h
1000
 db 0
1001
1002
 
1003
 db 1,'+',0
1004
 db 1,'-',0D1h
1005
 db 3,'not',0D0h
1006
 db 3,'rva',0E0h
1007
 db 0
1008
1009
 
1010
 db 2,'as',86h
1011
 db 2,'at',80h
1012
 db 7,'defined',88h
1013
 db 3,'dup',81h
1014
 db 2,'eq',0F0h
1015
 db 6,'eqtype',0F7h
1016
 db 4,'from',82h
1017
 db 2,'in',0F6h
1018
 db 2,'on',84h
1019
 db 3,'ptr',85h
1020
 db 4,'used',89h
1021
 db 0
1022
>